From ce81cc0802e3968bafcfb765d8c7aa023ac8996d Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Tue, 21 Jul 2020 20:34:25 +0100 Subject: [PATCH] (graphcache) - Mute warnings when using built-in fields See: https://spectrum.chat/urql/help/is-there-a-way-to-access-cache-directly~40669292-345e-4c02-b5ca-64c95f776762?m=MTU5NTIzMDA5MDQ0Ng== --- .changeset/chatty-poems-rescue.md | 5 +++++ exchanges/graphcache/src/ast/schemaPredicates.ts | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/chatty-poems-rescue.md diff --git a/.changeset/chatty-poems-rescue.md b/.changeset/chatty-poems-rescue.md new file mode 100644 index 0000000000..bb4113b61a --- /dev/null +++ b/.changeset/chatty-poems-rescue.md @@ -0,0 +1,5 @@ +--- +'@urql/exchange-graphcache': patch +--- + +Mute warning when using built-in GraphQL fields, like `__type` diff --git a/exchanges/graphcache/src/ast/schemaPredicates.ts b/exchanges/graphcache/src/ast/schemaPredicates.ts index f936711d5d..906e650904 100644 --- a/exchanges/graphcache/src/ast/schemaPredicates.ts +++ b/exchanges/graphcache/src/ast/schemaPredicates.ts @@ -17,12 +17,14 @@ import { OptimisticMutationConfig, } from '../types'; +const BUILTIN_FIELD_RE = /^__/; + export const isFieldNullable = ( schema: GraphQLSchema, typename: string, fieldName: string ): boolean => { - if (fieldName === '__schema') return true; + if (BUILTIN_FIELD_RE.test(fieldName)) return true; const field = getField(schema, typename, fieldName); return !!field && isNullableType(field.type); }; @@ -43,7 +45,7 @@ export const isFieldAvailableOnType = ( typename: string, fieldName: string ): boolean => { - if (fieldName === '__schema') return true; + if (BUILTIN_FIELD_RE.test(fieldName)) return true; return !!getField(schema, typename, fieldName); };