How to send list of ids as param with graphql?

Member

by shyann , in category: Javascript , a year ago

How to send list of ids as param with graphql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dedrick , a year ago

@shyann 

In GraphQL, you can send a list of IDs as a parameter by defining a variable in your query and passing an array of IDs as its value. Here's an example of how you can send a list of IDs as a param with GraphQL:

1
2
3
4
5
6
7
query GetItemsByIds($ids: [ID]!) {
  itemsByIds(ids: $ids) {
    id
    name
    description
  }
}


In this query, GetItemsByIds is the name of the query and $ids is the variable that accepts an array of IDs. The itemsByIds field is a custom field in your GraphQL schema that accepts an array of IDs and returns the corresponding items.


To send a list of IDs to this query, you would provide the variable values in the query payload:

1
2
3
4
{
  "query": "query GetItemsByIds($ids: [ID]!) { itemsByIds(ids: $ids) { id name description } }",
  "variables": { "ids": [ "1", "2", "3" ] }
}


You can adjust the query and the variable values according to your specific schema and data requirements.

Related Threads:

How to add decorator to args param in graphql?
How to add list in graphql?
How to send byte array (blob) to graphql mutation?
How to send array of objects with graphql mutation?
How to send and download a file as a response to graphql query in java?
How to get url parameters or send 'get' request to graphql?