-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial implementation of persisted queries plugin #324
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/theguild/envelop/En2spsP5Nq6WpT2kySkozFdPCw3L |
0f0a317
to
a2e9876
Compare
a2e9876
to
d8d8172
Compare
Adding this separate comment to discuss more the differences with the existing "persist-operations" plugin. In all honesty, I wouldn't even be sure how to add the extra functionalities to the existing plugin without changing the existing API. I could add a simple store implementation that handles static JSON files to the existing plugin, but then developers will still have to build their matching logic to retrieve the stringified documents from the store. My plugin provides a good solution for static JSON files, but this can be used as an example and customised for more complex setups (such as grabbing persisted lists from a database f.i.). Hope this helps. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this concept. I wonder if some of the things can be merged with persisted-operations plugin? 🤔
Some, probably, you could define an easy way to get the id from context and implement default behaviour to get it from GraphQL source. Anything else, like a built-in matching logic that works out-of-the-box with one/multiple lists, would require breaking changes in the plugin. The best way I could think about implementing those functionalities is the way I built this new plugin. So the question still remains. |
@kamilkisiela did
The way I see it, the store should have a single API for
I'm not sure that we have to break it, can you please explain why we can do a single store, that supports multiple files? eventually it doesn't matter which file the data is fetched from, it's just needs the id and the document.
I still think we can find a way to keep the persisted operations API simple as possible, and allow the store to implement any kind of flow. Maybe the API for |
yes, this can easily be added, and also a default behavior to get id from source, as I have implemented here (which is effectively comparable to a default implementation for
The main use case is to support multiple applications. Each application exports its list of persisted queries. Some applications might require one or more exact queries that will have conflicting hashes. The conflict is not necessarily a problem, cause you can ignore duplicate hashes, trusting that their value will always be equal. But when I support multiple applications I might want to tell my server that the requests come from application A and it should match queries only from the list generated by application A rather than all applications supported by my server.
With the context above, if you do want to support multiple lists, you need a signature for the store, which is no longer a simple key/value pair.
This is my main goal, if you look at the README file you can see how you can simply pass one or more json files to the plugin and it works out of the box; the API is damn simple in my view. If you do want to implement your own store, the only overhead I am proposing (to prescript the store shape) is to wrap each list in a Map which key is the name of the list and value is the full object containing hashes and their values.
Do you think the plugin I am proposing would prevent anything here? As for your proposal to extend I am only addressing your points, but really do not feel like I am forcing you to accept this new plugin. |
also better methods naming
also renamed build() to load()
useful to update existing store only on specific lists rather than the full array
adfad62
to
0e80b10
Compare
We are going with #498 , closing. |
Description
This draft PR is for implementing a persisted queries plugin with the following goals:
Since the plugin is meant to support multiple JSON files, it also offers an option to match from a single list only.
This allows developers to implement logic to target a single list, so you can avoid matching against all lists when you know your request comes from a specific application and so must be available in a single list.
The point is not necessarily to improve performance, in fact matching against multiple lists might still be implemented with o(1) cost (since it's just a lookup job), but more about offering proper support for multiple applications; in fact it might be that different applications have one or more equal queries, that would result in the same SHA256 id. By handling multiple and separate queries lists there is no worry of conflicts and file might just be provided to the server as they're generated by clients.
Type of change
How Has This Been Tested?
Being just a draft, this is open for a conversation.
I am planning to add tests once we finalise the strategy.
Checklist:
Further comments
This plugin might be seen in conflict with the existing persisted-oeprations, but it differs as it is more intended (but not limited) to handle static lists.
The main difference is the concept of handling multiple lists to support multiple client applications.
Also this plugin provides an implementation for a store (again targeting a basic usage with static files), which is useful to be used as a guide for developers wanting to implement their own store from other sources (such as databases).
Ultimately I am open to merge the two plugins so that we offer a solution that is flexible enough and provides a basic store implementation.