React-apollo: Feature: Docs on how to perform dynamic queries

Created on 3 May 2017  路  2Comments  路  Source: apollographql/react-apollo

Hey everyone, I have a use case I'd like to support with apollo/graphql:

Basically the idea is to allow users to define which columns (from a set list) they would like to view on a data table. Querying for all of the columns could mean a lot of unnecessary data would be grabbed, thus, I'd like to only send a graphql query with the user-requested columns.

I haven't been able to figure out how to do this yet, but I might be missing something. Any help would be greatly appreciated!

Also, this seems like a pretty common use case. I understand that apollo/relay are moving toward static queries (which might make sense for 90% of use cases), but it seems unwise to completely drop all dynamic query functionality (sometimes you just need to do it).

I originally posted this question in another issue but was told to make a new issue: https://github.com/apollographql/react-apollo/issues/330#issuecomment-297662937

Most helpful comment

I'm a little dumbfounded that AC doesn't support some kind of mechanism for dynamic queries. The promise of GQL has always been no over-fetching/under-fetching. In GraphiQL yes... you can enter only the fields you want. But, in the real world you need an HOC and all kinds of problematic hacks. As the complexity of GQL applications grow, so will the need for non-static queries.

All 2 comments

@tnrich this can be done using a higher order component or (the method I would suggest) using @skip or @include directives.

I don't want to support dynamic queries since you loose so much of the static benefits and open up to potential attack vectors with user generated queries

I'm a little dumbfounded that AC doesn't support some kind of mechanism for dynamic queries. The promise of GQL has always been no over-fetching/under-fetching. In GraphiQL yes... you can enter only the fields you want. But, in the real world you need an HOC and all kinds of problematic hacks. As the complexity of GQL applications grow, so will the need for non-static queries.

Was this page helpful?
0 / 5 - 0 ratings