GraphQL error: Field 'product' doesn't exist on type 'QueryRoot'

Im new to GraphQL and this example only sure a basic example which is great. Sadly they have not provided an example of a product show page; how to fetch a single product.

Using GraphiQL:

{ 
  product(id: "gid://shopify/Product/1245678") {
    title
    description
    onlineStoreUrl
  }
}

I seem to get the data. I, getting an error ““GraphQL error: Field ‘product’ doesn’t exist on type ‘QueryRoot’” which is wrong because “product” in on the QueryRoot”.

My actual code:

const query = gql`
  query {
    product(id: "gid://shopify/Product/4416592838700") {
        title
        description
        onlineStoreUrl
      }
  }
`;

// Then later:
graphql(query),
[...]
1 Like

Is anyone looking at this? The example is hidden important things such as the “bodyHtml” and fetch a single product. They having not included that query as it does not work. How do you mean: “GraphQL error: Field ‘bodyHtml’ doesn’t exist on type ‘Product’” when it is there? Could a member of staff please advice???

Did you manage to resolve this?
I get the same error and this is literary copy paste from Shopify docs here

Really strange that Shopify provides examples that do not work.

Hi,

If you use the Storefont API, you query begins with QueryRoot

You need to use Inline Fragments, like that :

query {
  node(id:"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzQ0MTg5MzQ1MzgzNDA=") {
    ...on Product {
      title
    }
  }
}
2 Likes

can any one help me i am getting similar issue, here is my code

const GET_FIRST_PRODUCTS = gqlquery getProducts($row:Int!){ products(first: $row) { edges { cursor node{ id title variants(first:1){ edges{ node{ price } } } priceRangeV2{ minVariantPrice{ amount currencyCode } } images(first:1){ edges{ node{ id originalSrc altText width height transformedSrc } } } } } pageInfo { hasNextPage hasPreviousPage } } };
GraphQL error: Field ‘priceRangeV2’ doesn’t exist on type ‘Product’ GraphQL error: Field ‘width’ doesn’t exist on type ‘Image’ GraphQL error: Field ‘height’ doesn’t exist on type ‘Image’

I was getting the same error. It turned out that I use using the id and not the “product_id”. The two are different.

just in case anyone else finds this in hopes of getting an actual answer to this question.

Assuming you’re using something like GraphQL to call the API endpoints…

The API defaults anything sent to it as a query.

If you want a mutation, you need to set your query string up like this - “mutation {YOUR_QUERY}”

Hope that helps, Peter