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
Summary
When applied, this change alters
formatDocument
to return aFormattedNode
type mapping. This maps GraphQL AST nodes and specifically:_generated: true
flag on added__typename
fields so Graphcache can identify them as relevant only to introspection_directives: {...}
dictionary to selection nodes that contains a mapping of directive names to directive nodes for client-side directives"_"
underscoresThis 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
formatDocument
tocore/src/utils/formatDocument.ts
collectTypesFromResponse
tocollectTypenames
and move it tocore/src/utils/collectTypenames.ts
FormattedNode
type mapping forformatDocument
formatDocument
_generated: true
annotation to__typename
fields thatformatDocument
addshasChanged
checks informatDocument
@urql/exchange-graphcache
_generated: true
in cache reads_directives
map instead ofdirectives
list for@include
,@skip
and@defer
FormattedNode
AST nodes throughout the codebase