GraphQL fetch products by collection IDs

Solved
Highlighted
New Member
2 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
Highlighted
Shopify Partner
654 46 131

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

1 Like
Highlighted
New Member
2 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