jaydenseric / graphql-react

A GraphQL client for React using modern context and hooks APIs that is lightweight (< 4 kB) but powerful; the first Relay and Apollo alternative with server side rendering.
https://npm.im/graphql-react
MIT License
717 stars 22 forks source link

Support automatic persisted queries #43

Open shortcircuit3 opened 4 years ago

shortcircuit3 commented 4 years ago

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?

jaydenseric commented 4 years ago

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 commented 3 years ago

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.