3 ms·
Anybody have any advice for query optimization in GraphQL? Seems to me so far that it’s pretty nice for flexibility with small datasets, but once your data gets
by mplanchard 4y ago
Anybody have any advice for query optimization in GraphQL? Seems to me so far that it’s pretty nice for flexibility with small datasets, but once your data gets really big you need precise control over how things are queried in order to take best advantage of indexes, and I’m finding it hard to manage that with GraphQL since queries are so dispersed. It often for me is hard to even figure out when queries might be triggered or why, which makes it harder to ensure they’re not called too much and/or not called in an ineffective way.
- nerdbaggy 4y agoWhat are you using for your gql server? For me Hasura was a godsend especially with the ability to explain. https://hasura.io/docs/latest/api-reference/explain/ https://hasura.io/docs/latest/api-reference/explain/
- nforgerit 4y agoAlso, have a look at Facebook's Dataloader[0]. [0] https://github.com/graphql/dataloader https://github.com/graphql/dataloader
- eurasiantiger 4y agoUse a GraphQL-native or graph-with-GraphQL-adapter datastore like Dgraph Community Edition, ArangoDB, EdgeDB, Neo4j, Apache AGE for PostgreSQL, etc. For extra kicks, select one that supports GraphQL federation.
- karmakaze 4y agoBetween the request's query parameters and the query building, I added an optional SqlQueryOptimizer interface and injectable that's used for models/tables that need them. To minimize scope of writing each one, I made a sequential adapter that just tries each listed one until one applies. Each implementation first checks if the query params qualifies to use it, then makes any index hints or other query changes. Ended up doing this twice, once for ActiveRecord and once for an internal AST query builder.
- mplanchard 4y agoThis is a really stellar idea, thank you very much for sharing!