diff --git a/.changeset/weak-clocks-yawn.md b/.changeset/weak-clocks-yawn.md new file mode 100644 index 0000000000..d7dc27f063 --- /dev/null +++ b/.changeset/weak-clocks-yawn.md @@ -0,0 +1,5 @@ +--- +'@urql/exchange-graphcache': patch +--- + +Fix Introspection Queries (or internal types in general) triggering lots of warnings for unkeyed entities. diff --git a/exchanges/graphcache/src/operations/write.ts b/exchanges/graphcache/src/operations/write.ts index 70551e2b86..ebe28fea8f 100644 --- a/exchanges/graphcache/src/operations/write.ts +++ b/exchanges/graphcache/src/operations/write.ts @@ -291,6 +291,9 @@ const writeSelection = ( } }; +// A pattern to match typenames of types that are likely never keyable +const KEYLESS_TYPE_RE = /^__|PageInfo|(Connection|Edge)$/; + const writeField = ( ctx: Context, select: SelectionSet, @@ -324,9 +327,7 @@ const writeField = ( ctx.store.keys[data.__typename] === undefined && entityKey === null && typeof typename === 'string' && - !typename.endsWith('Connection') && - !typename.endsWith('Edge') && - typename !== 'PageInfo' + !KEYLESS_TYPE_RE.test(typename) ) { warn( 'Invalid key: The GraphQL query at the field at `' +