-
Notifications
You must be signed in to change notification settings - Fork 3
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
How does this compare to graphql-normalizer? #28
Comments
I haven't used graphql-normalizer but it says:
This library OTOH is designed to be as simple and independent (and fast) as possible. It does only normalization (responses to a flat strucutre) and denormalization (flat structure to response). You can use it as a building block to build a normalized client-side cache or you can use it on the server side to normalize (deduplicate) the returned data (although that would require the client to be able to received normalized data and denormalize it before handing it to the app). Not sure if that helps tough, do you have any specific use-case in mind? |
Thanks. That's actually the wrong library. I spelled the name wrong. Here's the one I was referring to: graphql-normalizr. I'm experimenting with creating a lighweight graphql client for svelte.js and was looking for a library helps provide a caching solution similar to Apollo's InMemoryCache. |
Ah, yes that makes more sense. We have the same use-case, building a client-side cache and I looked into that library too. It seems to be similar to this, in fact I started an issue there about aliases since that was not supported. However, since that library did not fully support all of graphql syntax (eg. aliases and probably This library has only graphql-normalizr does have a "addRequiredFields" function that this library does not have. It is handy for adding the |
If you are familiar with the normalizr library, the best way to describe gql-cache would be to say it is the exact same thing except it does not need the |
Awesome. Thanks for taking time to reply and for creating this library. Very useful and a time saver. I'll continue testing to see if I run into any issues. I did notice that the docs needs updating, specifically in regards to the |
Yes, the docs could use some polishing. I think the plan was to rename |
Does this library support arguments on fields? Update: some explanation of the challenges can be found in relay docs: https://relay.dev/docs/en/thinking-in-graphql#populating-the-cache |
All works fine. Thanks for explanation, I’ve already tried :) |
@drejohnson @stalniy FYI, the package has been renamed from gql-cache to graphql-norm. It is basically the same API but I cleaned up a few things. All changes are noted in the changelog. |
@jonaskello , hi! Nice to see you built your own solution to handle your needs. One thing I would like to point out, though: graphql-normalizr doesn't require the |
Yes that's a good point. The reference in the readme is for the paularmstrong/normalizr package. I used that once with graphql and it worked but I had to hand-code normalizr schemas for every part of the graphql schema which is one of the main reasons I went ahead and made graphql-norm. Both graphql-normalizr and graphql-norm have better approaches that are more integrated with graphql. In graphql-norm there are no required fields, instead you pass a callback function that will extract the ID of each object during normalization. That callback can of course use The graphql schema is not required by graphql-norm either but the query is. You can get quite far with normalization without knowing the query but there are some cases that are not possible without it. For example if a field is aliased in the query, the data will only contain the alias, not the original field name from the graphql schema. To know the original name you need the query. If normalization happens using the alias and the same field is queried multiple times with different aliases it will be stored multiple times under different names. Another feature that requires the query during normaliztion is using varriables on fields as they are not derivable from the data alone. @monojack Btw, I think you may have an old version of the readme cached since it referes to the old package name (gql-cache). You may want to refresh to get the latest version. |
No description provided.
The text was updated successfully, but these errors were encountered: