Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

GraphQL Storefront API: Field 'products' doesn't accept argument 'id'

GraphQL Storefront API: Field 'products' doesn't accept argument 'id'

codemonkey
Excursionist
12 1 2

I'm using Apollo and GraphQL with the Storefront API.

query getProduct($id: String!) {
  products(id: $id) {
    edges {
      cursor
      node {
        id
        vendor
        title
        descriptionHtml
        availableForSale
        images(first: 10) {
          edges {
            node {
              altText
              src: originalSrc
            }
          }
        }
        variants(first: 50) {
          edges {
            node {
              id
              availableForSale
              compareAtPrice
              title
              price
            }
          }
        }
      }
    }
  }
}
Replies 2 (2)

codemonkey
Excursionist
12 1 2

Using GraphiQL the following works:

query getProduct {
  product(id: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzE1NDM4ODM3MTg3MTE=") {
    id
    vendor
    title
    descriptionHtml
    images(first: 10) {
      edges {
        node {
          altText
          src: originalSrc
        }
      }
    }
    variants(first: 50) {
      edges {
        node {
          id
          availableForSale
          compareAtPrice
          title
          price
        }
      }
    }
  }
}

However, this does not:

query getProduct($id: ID!) {
  product(id: $id) {
    id
    vendor
    title
    descriptionHtml
    availableForSale
    images(first: 10) {
      edges {
        node {
          altText
          src: originalSrc
        }
      }
    }
    variants(first: 50) {
      edges {
        node {
          id
          availableForSale
          compareAtPrice
          title
          price
        }
      }
    }
  }
}

I'm given the error: GraphQL error: Field 'product' doesn't exist on type 'QueryRoot'

codemonkey
Excursionist
12 1 2

My Apollo connection:

this.apollo.create({
  cache: new InMemoryCache(),
  link: new HttpLink(this.http).create({
    uri: `https://${environment.shopify_domain}/api/graphql`,
    headers: new HttpHeaders().set('X-Shopify-Storefront-Access-Token', environment.shopify_storefront_access_token),
  })
});

And the query:

public product(id: string): Promise<any> {
  this.presentLoading();
  return new Promise((resolve, reject) => {
    this.apollo.query({ query: product, variables: { id } }).toPromise().then((result) => {
      resolve(defaultResolver('product', result));
    }).catch((reason) => {
      console.error(reason);
      reject(reason);
    }).finally(() => this.loadingDismiss());
  });
}