graphql-react
graphql-react copied to clipboard
Support automatic persisted queries
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?
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.
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.