Ad

Shopify GraphQL Using Swift Not Getting Response

- 1 answer

in Shopify store front grahpQL getting issue while calling store name

Here is the code for it

      let client: Graph.Client = Graph.Client(shopDomain: shopDomain, apiKey: apiKey, locale: locale)
      let query = Storefront.buildQuery { 
        .shop { 
            .name()
        }
        
    }
    let task = client.queryGraphWith(query) { response, error in
        if let response = response {
            print(response);
        }else {
            print("Query failed: \(error)")
        }
    }
    task.resume()

But not getting success response

Ad

Answer

You are missing the $ sign inside your code you can check updated code here https://github.com/skyclones/ShopifyMobileApp

    let shopDomain = "YOUR STORE NAME"
    let apiKey     = "YOUR STORE KEY"
    let locale   = Locale(identifier: "en-US")

    let client: Graph.Client = Graph.Client(shopDomain: shopDomain, apiKey: apiKey, locale: locale)
    client.cachePolicy = .cacheFirst(expireIn: 3600)

    let query = Storefront.buildQuery { $0
        .shop { $0
            .name()
        }
        
    }
    let task = client.queryGraphWith(query) { response, error in
        if let response = response {
            print(response);
        }else {
            print("Query failed: \(error)")
        }
    }
    task.resume()
Ad
source: stackoverflow.com
Ad