Field 'variants' doesn't exist on type 'QueryRoot'

Solved
daniort
New Member
6 0 0

Estoy tratando de obtener la id de una variante de un producto para poder estructurar y crear un checkout, los datos con los que cuentos, son información de la variante obtenida con la API de admin.


Tengo esta ID: 32225551155258

y tengo esta: gid://shopify/ProductVariant/32225551155258

(la id que necesito es la de este tipo: Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzQ2MjgwMDA1Mzg2ODI== )

Para esto lo que entiendo es que debemos usar GraphQL, por lo que la query con la que estoy intentando es la siguiente:

 query {
    productVariants (id"gid://shopify/ProductVariant/32225551455258") {
        id
        title
      }
  }

 

 

Aunque estoy haciendo las pruebas en Postman, las usare en una app con el elenguaje DART

la version de api que estoy ocupando es 2020-10.

 

Este es el error que me sale:

            "message": "Field 'productVariants' doesn't exist on type 'QueryRoot'",

 

Aunque "productVariant" si existe en los fields que muestra la lista de QueryRoot

(aquí: https://shopify.dev/docs/admin-api/graphql/reference/common-objects/queryroot?api%5Bversion%5D=2020-...)

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 223

Try productVariant not productVariants if you are providing a specific ID then you are looking for just one.

0 Likes
daniort
New Member
6 0 0

Of course, y was tryed this option "productVariant" and also "ProductVariants"

The result is equal.

            "message": "Field 'productVariant' doesn't exist on type 'QueryRoot'",
0 Likes
Greg_Kujawa
Shopify Partner
1016 83 223

It must have something to do with how you are enclosing things with the Query {} block. Here is a sample GQL request I just made through the Shopify GraphiQL app, and it works just fine.

Untitled.png

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 223

And here is the same thing run through Postman. 

Untitled.png

0 Likes
daniort
New Member
6 0 0

Hi!, Thancks for anwers me.

Well, I tryed with "productVariant" and "productVariants", also with API "2020-10" and "2021-01"

My headers data is fine?

title.jpg

________________________________________________________________________________________________________________

I want ID variants to make my create Checkout  so similar  of this:

(This query is fine, is funcionality)(the headers data and the api version is equal)

mutation {
  checkoutCreate(input: {
    lineItems: [{ variantId: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zMTQ4NDM0OTU3OTMyMg==", quantity: 4 }]
  }) {
    checkout {
       id
       webUrl
       lineItems(first: 5) {
         edges {
           node {
             title
             quantity
           }
         }
       }
    }
  }
}
0 Likes
Greg_Kujawa
Shopify Partner
1016 83 223

This is an accepted solution.

I think you have the URL wrong. should be /admin/api/2021-01 or whatever. 

0 Likes
syf_
Shopify Staff
Shopify Staff
84 18 14

This is an accepted solution.

Hey @daniort,

I believe you're using the Storefront API which doesn't have the productVariant field on its QueryRoot. This is only available for the Admin API.

Hopefully this helps clarify the confusion.

Best,
Seth.

syf_ | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes