ios – GraphQL best practice when processing queries with multiple data
I’m new to GraphQL, and I’m confused about what the best practice is when a client needs to repeat a query for multiple inputs. For example, let’s say I have an API that can tell me which city is nearest a GPS coordinate. (Apologies if this has errors, but you get the idea)
type Query {
locate(gps: GPS!): City!
}
Now let’s say my client has a couple hundred GPS coordinates it wants to locate. It’s obviously grossly inefficient to make hundreds of requests. Should I make a query that can locate a bunch of coordinates? Or batch them in some other way?
type Query {
locate(gps: GPS!): City!
locateMultiple(gpss: [GPS]!): [City]!
}
This seems antithetical to the idea of GraphQL, but I’m still new here. Also, for context, I’m not planning on using Apollo (Haskell backend with iOS frontend, I’m looking at SwiftGraphQL), but I could probably create a simple batching system (an array of requests to an array of responses) if needed.
What would you do?
Read more here: Source link