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,CAAC;aACjB;YAED,IAAI,uBAAuB,CAAC,QAAQ,CAAC;gBACjC,uBAAuB,CAAC,QAAQ,CAAC,EAAE;gBACrC,6BAAY,QAAQ,GAAK,QAAQ,EAAG;aACrC;SACF;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { invariant, InvariantError } from '../../utilities/globals';\n\nimport {\n InlineFragmentNode,\n FragmentDefinitionNode,\n SelectionSetNode,\n FieldNode,\n} from 'graphql';\n\nimport {\n FragmentMap,\n storeKeyNameFromField,\n StoreValue,\n StoreObject,\n argumentsObjectFromField,\n Reference,\n isReference,\n getStoreKeyName,\n isNonNullObject,\n stringifyForDisplay,\n} from '../../utilities';\nimport {\n IdGetter,\n MergeInfo,\n NormalizedCache,\n ReadMergeModifyContext,\n} from \"./types\";\nimport {\n hasOwn,\n fieldNameFromStoreName,\n storeValueIsStoreObject,\n selectionSetMatchesResult,\n TypeOrFieldNameRegExp,\n defaultDataIdFromObject,\n isArray,\n} from './helpers';\nimport { cacheSlot } from './reactiveVars';\nimport { InMemoryCache } from './inMemoryCache';\nimport {\n SafeReadonly,\n FieldSpecifier,\n ToReferenceFunction,\n ReadFieldFunction,\n ReadFieldOptions,\n CanReadFunction,\n} from '../core/types/common';\nimport { WriteContext } from './writeToStore';\n\n// Upgrade to a faster version of the default stable JSON.stringify function\n// used by getStoreKeyName. This function is used when computing storeFieldName\n// strings (when no keyArgs has been configured for a field).\nimport { canonicalStringify } from './object-canon';\nimport { keyArgsFnFromSpecifier, keyFieldsFnFromSpecifier } from './key-extractor';\n\ngetStoreKeyName.setStringify(canonicalStringify);\n\nexport type TypePolicies = {\n [__typename: string]: TypePolicy;\n}\n\n// TypeScript 3.7 will allow recursive type aliases, so this should work:\n// type KeySpecifier = (string | KeySpecifier)[]\nexport type KeySpecifier = ReadonlyArray<string | KeySpecifier>;\n\nexport type KeyFieldsContext = {\n // The __typename of the incoming object, even if the __typename field was\n // aliased to another name in the raw result object. May be undefined when\n // dataIdFromObject is called for objects without __typename fields.\n typename: string | undefined;\n\n // The object to be identified, after processing to remove aliases and\n // normalize identifiable child objects with references.\n storeObject: StoreObject;\n\n // Handy tool for reading additional fields from context.storeObject, either\n // readField(\"fieldName\") to read storeObject[fieldName], or readField(\"name\",\n // objectOrReference) to read from another object or Reference. If you read a\n // field with a read function, that function will be invoked.\n readField: ReadFieldFunction;\n\n // If you are writing a custom keyFields function, and you plan to use the raw\n // result object passed as the first argument, you may also need access to the\n // selection set and available fragments for this object, just in case any\n // fields have aliases. Since this logic is tricky to get right, and these\n // context properties are not even always provided (for example, they are\n // omitted when calling cache.identify(object), where object is assumed to be\n // a StoreObject), we recommend you use context.storeObject (which has already\n // been de-aliased) and context.readField (which can read from references as\n // well as objects) instead of the raw result object in your keyFields\n // functions, or just rely on the internal implementation of keyFields:[...]\n // syntax to get these details right for you.\n selectionSet?: SelectionSetNode;\n fragmentMap?: FragmentMap;\n\n // Internal. May be set by the KeyFieldsFunction to report fields that were\n // involved in computing the ID. Never passed in by the caller.\n keyObject?: Record<string, any>;\n};\n\nexport type KeyFieldsFunction = (\n object: Readonly<StoreObject>,\n context: KeyFieldsContext,\n) => KeySpecifier | false | ReturnType<IdGetter>;\n\ntype KeyFieldsResult = Exclude<ReturnType<KeyFieldsFunction>, KeySpecifier>;\n\n// TODO Should TypePolicy be a generic type, with a TObject or TEntity\n// type parameter?\nexport type TypePolicy = {\n // Allows defining the primary key fields for this type, either using an\n // array of field names or a function that returns an arbitrary string.\n keyFields?: KeySpecifier | KeyFieldsFunction | false;\n\n // Allows defining a merge function (or merge:true/false shorthand) to\n // be used for merging objects of this type wherever they appear, unless\n // the parent field also defines a merge function/boolean (that is,\n // parent field merge functions take precedence over type policy merge\n // functions). In many cases, defining merge:true for a given type\n // policy can save you from specifying merge:true for all the field\n // policies where that type might be encountered.\n merge?: FieldMergeFunction | boolean;\n\n // In the rare event that your schema happens to use a different\n // __typename for the root Query, Mutation, and/or Schema types, you can\n // express your deviant preferences by enabling one of these options.\n queryType?: true,\n mutationType?: true,\n subscriptionType?: true,\n\n fields?: {\n [fieldName: string]:\n | FieldPolicy<any>\n | FieldReadFunction<any>;\n }\n};\n\nexport type KeyArgsFunction = (\n args: Record<string, any> | null,\n context: {\n typename: string;\n fieldName: string;\n field: FieldNode | null;\n variables?: Record<string, any>;\n },\n) => KeySpecifier | false | ReturnType<IdGetter>;\n\nexport type FieldPolicy<\n // The internal representation used to store the field's data in the\n // cache. Must be JSON-serializable if you plan to serialize the result\n // of cache.extract() using JSON.\n TExisting = any,\n // The type of the incoming parameter passed to the merge function,\n // typically matching the GraphQL response format, but with Reference\n // objects substituted for any identifiable child objects. Often the\n // same as TExisting, but not necessarily.\n TIncoming = TExisting,\n // The type that the read function actually returns, using TExisting\n // data and options.args as input. Usually the same as TIncoming.\n TReadResult = TIncoming,\n // Allows FieldFunctionOptions definition to be overwritten by the\n // developer\n TOptions extends FieldFunctionOptions = FieldFunctionOptions\n> = {\n keyArgs?: KeySpecifier | KeyArgsFunction | false;\n read?: FieldReadFunction<TExisting, TReadResult, TOptions>;\n merge?: FieldMergeFunction<TExisting, TIncoming, TOptions> | boolean;\n};\n\nexport type StorageType = Record<string, any>;\n\nfunction argsFromFieldSpecifier(spec: FieldSpecifier) {\n return spec.args !== void 0 ? spec.args :\n spec.field ? argumentsObjectFromField(spec.field, spec.variables) : null;\n}\n\nexport interface FieldFunctionOptions<\n TArgs = Record<string, any>,\n TVars = Record<string, any>,\n> {\n args: TArgs | null;\n\n // The name of the field, equal to options.field.name.value when\n // options.field is available. Useful if you reuse the same function for\n // multiple fields, and you need to know which field you're currently\n // processing. Always a string, even when options.field is null.\n fieldName: string;\n\n // The full field key used internally, including serialized key arguments.\n storeFieldName: string;\n\n // The FieldNode object used to read this field. Useful if you need to\n // know about other attributes of the field, such as its directives. This\n // option will be null when a string was passed to options.readField.\n field: FieldNode | null;\n\n variables?: TVars;\n\n // Utilities for dealing with { __ref } objects.\n isReference: typeof isReference;\n toReference: ToReferenceFunction;\n\n // A handy place to put field-specific data that you want to survive\n // across multiple read function calls. Useful for field-level caching,\n // if your read function does any expensive work.\n storage: StorageType;\n\n cache: InMemoryCache;\n\n // Helper function for reading other fields within the current object.\n // If a foreign object or reference is provided, the field will be read\n // from that object instead of the current object, so this function can\n // be used (together with isReference) to examine the cache outside the\n // current object. If a FieldNode is passed instead of a string, and\n // that FieldNode has arguments, the same options.variables will be used\n // to compute the argument values. Note that this function will invoke\n // custom read functions for other fields, if defined. Always returns\n // immutable data (enforced with Object.freeze in development).\n readField: ReadFieldFunction;\n\n // Returns true for non-normalized StoreObjects and non-dangling\n // References, indicating that readField(name, objOrRef) has a chance of\n // working. Useful for filtering out dangling references from lists.\n canRead: CanReadFunction;\n\n // Instead of just merging objects with { ...existing, ...incoming }, this\n // helper function can be used to merge objects in a way that respects any\n // custom merge functions defined for their fields.\n mergeObjects: MergeObjectsFunction;\n}\n\ntype MergeObjectsFunction = <T extends StoreObject | Reference>(\n existing: T,\n incoming: T,\n) => T;\n\nexport type FieldReadFunction<\n TExisting = any,\n TReadResult = TExisting,\n TOptions extends FieldFunctionOptions = FieldFunctionOptions\n> = (\n // When reading a field, one often needs to know about any existing\n // value stored for that field. If the field is read before any value\n // has been written to the cache, this existing parameter will be\n // undefined, which makes it easy to use a default parameter expression\n // to supply the initial value. This parameter is positional (rather\n // than one of the named options) because that makes it possible for the\n // developer to annotate it with a type, without also having to provide\n // a whole new type for the options object.\n existing: SafeReadonly<TExisting> | undefined,\n options: TOptions,\n) => TReadResult | undefined;\n\nexport type FieldMergeFunction<\n TExisting = any,\n TIncoming = TExisting,\n // Passing the whole FieldFunctionOptions makes the current definition\n // independent from its implementation\n TOptions extends FieldFunctionOptions = FieldFunctionOptions\n> = (\n existing: SafeReadonly<TExisting> | undefined,\n // The incoming parameter needs to be positional as well, for the same\n // reasons discussed in FieldReadFunction above.\n incoming: SafeReadonly<TIncoming>,\n options: TOptions,\n) => SafeReadonly<TExisting>;\n\nconst nullKeyFieldsFn: KeyFieldsFunction = () => void 0;\nconst simpleKeyArgsFn: KeyArgsFunction = (_args, context) => context.fieldName;\n\n// These merge functions can be selected by specifying merge:true or\n// merge:false in a field policy.\nconst mergeTrueFn: FieldMergeFunction<any> =\n (existing, incoming, { mergeObjects }) => mergeObjects(existing, incoming);\nconst mergeFalseFn: FieldMergeFunction<any> = (_, incoming) => incoming;\n\nexport type PossibleTypesMap = {\n [supertype: string]: string[];\n};\n\nexport class Policies {\n private typePolicies: {\n [__typename: string]: {\n keyFn?: KeyFieldsFunction;\n merge?: FieldMergeFunction<any>;\n fields: {\n [fieldName: string]: {\n keyFn?: KeyArgsFunction;\n read?: FieldReadFunction<any>;\n merge?: FieldMergeFunction<any>;\n };\n };\n };\n } = Object.create(null);\n\n private toBeAdded: {\n [__typename: string]: TypePolicy[];\n } = Object.create(null);\n\n // Map from subtype names to sets of supertype names. Note that this\n // representation inverts the structure of possibleTypes (whose keys are\n // supertypes and whose values are arrays of subtypes) because it tends\n // to be much more efficient to search upwards than downwards.\n private supertypeMap = new Map<string, Set<string>>();\n\n // Any fuzzy subtypes specified by possibleTypes will be converted to\n // RegExp objects and recorded here. Every key of this map can also be\n // found in supertypeMap. In many cases this Map will be empty, which\n // means no fuzzy subtype checking will happen in fragmentMatches.\n private fuzzySubtypes = new Map<string, RegExp>();\n\n public readonly cache: InMemoryCache;\n\n public readonly rootIdsByTypename: Record<string, string> = Object.create(null);\n public readonly rootTypenamesById: Record<string, string> = Object.create(null);\n\n public readonly usingPossibleTypes = false;\n\n constructor(private config: {\n cache: InMemoryCache;\n dataIdFromObject?: KeyFieldsFunction;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n }) {\n this.config = {\n dataIdFromObject: defaultDataIdFromObject,\n ...config,\n };\n\n this.cache = this.config.cache;\n\n this.setRootTypename(\"Query\");\n this.setRootTypename(\"Mutation\");\n this.setRootTypename(\"Subscription\");\n\n if (config.possibleTypes) {\n this.addPossibleTypes(config.possibleTypes);\n }\n\n if (config.typePolicies) {\n this.addTypePolicies(config.typePolicies);\n }\n }\n\n public identify(\n object: StoreObject,\n partialContext?: Partial<KeyFieldsContext>,\n ): [string?, StoreObject?] {\n const policies = this;\n\n const typename = partialContext && (\n partialContext.typename ||\n partialContext.storeObject?.__typename\n ) || object.__typename;\n\n // It should be possible to write root Query fields with writeFragment,\n // using { __typename: \"Query\", ... } as the data, but it does not make\n // sense to allow the same identification behavior for the Mutation and\n // Subscription types, since application code should never be writing\n // directly to (or reading directly from) those root objects.\n if (typename === this.rootTypenamesById.ROOT_QUERY) {\n return [\"ROOT_QUERY\"];\n }\n\n // Default context.storeObject to object if not otherwise provided.\n const storeObject = partialContext && partialContext.storeObject || object;\n\n const context: KeyFieldsContext = {\n ...partialContext,\n typename,\n storeObject,\n readField: partialContext && partialContext.readField || function () {\n const options = normalizeReadFieldOptions(arguments, storeObject);\n return policies.readField(options, {\n store: policies.cache[\"data\"],\n variables: options.variables,\n });\n },\n };\n\n let id: KeyFieldsResult;\n\n const policy = typename && this.getTypePolicy(typename);\n let keyFn = policy && policy.keyFn || this.config.dataIdFromObject;\n while (keyFn) {\n const specifierOrId = keyFn(object, context);\n if (isArray(specifierOrId)) {\n keyFn = keyFieldsFnFromSpecifier(specifierOrId);\n } else {\n id = specifierOrId;\n break;\n }\n }\n\n id = id ? String(id) : void 0;\n return context.keyObject ? [id, context.keyObject] : [id];\n }\n\n public addTypePolicies(typePolicies: TypePolicies) {\n Object.keys(typePolicies).forEach(typename => {\n const {\n queryType,\n mutationType,\n subscriptionType,\n ...incoming\n } = typePolicies[typename];\n\n // Though {query,mutation,subscription}Type configurations are rare,\n // it's important to call setRootTypename as early as possible,\n // since these configurations should apply consistently for the\n // entire lifetime of the cache. Also, since only one __typename can\n // qualify as one of these root types, these three properties cannot\n // be inherited, unlike the rest of the incoming properties. That\n // restriction is convenient, because the purpose of this.toBeAdded\n // is to delay the processing of type/field policies until the first\n // time they're used, allowing policies to be added in any order as\n // long as all relevant policies (including policies for supertypes)\n // have been added by the time a given policy is used for the first\n // time. In other words, since inheritance doesn't matter for these\n // properties, there's also no need to delay their processing using\n // the this.toBeAdded queue.\n if (queryType) this.setRootTypename(\"Query\", typename);\n if (mutationType) this.setRootTypename(\"Mutation\", typename);\n if (subscriptionType) this.setRootTypename(\"Subscription\", typename);\n\n if (hasOwn.call(this.toBeAdded, typename)) {\n this.toBeAdded[typename].push(incoming);\n } else {\n this.toBeAdded[typename] = [incoming];\n }\n });\n }\n\n private updateTypePolicy(typename: string, incoming: TypePolicy) {\n const existing = this.getTypePolicy(typename);\n const { keyFields, fields } = incoming;\n\n function setMerge(\n existing: { merge?: FieldMergeFunction | boolean; },\n merge?: FieldMergeFunction | boolean,\n ) {\n existing.merge =\n typeof merge === \"function\" ? merge :\n // Pass merge:true as a shorthand for a merge implementation\n // that returns options.mergeObjects(existing, incoming).\n merge === true ? mergeTrueFn :\n // Pass merge:false to make incoming always replace existing\n // without any warnings about data clobbering.\n merge === false ? mergeFalseFn :\n existing.merge;\n }\n\n // Type policies can define merge functions, as an alternative to\n // using field policies to merge child objects.\n setMerge(existing, incoming.merge);\n\n existing.keyFn =\n // Pass false to disable normalization for this typename.\n keyFields === false ? nullKeyFieldsFn :\n // Pass an array of strings to use those fields to compute a\n // composite ID for objects of this typename.\n isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields) :\n // Pass a function to take full control over identification.\n typeof keyFields === \"function\" ? keyFields :\n // Leave existing.keyFn unchanged if above cases fail.\n existing.keyFn;\n\n if (fields) {\n Object.keys(fields).forEach(fieldName => {\n const existing = this.getFieldPolicy(typename, fieldName, true)!;\n const incoming = fields[fieldName];\n\n if (typeof incoming === \"function\") {\n existing.read = incoming;\n } else {\n const { keyArgs, read, merge } = incoming;\n\n existing.keyFn =\n // Pass false to disable argument-based differentiation of\n // field identities.\n keyArgs === false ? simpleKeyArgsFn :\n // Pass an array of strings to use named arguments to\n // compute a composite identity for the field.\n isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs) :\n // Pass a function to take full control over field identity.\n typeof keyArgs === \"function\" ? keyArgs :\n // Leave existing.keyFn unchanged if above cases fail.\n existing.keyFn;\n\n if (typeof read === \"function\") {\n existing.read = read;\n }\n\n setMerge(existing, merge);\n }\n\n if (existing.read && existing.merge) {\n // If we have both a read and a merge function, assume\n // keyArgs:false, because read and merge together can take\n // responsibility for interpreting arguments in and out. This\n // default assumption can always be overridden by specifying\n // keyArgs explicitly in the FieldPolicy.\n existing.keyFn = existing.keyFn || simpleKeyArgsFn;\n }\n });\n }\n }\n\n private setRootTypename(\n which: \"Query\" | \"Mutation\" | \"Subscription\",\n typename: string = which,\n ) {\n const rootId = \"ROOT_\" + which.toUpperCase();\n const old = this.rootTypenamesById[rootId];\n if (typename !== old) {\n invariant(!old || old === which, `Cannot change root ${which} __typename more than once`);\n // First, delete any old __typename associated with this rootId from\n // rootIdsByTypename.\n if (old) delete this.rootIdsByTypename[old];\n // Now make this the only __typename that maps to this rootId.\n this.rootIdsByTypename[typename] = rootId;\n // Finally, update the __typename associated with this rootId.\n this.rootTypenamesById[rootId] = typename;\n }\n }\n\n public addPossibleTypes(possibleTypes: PossibleTypesMap) {\n (this.usingPossibleTypes as boolean) = true;\n Object.keys(possibleTypes).forEach(supertype => {\n // Make sure all types have an entry in this.supertypeMap, even if\n // their supertype set is empty, so we can return false immediately\n // from policies.fragmentMatches for unknown supertypes.\n this.getSupertypeSet(supertype, true);\n\n possibleTypes[supertype].forEach(subtype => {\n this.getSupertypeSet(subtype, true)!.add(supertype);\n const match = subtype.match(TypeOrFieldNameRegExp);\n if (!match || match[0] !== subtype) {\n // TODO Don't interpret just any invalid typename as a RegExp.\n this.fuzzySubtypes.set(subtype, new RegExp(subtype));\n }\n });\n });\n }\n\n private getTypePolicy(typename: string): Policies[\"typePolicies\"][string] {\n if (!hasOwn.call(this.typePolicies, typename)) {\n const policy: Policies[\"typePolicies\"][string] =\n this.typePolicies[typename] = Object.create(null);\n policy.fields = Object.create(null);\n\n // When the TypePolicy for typename is first accessed, instead of\n // starting with an empty policy object, inherit any properties or\n // fields from the type policies of the supertypes of typename.\n //\n // Any properties or fields defined explicitly within the TypePolicy\n // for typename will take precedence, and if there are multiple\n // supertypes, the properties of policies whose types were added\n // later via addPossibleTypes will take precedence over those of\n // earlier supertypes. TODO Perhaps we should warn about these\n // conflicts in development, and recommend defining the property\n // explicitly in the subtype policy?\n //\n // Field policy inheritance is atomic/shallow: you can't inherit a\n // field policy and then override just its read function, since read\n // and merge functions often need to cooperate, so changing only one\n // of them would be a recipe for inconsistency.\n //\n // Once the TypePolicy for typename has been accessed, its\n // properties can still be updated directly using addTypePolicies,\n // but future changes to supertype policies will not be reflected in\n // this policy, because this code runs at most once per typename.\n const supertypes = this.supertypeMap.get(typename);\n if (supertypes && supertypes.size) {\n supertypes.forEach(supertype => {\n const { fields, ...rest } = this.getTypePolicy(supertype);\n Object.assign(policy, rest);\n Object.assign(policy.fields, fields);\n });\n }\n }\n\n const inbox = this.toBeAdded[typename];\n if (inbox && inbox.length) {\n // Merge the pending policies into this.typePolicies, in the order they\n // were originally passed to addTypePolicy.\n inbox.splice(0).forEach(policy => {\n this.updateTypePolicy(typename, policy);\n });\n }\n\n return this.typePolicies[typename];\n }\n\n private getFieldPolicy(\n typename: string | undefined,\n fieldName: string,\n createIfMissing: boolean,\n ): {\n keyFn?: KeyArgsFunction;\n read?: FieldReadFunction<any>;\n merge?: FieldMergeFunction<any>;\n } | undefined {\n if (typename) {\n const fieldPolicies = this.getTypePolicy(typename).fields;\n return fieldPolicies[fieldName] || (\n createIfMissing && (fieldPolicies[fieldName] = Object.create(null)));\n }\n }\n\n private getSupertypeSet(\n subtype: string,\n createIfMissing: boolean,\n ): Set<string> | undefined {\n let supertypeSet = this.supertypeMap.get(subtype);\n if (!supertypeSet && createIfMissing) {\n this.supertypeMap.set(subtype, supertypeSet = new Set<string>());\n }\n return supertypeSet;\n }\n\n public fragmentMatches(\n fragment: InlineFragmentNode | FragmentDefinitionNode,\n typename: string | undefined,\n result?: Record<string, any>,\n variables?: Record<string, any>,\n ): boolean {\n if (!fragment.typeCondition) return true;\n\n // If the fragment has a type condition but the object we're matching\n // against does not have a __typename, the fragment cannot match.\n if (!typename) return false;\n\n const supertype = fragment.typeCondition.name.value;\n // Common case: fragment type condition and __typename are the same.\n if (typename === supertype) return true;\n\n if (this.usingPossibleTypes &&\n this.supertypeMap.has(supertype)) {\n const typenameSupertypeSet = this.getSupertypeSet(typename, true)!;\n const workQueue = [typenameSupertypeSet];\n const maybeEnqueue = (subtype: string) => {\n const supertypeSet = this.getSupertypeSet(subtype, false);\n if (supertypeSet &&\n supertypeSet.size &&\n workQueue.indexOf(supertypeSet) < 0) {\n workQueue.push(supertypeSet);\n }\n };\n\n // We need to check fuzzy subtypes only if we encountered fuzzy\n // subtype strings in addPossibleTypes, and only while writing to\n // the cache, since that's when selectionSetMatchesResult gives a\n // strong signal of fragment matching. The StoreReader class calls\n // policies.fragmentMatches without passing a result object, so\n // needToCheckFuzzySubtypes is always false while reading.\n let needToCheckFuzzySubtypes = !!(result && this.fuzzySubtypes.size);\n let checkingFuzzySubtypes = false;\n\n // It's important to keep evaluating workQueue.length each time through\n // the loop, because the queue can grow while we're iterating over it.\n for (let i = 0; i < workQueue.length; ++i) {\n const supertypeSet = workQueue[i];\n\n if (supertypeSet.has(supertype)) {\n if (!typenameSupertypeSet.has(supertype)) {\n if (checkingFuzzySubtypes) {\n invariant.warn(`Inferring subtype ${typename} of supertype ${supertype}`);\n }\n // Record positive results for faster future lookup.\n // Unfortunately, we cannot safely cache negative results,\n // because new possibleTypes data could always be added to the\n // Policies class.\n typenameSupertypeSet.add(supertype);\n }\n return true;\n }\n\n supertypeSet.forEach(maybeEnqueue);\n\n if (needToCheckFuzzySubtypes &&\n // Start checking fuzzy subtypes only after exhausting all\n // non-fuzzy subtypes (after the final iteration of the loop).\n i === workQueue.length - 1 &&\n // We could wait to compare fragment.selectionSet to result\n // after we verify the supertype, but this check is often less\n // expensive than that search, and we will have to do the\n // comparison anyway whenever we find a potential match.\n selectionSetMatchesResult(fragment.selectionSet, result!, variables)) {\n // We don't always need to check fuzzy subtypes (if no result\n // was provided, or !this.fuzzySubtypes.size), but, when we do,\n // we only want to check them once.\n needToCheckFuzzySubtypes = false;\n checkingFuzzySubtypes = true;\n\n // If we find any fuzzy subtypes that match typename, extend the\n // workQueue to search through the supertypes of those fuzzy\n // subtypes. Otherwise the for-loop will terminate and we'll\n // return false below.\n this.fuzzySubtypes.forEach((regExp, fuzzyString) => {\n const match = typename.match(regExp);\n if (match && match[0] === typename) {\n maybeEnqueue(fuzzyString);\n }\n });\n }\n }\n }\n\n return false;\n }\n\n public hasKeyArgs(typename: string | undefined, fieldName: string) {\n const policy = this.getFieldPolicy(typename, fieldName, false);\n return !!(policy && policy.keyFn);\n }\n\n public getStoreFieldName(fieldSpec: FieldSpecifier): string {\n const { typename, fieldName } = fieldSpec;\n const policy = this.getFieldPolicy(typename, fieldName, false);\n let storeFieldName: Exclude<ReturnType<KeyArgsFunction>, KeySpecifier>;\n\n let keyFn = policy && policy.keyFn;\n if (keyFn && typename) {\n const context: Parameters<KeyArgsFunction>[1] = {\n typename,\n fieldName,\n field: fieldSpec.field || null,\n variables: fieldSpec.variables,\n };\n const args = argsFromFieldSpecifier(fieldSpec);\n while (keyFn) {\n const specifierOrString = keyFn(args, context);\n if (isArray(specifierOrString)) {\n keyFn = keyArgsFnFromSpecifier(specifierOrString);\n } else {\n // If the custom keyFn returns a falsy value, fall back to\n // fieldName instead.\n storeFieldName = specifierOrString || fieldName;\n break;\n }\n }\n }\n\n if (storeFieldName === void 0) {\n storeFieldName = fieldSpec.field\n ? storeKeyNameFromField(fieldSpec.field, fieldSpec.variables)\n : getStoreKeyName(fieldName, argsFromFieldSpecifier(fieldSpec));\n }\n\n // Returning false from a keyArgs function is like configuring\n // keyArgs: false, but more dynamic.\n if (storeFieldName === false) {\n return fieldName;\n }\n\n // Make sure custom field names start with the actual field.name.value\n // of the field, so we can always figure out which properties of a\n // StoreObject correspond to which original field names.\n return fieldName === fieldNameFromStoreName(storeFieldName)\n ? storeFieldName\n : fieldName + \":\" + storeFieldName;\n }\n\n public readField<V = StoreValue>(\n options: ReadFieldOptions,\n context: ReadMergeModifyContext,\n ): SafeReadonly<V> | undefined {\n const objectOrReference = options.from;\n if (!objectOrReference) return;\n\n const nameOrField = options.field || options.fieldName;\n if (!nameOrField) return;\n\n if (options.typename === void 0) {\n const typename = context.store.getFieldValue<string>(objectOrReference, \"__typename\");\n if (typename) options.typename = typename;\n }\n\n const storeFieldName = this.getStoreFieldName(options);\n const fieldName = fieldNameFromStoreName(storeFieldName);\n const existing = context.store.getFieldValue<V>(objectOrReference, storeFieldName);\n const policy = this.getFieldPolicy(options.typename, fieldName, false);\n const read = policy && policy.read;\n\n if (read) {\n const readOptions = makeFieldFunctionOptions(\n this,\n objectOrReference,\n options,\n context,\n context.store.getStorage(\n isReference(objectOrReference)\n ? objectOrReference.__ref\n : objectOrReference,\n storeFieldName,\n ),\n );\n\n // Call read(existing, readOptions) with cacheSlot holding this.cache.\n return cacheSlot.withValue(\n this.cache,\n read,\n [existing, readOptions],\n ) as SafeReadonly<V>;\n }\n\n return existing;\n }\n\n public getReadFunction(\n typename: string | undefined,\n fieldName: string,\n ): FieldReadFunction | undefined {\n const policy = this.getFieldPolicy(typename, fieldName, false);\n return policy && policy.read;\n }\n\n public getMergeFunction(\n parentTypename: string | undefined,\n fieldName: string,\n childTypename: string | undefined,\n ): FieldMergeFunction | undefined {\n let policy:\n | Policies[\"typePolicies\"][string]\n | Policies[\"typePolicies\"][string][\"fields\"][string]\n | undefined =\n this.getFieldPolicy(parentTypename, fieldName, false);\n let merge = policy && policy.merge;\n if (!merge && childTypename) {\n policy = this.getTypePolicy(childTypename);\n merge = policy && policy.merge;\n }\n return merge;\n }\n\n public runMergeFunction(\n existing: StoreValue,\n incoming: StoreValue,\n { field, typename, merge }: MergeInfo,\n context: WriteContext,\n storage?: StorageType,\n ) {\n if (merge === mergeTrueFn) {\n // Instead of going to the trouble of creating a full\n // FieldFunctionOptions object and calling mergeTrueFn, we can\n // simply call mergeObjects, as mergeTrueFn would.\n return makeMergeObjectsFunction(\n context.store,\n )(existing as StoreObject,\n incoming as StoreObject);\n }\n\n if (merge === mergeFalseFn) {\n // Likewise for mergeFalseFn, whose implementation is even simpler.\n return incoming;\n }\n\n // If cache.writeQuery or cache.writeFragment was called with\n // options.overwrite set to true, we still call merge functions, but\n // the existing data is always undefined, so the merge function will\n // not attempt to combine the incoming data with the existing data.\n if (context.overwrite) {\n existing = void 0;\n }\n\n return merge(existing, incoming, makeFieldFunctionOptions(\n this,\n // Unlike options.readField for read functions, we do not fall\n // back to the current object if no foreignObjOrRef is provided,\n // because it's not clear what the current object should be for\n // merge functions: the (possibly undefined) existing object, or\n // the incoming object? If you think your merge function needs\n // to read sibling fields in order to produce a new value for\n // the current field, you might want to rethink your strategy,\n // because that's a recipe for making merge behavior sensitive\n // to the order in which fields are written into the cache.\n // However, readField(name, ref) is useful for merge functions\n // that need to deduplicate child objects and references.\n void 0,\n { typename,\n fieldName: field.name.value,\n field,\n variables: context.variables },\n context,\n storage || Object.create(null),\n ));\n }\n}\n\nfunction makeFieldFunctionOptions(\n policies: Policies,\n objectOrReference: StoreObject | Reference | undefined,\n fieldSpec: FieldSpecifier,\n context: ReadMergeModifyContext,\n storage: StorageType,\n): FieldFunctionOptions {\n const storeFieldName = policies.getStoreFieldName(fieldSpec);\n const fieldName = fieldNameFromStoreName(storeFieldName);\n const variables = fieldSpec.variables || context.variables;\n const { toReference, canRead } = context.store;\n\n return {\n args: argsFromFieldSpecifier(fieldSpec),\n field: fieldSpec.field || null,\n fieldName,\n storeFieldName,\n variables,\n isReference,\n toReference,\n storage,\n cache: policies.cache,\n canRead,\n readField<T>() {\n return policies.readField<T>(\n normalizeReadFieldOptions(arguments, objectOrReference, variables),\n context,\n );\n },\n mergeObjects: makeMergeObjectsFunction(context.store),\n };\n}\n\nexport function normalizeReadFieldOptions(\n readFieldArgs: IArguments,\n objectOrReference: StoreObject | Reference | undefined,\n variables?: ReadMergeModifyContext[\"variables\"],\n): ReadFieldOptions {\n const {\n 0: fieldNameOrOptions,\n 1: from,\n length: argc,\n } = readFieldArgs;\n\n let options: ReadFieldOptions;\n\n if (typeof fieldNameOrOptions === \"string\") {\n options = {\n fieldName: fieldNameOrOptions,\n // Default to objectOrReference only when no second argument was\n // passed for the from parameter, not when undefined is explicitly\n // passed as the second argument.\n from: argc > 1 ? from : objectOrReference,\n };\n } else {\n options = { ...fieldNameOrOptions };\n // Default to objectOrReference only when fieldNameOrOptions.from is\n // actually omitted, rather than just undefined.\n if (!hasOwn.call(options, \"from\")) {\n options.from = objectOrReference;\n }\n }\n\n if (__DEV__ && options.from === void 0) {\n invariant.warn(`Undefined 'from' passed to readField with arguments ${\n stringifyForDisplay(Array.from(readFieldArgs))\n }`);\n }\n\n if (void 0 === options.variables) {\n options.variables = variables;\n }\n\n return options;\n}\n\nfunction makeMergeObjectsFunction(\n store: NormalizedCache,\n): MergeObjectsFunction {\n return function mergeObjects(existing, incoming) {\n if (isArray(existing) || isArray(incoming)) {\n throw new InvariantError(\"Cannot automatically merge arrays\");\n }\n\n // These dynamic checks are necessary because the parameters of a\n // custom merge function can easily have the any type, so the type\n // system cannot always enforce the StoreObject | Reference parameter\n // types of options.mergeObjects.\n if (isNonNullObject(existing) &&\n isNonNullObject(incoming)) {\n const eType = store.getFieldValue(existing, \"__typename\");\n const iType = store.getFieldValue(incoming, \"__typename\");\n const typesDiffer = eType && iType && eType !== iType;\n\n if (typesDiffer) {\n return incoming;\n }\n\n if (isReference(existing) &&\n storeValueIsStoreObject(incoming)) {\n // Update the normalized EntityStore for the entity identified by\n // existing.__ref, preferring/overwriting any fields contributed by the\n // newer incoming StoreObject.\n store.merge(existing.__ref, incoming);\n return existing;\n }\n\n if (storeValueIsStoreObject(existing) &&\n isReference(incoming)) {\n // Update the normalized EntityStore for the entity identified by\n // incoming.__ref, taking fields from the older existing object only if\n // those fields are not already present in the newer StoreObject\n // identified by incoming.__ref.\n store.merge(existing, incoming.__ref);\n return incoming;\n }\n\n if (storeValueIsStoreObject(existing) &&\n storeValueIsStoreObject(incoming)) {\n return { ...existing, ...incoming };\n }\n }\n\n return incoming;\n };\n}\n"]}
\No newline at end of file