Skip to content
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

AST-based normalization / denormalization #471

Closed
smkhalsa opened this issue Nov 14, 2019 · 5 comments
Closed

AST-based normalization / denormalization #471

smkhalsa opened this issue Nov 14, 2019 · 5 comments
Labels
📦 cache Relates to caching functionality

Comments

@smkhalsa
Copy link
Contributor

With the addition of AST-based operations in #429, I'd like to propose that we implement AST-aware cache normalization / denormalization.

This will allow us to only read the requested fields from the cache, which will allow us to get rid of all the dereferencing code.

It will also make it trivial to implement readQuery / readFragment & writeQuery / writeFragment as requested in #176.

I just published normalize, a GraphQL AST-based normalization library as a first step. I've tested it for all the common use cases, and it currently supports:

  1. Fragments (definitions & inline)
  2. Variables
  3. Unions & Interface types
  4. Type Aliases
  5. Apollo's new TypePolicies (Implement apollo 3's typePolicies #458)

Per @klavs's suggestion, it also addresses #400 as it serializes query fields with their variables (like Apollo does, with optional field-level config via FieldPolicies).

Please let me know your thoughts.

@micimize
Copy link
Collaborator

micimize commented Dec 4, 2019

which will allow us to get rid of all the dereferencing code.

Oh man, finally looking at this and it's super exciting. I can't wait to delete LazyCacheMap now lol

@klavs klavs added the 📦 cache Relates to caching functionality label Feb 18, 2020
This was referenced Apr 18, 2020
@SwannLV
Copy link

SwannLV commented May 8, 2020

Can't wait to have aliases supported in my cache. Could I use it now?

@SwannLV
Copy link

SwannLV commented May 8, 2020

Would it get the cache by looking at if all the fields are in it?
I miss that a lot in my project.
Thank you very much 🙏

@micimize
Copy link
Collaborator

micimize commented May 8, 2020

As mentioned in #629, this will also solve the broken cache behavior of

query queryA {
   abc {
      fieldA, fieldB
   }
}

# resolves the partial from `queryA` which is entirely incorrect
query queryB {
   abc {
      fieldC, fieldD
   }
}

@micimize
Copy link
Collaborator

micimize commented Oct 7, 2020

closed with 4.0.0-beta.1 🙌 I still need to migrate us to normalize ^0.4.0 though 😅

@micimize micimize closed this as completed Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 cache Relates to caching functionality
Projects
None yet
Development

No branches or pull requests

4 participants