apollo-feature-requests icon indicating copy to clipboard operation
apollo-feature-requests copied to clipboard

Support operationName in client queries

Open dendrochronology opened this issue 7 years ago • 2 comments

I'm using the <Query> component of react-apollo, and I'm looking a simple way to write one GQL file that defines several related operations I might need for a component, which I could then reference by operationName, which Apollo Server supports.

For example, imagine a page of products, and a subnav widget that lets you filter by product category. One queries.gql file could define both a getAllProducts and a getProductsByCategory query. I imagine it looking something like:

<Query query={PRODUCT_QUERIES} operationName={SELECTED_OPERATION || DEFAULT_OPERATION} {...otherProps} />

I know I can just add more component logic to swap out queries, but that seems wrong somehow, given the first-class nature of operationName elsewhere in the GraphQL universe.

A quick google search shows that other folks have wondered why Apollo server supports operationName, but the client does not: https://github.com/apollographql/apollo-client/issues/872

UPDATE: apologies if this request conflates base+react client stuff.

dendrochronology avatar Sep 27 '18 13:09 dendrochronology

I would also like to have this feature. I am very surprised it is not already implemented.

alkismavridis avatar Aug 27 '21 11:08 alkismavridis

Bump, this feature must be implemented.

dimdimych avatar Feb 09 '22 00:02 dimdimych