GraphQL fetch products by collection IDs

Solved
tiagoalmeida
Tourist
4 0 0

Hello,

 

I am going to fetch all products included in collections by providing collection IDs as a query param.

This is the query that I tried on https://shopify.dev/graphiql/admin-graphiql.

 

query nodes($ids: [ID!]!) {
  nodes(ids: $ids) {
    ...on Collection {
      id
      products(first: 50) {
        edges {
          node {
            id
            title
          }
        }
      }
    }
  }
}

 

And for query variables...

 

{
  "ids": ["gid://shopify/Collection/70598819862", "gid://shopify/Collection/70591239862"]
}

 

 

I get this error.

 

{
  "errors": [
    {
      "message": "Variable $ids of type [ID!]! was provided invalid value",
      "locations": [
        {
          "line": 1,
          "column": 13
        }
      ],
      "extensions": {
        "value": null,
        "problems": [
          {
            "path": [],
            "explanation": "Expected value to not be null"
          }
        ]
      }
    }
  ]
}

 

 

What is wrong with the query?

 

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 232

This is an accepted solution.

Strange, it looks okay. And when I ran it in my GraphiQL app against a couple of valid collection ID's it came back fine. See below. What happens when you run it in the GraphiQL app, after you've verified the collection ID's are correct?

 

Untitled.png

tiagoalmeida
Tourist
4 0 0

Hello @Greg_Kujawa ,

Thanks for your quick response. My query works well in GraphiQL app. The online environment https://shopify.dev/graphiql/admin-graphiql has something wrong.

0 Likes
Anonymous
Not applicable
1759 0 0

Hi

 

Did you find a solution?

0 Likes
tiagoalmeida
Tourist
4 0 0

Hi @Anonymous 

My query was correct and the problem was that I tried to run GraphQL in the wrong platform.

The query worked well on GraphQL app and my private app as well.

0 Likes