Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

(graphcache) - improve perf by using String.indexOf in getField (#1957)

* attempt to improve perf by using String.indexOf

* Create afraid-kiwis-end.md

* move to `startsWith` instead

* update changeset

* revert back to indexOf for linter

authored by

Jovi De Croock and committed by
GitHub
d3c452db 9446377a

+13 -4
+5
.changeset/afraid-kiwis-end.md
··· 1 + --- 2 + '@urql/exchange-graphcache': patch 3 + --- 4 + 5 + Improve perf by using String.indexOf in getField
+8 -4
exchanges/graphcache/src/ast/schemaPredicates.ts
··· 11 11 OptimisticMutationConfig, 12 12 } from '../types'; 13 13 14 - const BUILTIN_NAME_RE = /^__/; 14 + const BUILTIN_NAME = '__'; 15 15 16 16 export const isFieldNullable = ( 17 17 schema: SchemaIntrospector, ··· 39 39 typename: string, 40 40 fieldName: string 41 41 ): boolean => 42 - BUILTIN_NAME_RE.test(fieldName) || 43 - BUILTIN_NAME_RE.test(typename) || 42 + fieldName.indexOf(BUILTIN_NAME) === 0 || 43 + typename.indexOf(BUILTIN_NAME) === 0 || 44 44 !!getField(schema, typename, fieldName); 45 45 46 46 export const isInterfaceOfType = ( ··· 69 69 typename: string, 70 70 fieldName: string 71 71 ) => { 72 - if (BUILTIN_NAME_RE.test(typename) || BUILTIN_NAME_RE.test(fieldName)) return; 72 + if ( 73 + fieldName.indexOf(BUILTIN_NAME) === 0 || 74 + typename.indexOf(BUILTIN_NAME) === 0 75 + ) 76 + return; 73 77 74 78 expectObjectType(schema, typename); 75 79 const object = schema.types![typename] as SchemaObject;