graphql-react icon indicating copy to clipboard operation
graphql-react copied to clipboard

Support automatic persisted queries

Open shortcircuit3 opened this issue 5 years ago • 2 comments

I’ll be using a go library for the server and I was not sure if this library supported automatic persisted queries

If so, how do I use this functionality?

shortcircuit3 avatar Mar 29 '20 13:03 shortcircuit3

Interesting; at the moment that feature is not supported.

To get it working, we would need to either need to build in support for it (config option, hashing the query, multiple fetch requests per operation), or allow configuring the fetcher for custom implementations.

jaydenseric avatar Apr 06 '20 23:04 jaydenseric

The new graphql-react v13 API has composable React hooks for the separate concerns of reading from the cache vs loading it.

A custom hook could be used as an alternative to useLoadGraphQL, that does the persisted queries stuff instead of a single, normal fetch request. Here is the source for inspiration:

https://github.com/jaydenseric/graphql-react/blob/4ea092280531b4ef62adb02d365e4fbb23e418d8/public/useLoadGraphQL.js#L33

If you know for sure the query is persisted and you don't need to make fallback fetch requests, you could just have some sort of hook/function that creates appropriate fetch options for a persisted query to pass into the normal useLoadGraphQL hook.

jaydenseric avatar Apr 20 '21 07:04 jaydenseric