What I want to do is to query for a particular field multiple times with different arguments. Is that possible in GraphQL?
Something like this:
query { myItem(size: 100, type: 2) { id, name } myItem(size: 150, type: 2) { id, name } myItem(size: 10, type: 1) { id, name } }
Multiple OperationsIf a request has two or more operations, then each operation must have a name. A request can only execute one operation, so you must also include the operation name to execute in the request (see the “operations” field for requests). Every operation name in a request must be unique.
When doing query batching, the GraphQL server executes multiple queries in a single request. But those queries are still independent from each other. They just happen to be executed one after the other, to avoid the latency from multiple requests.
GraphQL can be overkillSince GraphQL is so complex and powerful, it can commonly be overkill for smaller applications. If you have a simple/straight-forward app in front of you, it will be easier to work with a REST API.
Yes, this is possible, but not in this form. GraphQL server will reject such query as a field with the same name used multiple times, but with different arguments.
You need to use aliases:
query { item1: myItem(size: 100, type: 2) { id, name } item2: myItem(size: 150, type: 2) { id, name } item3: myItem(size: 10, type: 1) { id, name } }
You can find more info on aliases here:
http://graphql.org/learn/queries/#aliases
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With