From 6f584792a36fcf97b4d696695bba1ebcd80f4731 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Wed, 19 Jul 2023 19:49:18 +0200 Subject: [PATCH] use underscored props --- exchanges/graphcache/src/cacheExchange.test.ts | 4 ++-- exchanges/graphcache/src/cacheExchange.ts | 1 - .../graphcache/src/extras/relayPagination.test.ts | 2 +- .../graphcache/src/extras/simplePagination.test.ts | 2 +- exchanges/graphcache/src/operations/query.ts | 9 +++------ exchanges/graphcache/src/types.ts | 10 ++++++++-- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/exchanges/graphcache/src/cacheExchange.test.ts b/exchanges/graphcache/src/cacheExchange.test.ts index 82777f224b..2dd212beba 100644 --- a/exchanges/graphcache/src/cacheExchange.test.ts +++ b/exchanges/graphcache/src/cacheExchange.test.ts @@ -691,7 +691,7 @@ describe('directives', () => { todos { id text - completed @optional + completed @_optional } } `; @@ -763,7 +763,7 @@ describe('directives', () => { todos { id text - completed @required + completed @_required } } `; diff --git a/exchanges/graphcache/src/cacheExchange.ts b/exchanges/graphcache/src/cacheExchange.ts index b17fbffb88..7d0594e135 100644 --- a/exchanges/graphcache/src/cacheExchange.ts +++ b/exchanges/graphcache/src/cacheExchange.ts @@ -237,7 +237,6 @@ export const cacheExchange = operations.set(operation.key, operation); updateDependencies(operation, result.dependencies); - // TODO: remove directives before sending it on return { outcome: cacheOutcome, operation, diff --git a/exchanges/graphcache/src/extras/relayPagination.test.ts b/exchanges/graphcache/src/extras/relayPagination.test.ts index 29a1486f42..8f45be42b6 100644 --- a/exchanges/graphcache/src/extras/relayPagination.test.ts +++ b/exchanges/graphcache/src/extras/relayPagination.test.ts @@ -1542,7 +1542,7 @@ describe('as directive', () => { const Pagination = gql` query ($cursor: String) { __typename - items(first: 1, after: $cursor) @relayPagination { + items(first: 1, after: $cursor) @_relayPagination { __typename edges { __typename diff --git a/exchanges/graphcache/src/extras/simplePagination.test.ts b/exchanges/graphcache/src/extras/simplePagination.test.ts index d1f1e6242b..a675f1115f 100644 --- a/exchanges/graphcache/src/extras/simplePagination.test.ts +++ b/exchanges/graphcache/src/extras/simplePagination.test.ts @@ -443,7 +443,7 @@ describe('as directive', () => { const Pagination = gql` query ($skip: Number, $limit: Number) { __typename - persons(skip: $skip, limit: $limit) @simplePagination { + persons(skip: $skip, limit: $limit) @_simplePagination { __typename id name diff --git a/exchanges/graphcache/src/operations/query.ts b/exchanges/graphcache/src/operations/query.ts index 6c30f19d79..d4d1d280e1 100644 --- a/exchanges/graphcache/src/operations/query.ts +++ b/exchanges/graphcache/src/operations/query.ts @@ -356,8 +356,8 @@ const readSelection = ( let node: FormattedNode | void; const output = InMemoryData.makeData(input); while ((node = iterate()) !== undefined) { - const fieldDirectives = node.directives?.map(x => x.name.value); - const storeDirective = fieldDirectives?.find(x => store.directives[x]); + const fieldDirectives = Object.keys(node._directives || {}).map(x => x); + const storeDirective = fieldDirectives.find(x => store.directives[x]); // Derive the needed data from our node. const fieldName = getName(node); @@ -415,9 +415,7 @@ const readSelection = ( } if (storeDirective) { - const fieldDirective = node.directives!.find( - x => x.name.value === storeDirective - )!; + const fieldDirective = node._directives![storeDirective]; const directiveArguments = getFieldArguments(fieldDirective, ctx.variables) || {}; dataFieldValue = store.directives[storeDirective]!( @@ -448,7 +446,6 @@ const readSelection = ( if ( store.schema && dataFieldValue === null && - // TODO: how would we inform this that we are indeed dealing with a nullable field !isFieldNullable(store.schema, typename, fieldName) ) { // Special case for when null is not a valid value for the diff --git a/exchanges/graphcache/src/types.ts b/exchanges/graphcache/src/types.ts index f528a8af15..0af5374b2d 100644 --- a/exchanges/graphcache/src/types.ts +++ b/exchanges/graphcache/src/types.ts @@ -555,7 +555,14 @@ export type CacheExchangeOpts = { * @see {@link https://urql.dev/goto/docs/graphcache/local-resolvers} for the full resolvers docs. */ resolvers?: ResolverConfig; - // TODO: docs + /** Configures directives which can perform custom logic on fields. + * + * @remarks + * `directives` is a map of a directive-name to a function which will be executed + * when graphcache encounters this directive. + * + * @see {@link https://urql.dev/goto/docs/graphcache/local-directives} for the full directives docs. + */ directives?: DirectivesConfig; /** Configures optimistic updates to react to mutations instantly before an API response. * @@ -708,7 +715,6 @@ export type ResolverConfig = { } | void; }; -// TODO: docs export type DirectivesConfig = { [directiveName: string]: Directive; };