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

feat(core/graphcache): Add support for client-side-only directive processing #3317

Merged
merged 9 commits into from
Jul 19, 2023

Conversation

kitten
Copy link
Member

@kitten kitten commented Jul 19, 2023

Summary

When applied, this change alters formatDocument to return a FormattedNode type mapping. This maps GraphQL AST nodes and specifically:

  • adds a _generated: true flag on added __typename fields so Graphcache can identify them as relevant only to introspection
  • adds a _directives: {...} dictionary to selection nodes that contains a mapping of directive names to directive nodes for client-side directives
  • filters directives to not include client-side directives, i.e. directive starting with "_" underscores

This will allow us to implement client-side directives in Graphcache as well as stabilise formatDocument to do more advanced processing of GraphQL ASTs.

Set of changes

  • @urql/core
    • Move formatDocument to core/src/utils/formatDocument.ts
    • Rename internal collectTypesFromResponse to collectTypenames and move it to core/src/utils/collectTypenames.ts
    • Add FormattedNode type mapping for formatDocument
    • Add directive handling to formatDocument
    • Add _generated: true annotation to __typename fields that formatDocument adds
    • Remove hasChanged checks in formatDocument
  • @urql/exchange-graphcache
    • Remove remapping of "original operations" and instead rely on skipping _generated: true in cache reads
    • Use _directives map instead of directives list for @include, @skip and @defer
    • Update to always require FormattedNode AST nodes throughout the codebase

@kitten kitten force-pushed the feat/extended-format-document branch from 687ac5f to c90838b Compare July 19, 2023 13:20
@kitten kitten force-pushed the feat/extended-format-document branch from 6d1bb6d to 49a168e Compare July 19, 2023 13:26
@kitten kitten merged commit d3eb256 into main Jul 19, 2023
6 checks passed
@kitten kitten deleted the feat/extended-format-document branch July 19, 2023 17:01
@github-actions github-actions bot mentioned this pull request Jul 19, 2023
kitten added a commit that referenced this pull request Aug 15, 2023
@github-actions github-actions bot mentioned this pull request Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant