@apollo/client 3.4.4 → 3.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apollo-client.cjs.js +971 -76
- package/apollo-client.cjs.js.map +1 -1
- package/apollo-core.cjs.js +5768 -0
- package/apollo-core.cjs.js.map +1 -0
- package/apollo-core.cjs.min.js +1 -0
- package/cache/cache.cjs.js +12 -9
- package/cache/cache.cjs.js.map +1 -1
- package/cache/inmemory/policies.js +9 -6
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +1 -1
- package/cache/inmemory/writeToStore.d.ts.map +1 -1
- package/cache/inmemory/writeToStore.js +3 -3
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ObservableQuery.d.ts +9 -6
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +70 -45
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +5 -3
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +4 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +3 -3
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +15 -13
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs.js +89 -59
- package/core/core.cjs.js.map +1 -1
- package/core/watchQueryOptions.d.ts +2 -1
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/invariantErrorCodes.js +4 -2
- package/link/http/createHttpLink.d.ts.map +1 -1
- package/link/http/createHttpLink.js +7 -5
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/http.cjs.js +6 -5
- package/link/http/http.cjs.js.map +1 -1
- package/package.json +8 -8
- package/react/data/QueryData.d.ts +2 -1
- package/react/data/QueryData.d.ts.map +1 -1
- package/react/data/QueryData.js +8 -8
- package/react/data/QueryData.js.map +1 -1
- package/react/data/data.cjs.js +8 -8
- package/react/data/data.cjs.js.map +1 -1
- package/react/hooks/hooks.cjs.js +1 -0
- package/react/hooks/hooks.cjs.js.map +1 -1
- package/react/hooks/utils/useBaseQuery.d.ts.map +1 -1
- package/react/hooks/utils/useBaseQuery.js +1 -0
- package/react/hooks/utils/useBaseQuery.js.map +1 -1
- package/testing/testing.cjs.js +0 -5
- package/testing/testing.cjs.js.map +1 -1
- package/utilities/index.d.ts +1 -0
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/testing/index.d.ts +0 -1
- package/utilities/testing/index.d.ts.map +1 -1
- package/utilities/testing/index.js +0 -1
- package/utilities/testing/index.js.map +1 -1
- package/utilities/utilities.cjs.js +1 -0
- package/utilities/utilities.cjs.js.map +1 -1
- package/version.js +1 -1
- package/apollo-client.cjs.min.js +0 -1
- package/utilities/testing/stripSymbols.d.ts +0 -2
- package/utilities/testing/stripSymbols.d.ts.map +0 -1
- package/utilities/testing/stripSymbols.js +0 -4
- package/utilities/testing/stripSymbols.js.map +0 -1
|
@@ -475,24 +475,27 @@ function makeAliasMap(selectionSet, fragmentMap) {
|
|
|
475
475
|
}
|
|
476
476
|
function computeKeyObject(response, specifier, strict, aliasMap) {
|
|
477
477
|
var keyObj = Object.create(null);
|
|
478
|
-
var
|
|
478
|
+
var lastResponseKey;
|
|
479
|
+
var lastActualKey;
|
|
479
480
|
specifier.forEach(function (s) {
|
|
480
481
|
if (Array.isArray(s)) {
|
|
481
|
-
if (typeof
|
|
482
|
+
if (typeof lastActualKey === "string" &&
|
|
483
|
+
typeof lastResponseKey === "string") {
|
|
482
484
|
var subsets = aliasMap && aliasMap.subsets;
|
|
483
|
-
var subset = subsets && subsets[
|
|
484
|
-
keyObj[
|
|
485
|
+
var subset = subsets && subsets[lastActualKey];
|
|
486
|
+
keyObj[lastActualKey] =
|
|
487
|
+
computeKeyObject(response[lastResponseKey], s, strict, subset);
|
|
485
488
|
}
|
|
486
489
|
}
|
|
487
490
|
else {
|
|
488
491
|
var aliases = aliasMap && aliasMap.aliases;
|
|
489
492
|
var responseName = aliases && aliases[s] || s;
|
|
490
493
|
if (hasOwn.call(response, responseName)) {
|
|
491
|
-
keyObj[
|
|
494
|
+
keyObj[lastActualKey = s] = response[lastResponseKey = responseName];
|
|
492
495
|
}
|
|
493
496
|
else {
|
|
494
497
|
__DEV__ ? invariant(!strict, "Missing field '" + responseName + "' while computing key fields") : invariant(!strict, 5);
|
|
495
|
-
|
|
498
|
+
lastResponseKey = lastActualKey = void 0;
|
|
496
499
|
}
|
|
497
500
|
}
|
|
498
501
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policies.js","sourceRoot":"","sources":["../../../src/cache/inmemory/policies.ts"],"names":[],"mappings":";AAOA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,EAEL,wBAAwB,EACxB,OAAO,EACP,qBAAqB,EACrB,qBAAqB,EAGrB,wBAAwB,EAExB,WAAW,EACX,eAAe,EACf,aAAa,EACb,eAAe,EACf,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EACL,MAAM,EACN,sBAAsB,EACtB,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAe3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,eAAe,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;AAyFjD,SAAS,sBAAsB,CAAC,IAAoB;IAClD,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,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GAAG,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAChD,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,EAAE;gBACvC,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;aAC9C;iBAAM;gBACL,SAAS,CAAC,CAAC,MAAM,EAAE,oBAAkB,YAAY,iCAA8B,CAAC,CAAC;gBACjF,OAAO,GAAG,KAAK,CAAC,CAAC;aAClB;SACF;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {\n InlineFragmentNode,\n FragmentDefinitionNode,\n SelectionSetNode,\n FieldNode,\n} from 'graphql';\n\nimport { Trie } from '@wry/trie';\nimport { invariant, InvariantError } from 'ts-invariant';\n\nimport {\n FragmentMap,\n getFragmentFromSelection,\n isField,\n getTypenameFromResult,\n storeKeyNameFromField,\n StoreValue,\n StoreObject,\n argumentsObjectFromField,\n Reference,\n isReference,\n getStoreKeyName,\n canUseWeakMap,\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} 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';\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)[]\ntype KeySpecifier = (string | any[])[];\n\ntype KeyFieldsContext = {\n typename?: string;\n selectionSet?: SelectionSetNode;\n fragmentMap?: FragmentMap;\n // May be set by the KeyFieldsFunction to report fields that were involved\n // 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\ntype KeyArgsResult = Exclude<ReturnType<KeyArgsFunction>, KeySpecifier>;\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> = {\n keyArgs?: KeySpecifier | KeyArgsFunction | false;\n read?: FieldReadFunction<TExisting, TReadResult>;\n merge?: FieldMergeFunction<TExisting, TIncoming> | 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<TExisting = any, TReadResult = TExisting> = (\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: FieldFunctionOptions,\n) => TReadResult | undefined;\n\nexport type FieldMergeFunction<TExisting = any, TIncoming = TExisting> = (\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: FieldFunctionOptions,\n) => SafeReadonly<TExisting>;\n\nexport const defaultDataIdFromObject = (\n { __typename, id, _id }: Readonly<StoreObject>,\n context?: KeyFieldsContext,\n) => {\n if (typeof __typename === \"string\") {\n if (context) {\n context.keyObject =\n id !== void 0 ? { id } :\n _id !== void 0 ? { _id } :\n void 0;\n }\n // If there is no object.id, fall back to object._id.\n if (id === void 0) id = _id;\n if (id !== void 0) {\n return `${__typename}:${(\n typeof id === \"number\" ||\n typeof id === \"string\"\n ) ? id : JSON.stringify(id)}`;\n }\n }\n};\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 selectionSet?: SelectionSetNode,\n fragmentMap?: FragmentMap,\n ): [string?, StoreObject?] {\n // TODO Use an AliasMap here?\n const typename = selectionSet && fragmentMap\n ? getTypenameFromResult(object, selectionSet, fragmentMap)\n : object.__typename;\n\n // It should be possible to write root Query fields with\n // writeFragment, using { __typename: \"Query\", ... } as the data, but\n // it does not make sense to allow the same identification behavior\n // for the Mutation and Subscription types, since application code\n // should never be writing directly to (or reading directly from)\n // those root objects.\n if (typename === this.rootTypenamesById.ROOT_QUERY) {\n return [\"ROOT_QUERY\"];\n }\n\n const context: KeyFieldsContext = {\n typename,\n selectionSet,\n fragmentMap,\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 (Array.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 Array.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 Array.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: KeyArgsResult;\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 (Array.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 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\n readField<T>(\n fieldNameOrOptions: string | ReadFieldOptions,\n from?: StoreObject | Reference,\n ) {\n let options: ReadFieldOptions;\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: arguments.length > 1 ? from : objectOrReference,\n };\n } else if (isNonNullObject(fieldNameOrOptions)) {\n options = { ...fieldNameOrOptions };\n // Default to objectOrReference only when fieldNameOrOptions.from is\n // actually omitted, rather than just undefined.\n if (!hasOwn.call(fieldNameOrOptions, \"from\")) {\n options.from = objectOrReference;\n }\n } else {\n invariant.warn(`Unexpected readField arguments: ${\n stringifyForDisplay(Array.from(arguments))\n }`);\n // The readField helper function returns undefined for any missing\n // fields, so it should also return undefined if the arguments were not\n // of a type we expected.\n return;\n }\n\n if (__DEV__ && options.from === void 0) {\n invariant.warn(`Undefined 'from' passed to readField with arguments ${\n stringifyForDisplay(Array.from(arguments))\n }`);\n }\n\n if (void 0 === options.variables) {\n options.variables = variables;\n }\n\n return policies.readField<T>(options, context);\n },\n\n mergeObjects: makeMergeObjectsFunction(context.store),\n };\n}\n\nfunction makeMergeObjectsFunction(\n store: NormalizedCache,\n): MergeObjectsFunction {\n return function mergeObjects(existing, incoming) {\n if (Array.isArray(existing) || Array.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\nfunction keyArgsFnFromSpecifier(\n specifier: KeySpecifier,\n): KeyArgsFunction {\n return (args, context) => {\n return args ? `${context.fieldName}:${\n JSON.stringify(computeKeyObject(args, specifier, false))\n }` : context.fieldName;\n };\n}\n\nfunction keyFieldsFnFromSpecifier(\n specifier: KeySpecifier,\n): KeyFieldsFunction {\n const trie = new Trie<{\n aliasMap?: AliasMap;\n }>(canUseWeakMap);\n\n return (object, context) => {\n let aliasMap: AliasMap | undefined;\n if (context.selectionSet && context.fragmentMap) {\n const info = trie.lookupArray([\n context.selectionSet,\n context.fragmentMap,\n ]);\n aliasMap = info.aliasMap || (\n info.aliasMap = makeAliasMap(context.selectionSet, context.fragmentMap)\n );\n }\n\n const keyObject = context.keyObject =\n computeKeyObject(object, specifier, true, aliasMap);\n\n return `${context.typename}:${JSON.stringify(keyObject)}`;\n };\n}\n\ntype AliasMap = {\n // Map from store key to corresponding response key. Undefined when there are\n // no aliased fields in this selection set.\n aliases?: Record<string, string>;\n // Map from store key to AliasMap correponding to a child selection set.\n // Undefined when there are no child selection sets.\n subsets?: Record<string, AliasMap>;\n};\n\nfunction makeAliasMap(\n selectionSet: SelectionSetNode,\n fragmentMap: FragmentMap,\n): AliasMap {\n let map: AliasMap = Object.create(null);\n // TODO Cache this work, perhaps by storing selectionSet._aliasMap?\n const workQueue = new Set([selectionSet]);\n workQueue.forEach(selectionSet => {\n selectionSet.selections.forEach(selection => {\n if (isField(selection)) {\n if (selection.alias) {\n const responseKey = selection.alias.value;\n const storeKey = selection.name.value;\n if (storeKey !== responseKey) {\n const aliases = map.aliases || (map.aliases = Object.create(null));\n aliases[storeKey] = responseKey;\n }\n }\n if (selection.selectionSet) {\n const subsets = map.subsets || (map.subsets = Object.create(null));\n subsets[selection.name.value] =\n makeAliasMap(selection.selectionSet, fragmentMap);\n }\n } else {\n const fragment = getFragmentFromSelection(selection, fragmentMap);\n if (fragment) {\n workQueue.add(fragment.selectionSet);\n }\n }\n });\n });\n return map;\n}\n\nfunction computeKeyObject(\n response: Record<string, any>,\n specifier: KeySpecifier,\n strict: boolean,\n aliasMap?: AliasMap,\n): Record<string, any> {\n // The order of adding properties to keyObj affects its JSON serialization,\n // so we are careful to build keyObj in the order of keys given in\n // specifier.\n const keyObj = Object.create(null);\n let prevKey: string | undefined;\n specifier.forEach(s => {\n if (Array.isArray(s)) {\n if (typeof prevKey === \"string\") {\n const subsets = aliasMap && aliasMap.subsets;\n const subset = subsets && subsets[prevKey];\n keyObj[prevKey] = computeKeyObject(response[prevKey], s, strict, subset);\n }\n } else {\n const aliases = aliasMap && aliasMap.aliases;\n const responseName = aliases && aliases[s] || s;\n if (hasOwn.call(response, responseName)) {\n keyObj[prevKey = s] = response[responseName];\n } else {\n invariant(!strict, `Missing field '${responseName}' while computing key fields`);\n prevKey = void 0;\n }\n }\n });\n return keyObj;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"policies.js","sourceRoot":"","sources":["../../../src/cache/inmemory/policies.ts"],"names":[],"mappings":";AAOA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,EAEL,wBAAwB,EACxB,OAAO,EACP,qBAAqB,EACrB,qBAAqB,EAGrB,wBAAwB,EAExB,WAAW,EACX,eAAe,EACf,aAAa,EACb,eAAe,EACf,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EACL,MAAM,EACN,sBAAsB,EACtB,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAe3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,eAAe,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;AAyFjD,SAAS,sBAAsB,CAAC,IAAoB;IAClD,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7E,CAAC;AAmFD,MAAM,CAAC,IAAM,uBAAuB,GAAG,UACrC,EAA8C,EAC9C,OAA0B;QADxB,UAAU,gBAAA,EAAE,EAAE,QAAA,EAA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Q,EAAE,YAAY,CAAC,EAAE;gBACvC,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,eAAe,GAAG,YAAY,CAAC,CAAC;aACtE;iBAAM;gBACL,SAAS,CAAC,CAAC,MAAM,EAAE,oBAAkB,YAAY,iCAA8B,CAAC,CAAC;gBACjF,eAAe,GAAG,aAAa,GAAG,KAAK,CAAC,CAAC;aAC1C;SACF;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {\n InlineFragmentNode,\n FragmentDefinitionNode,\n SelectionSetNode,\n FieldNode,\n} from 'graphql';\n\nimport { Trie } from '@wry/trie';\nimport { invariant, InvariantError } from 'ts-invariant';\n\nimport {\n FragmentMap,\n getFragmentFromSelection,\n isField,\n getTypenameFromResult,\n storeKeyNameFromField,\n StoreValue,\n StoreObject,\n argumentsObjectFromField,\n Reference,\n isReference,\n getStoreKeyName,\n canUseWeakMap,\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} 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';\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)[]\ntype KeySpecifier = (string | any[])[];\n\ntype KeyFieldsContext = {\n typename?: string;\n selectionSet?: SelectionSetNode;\n fragmentMap?: FragmentMap;\n // May be set by the KeyFieldsFunction to report fields that were involved\n // 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\ntype KeyArgsResult = Exclude<ReturnType<KeyArgsFunction>, KeySpecifier>;\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> = {\n keyArgs?: KeySpecifier | KeyArgsFunction | false;\n read?: FieldReadFunction<TExisting, TReadResult>;\n merge?: FieldMergeFunction<TExisting, TIncoming> | 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<TExisting = any, TReadResult = TExisting> = (\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: FieldFunctionOptions,\n) => TReadResult | undefined;\n\nexport type FieldMergeFunction<TExisting = any, TIncoming = TExisting> = (\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: FieldFunctionOptions,\n) => SafeReadonly<TExisting>;\n\nexport const defaultDataIdFromObject = (\n { __typename, id, _id }: Readonly<StoreObject>,\n context?: KeyFieldsContext,\n) => {\n if (typeof __typename === \"string\") {\n if (context) {\n context.keyObject =\n id !== void 0 ? { id } :\n _id !== void 0 ? { _id } :\n void 0;\n }\n // If there is no object.id, fall back to object._id.\n if (id === void 0) id = _id;\n if (id !== void 0) {\n return `${__typename}:${(\n typeof id === \"number\" ||\n typeof id === \"string\"\n ) ? id : JSON.stringify(id)}`;\n }\n }\n};\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 selectionSet?: SelectionSetNode,\n fragmentMap?: FragmentMap,\n ): [string?, StoreObject?] {\n // TODO Use an AliasMap here?\n const typename = selectionSet && fragmentMap\n ? getTypenameFromResult(object, selectionSet, fragmentMap)\n : object.__typename;\n\n // It should be possible to write root Query fields with\n // writeFragment, using { __typename: \"Query\", ... } as the data, but\n // it does not make sense to allow the same identification behavior\n // for the Mutation and Subscription types, since application code\n // should never be writing directly to (or reading directly from)\n // those root objects.\n if (typename === this.rootTypenamesById.ROOT_QUERY) {\n return [\"ROOT_QUERY\"];\n }\n\n const context: KeyFieldsContext = {\n typename,\n selectionSet,\n fragmentMap,\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 (Array.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 Array.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 Array.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: KeyArgsResult;\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 (Array.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 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\n readField<T>(\n fieldNameOrOptions: string | ReadFieldOptions,\n from?: StoreObject | Reference,\n ) {\n let options: ReadFieldOptions;\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: arguments.length > 1 ? from : objectOrReference,\n };\n } else if (isNonNullObject(fieldNameOrOptions)) {\n options = { ...fieldNameOrOptions };\n // Default to objectOrReference only when fieldNameOrOptions.from is\n // actually omitted, rather than just undefined.\n if (!hasOwn.call(fieldNameOrOptions, \"from\")) {\n options.from = objectOrReference;\n }\n } else {\n invariant.warn(`Unexpected readField arguments: ${\n stringifyForDisplay(Array.from(arguments))\n }`);\n // The readField helper function returns undefined for any missing\n // fields, so it should also return undefined if the arguments were not\n // of a type we expected.\n return;\n }\n\n if (__DEV__ && options.from === void 0) {\n invariant.warn(`Undefined 'from' passed to readField with arguments ${\n stringifyForDisplay(Array.from(arguments))\n }`);\n }\n\n if (void 0 === options.variables) {\n options.variables = variables;\n }\n\n return policies.readField<T>(options, context);\n },\n\n mergeObjects: makeMergeObjectsFunction(context.store),\n };\n}\n\nfunction makeMergeObjectsFunction(\n store: NormalizedCache,\n): MergeObjectsFunction {\n return function mergeObjects(existing, incoming) {\n if (Array.isArray(existing) || Array.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\nfunction keyArgsFnFromSpecifier(\n specifier: KeySpecifier,\n): KeyArgsFunction {\n return (args, context) => {\n return args ? `${context.fieldName}:${\n JSON.stringify(computeKeyObject(args, specifier, false))\n }` : context.fieldName;\n };\n}\n\nfunction keyFieldsFnFromSpecifier(\n specifier: KeySpecifier,\n): KeyFieldsFunction {\n const trie = new Trie<{\n aliasMap?: AliasMap;\n }>(canUseWeakMap);\n\n return (object, context) => {\n let aliasMap: AliasMap | undefined;\n if (context.selectionSet && context.fragmentMap) {\n const info = trie.lookupArray([\n context.selectionSet,\n context.fragmentMap,\n ]);\n aliasMap = info.aliasMap || (\n info.aliasMap = makeAliasMap(context.selectionSet, context.fragmentMap)\n );\n }\n\n const keyObject = context.keyObject =\n computeKeyObject(object, specifier, true, aliasMap);\n\n return `${context.typename}:${JSON.stringify(keyObject)}`;\n };\n}\n\ntype AliasMap = {\n // Map from store key to corresponding response key. Undefined when there are\n // no aliased fields in this selection set.\n aliases?: Record<string, string>;\n // Map from store key to AliasMap correponding to a child selection set.\n // Undefined when there are no child selection sets.\n subsets?: Record<string, AliasMap>;\n};\n\nfunction makeAliasMap(\n selectionSet: SelectionSetNode,\n fragmentMap: FragmentMap,\n): AliasMap {\n let map: AliasMap = Object.create(null);\n // TODO Cache this work, perhaps by storing selectionSet._aliasMap?\n const workQueue = new Set([selectionSet]);\n workQueue.forEach(selectionSet => {\n selectionSet.selections.forEach(selection => {\n if (isField(selection)) {\n if (selection.alias) {\n const responseKey = selection.alias.value;\n const storeKey = selection.name.value;\n if (storeKey !== responseKey) {\n const aliases = map.aliases || (map.aliases = Object.create(null));\n aliases[storeKey] = responseKey;\n }\n }\n if (selection.selectionSet) {\n const subsets = map.subsets || (map.subsets = Object.create(null));\n subsets[selection.name.value] =\n makeAliasMap(selection.selectionSet, fragmentMap);\n }\n } else {\n const fragment = getFragmentFromSelection(selection, fragmentMap);\n if (fragment) {\n workQueue.add(fragment.selectionSet);\n }\n }\n });\n });\n return map;\n}\n\nfunction computeKeyObject(\n response: Record<string, any>,\n specifier: KeySpecifier,\n strict: boolean,\n aliasMap?: AliasMap,\n): Record<string, any> {\n // The order of adding properties to keyObj affects its JSON serialization,\n // so we are careful to build keyObj in the order of keys given in\n // specifier.\n const keyObj = Object.create(null);\n\n // The lastResponseKey variable tracks keys as seen in actual GraphQL response\n // objects, potentially affected by aliasing. The lastActualKey variable\n // tracks the corresponding key after removing aliases.\n let lastResponseKey: string | undefined;\n let lastActualKey: string | undefined;\n\n specifier.forEach(s => {\n if (Array.isArray(s)) {\n if (typeof lastActualKey === \"string\" &&\n typeof lastResponseKey === \"string\") {\n const subsets = aliasMap && aliasMap.subsets;\n const subset = subsets && subsets[lastActualKey];\n keyObj[lastActualKey] =\n computeKeyObject(response[lastResponseKey], s, strict, subset);\n }\n } else {\n const aliases = aliasMap && aliasMap.aliases;\n const responseName = aliases && aliases[s] || s;\n if (hasOwn.call(response, responseName)) {\n keyObj[lastActualKey = s] = response[lastResponseKey = responseName];\n } else {\n invariant(!strict, `Missing field '${responseName}' while computing key fields`);\n lastResponseKey = lastActualKey = void 0;\n }\n }\n });\n return keyObj;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeToStore.d.ts","sourceRoot":"","sources":["../../../src/cache/inmemory/writeToStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAa,aAAa,EAAE,MAAM,SAAS,CAAC;AAIrE,OAAO,EAEL,WAAW,EAUX,WAAW,EACX,SAAS,EAKV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE7E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,MAAM,WAAW,YAAa,SAAQ,sBAAsB;IAC1D,QAAQ,CAAC,OAAO,EAAE;QAChB,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAC;KACtC,CAAC;IACF,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IAEnC,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IAEtC,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE;QACxB,MAAM,EAAE,WAAW,CAAC;QACpB,SAAS,EAAE,SAAS,CAAC;
|
|
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,GAAG,SAAS,GAAG,SAAS;IAkG7C,OAAO,CAAC,mBAAmB;IAiO3B,OAAO,CAAC,iBAAiB;IA8BzB,OAAO,CAAC,WAAW;CA6FpB"}
|
|
@@ -42,7 +42,7 @@ var StoreWriter = (function () {
|
|
|
42
42
|
context.incomingById.forEach(function (_a, dataId) {
|
|
43
43
|
var fields = _a.fields, mergeTree = _a.mergeTree, selections = _a.selections;
|
|
44
44
|
var entityRef = makeReference(dataId);
|
|
45
|
-
if (mergeTree.map.size) {
|
|
45
|
+
if (mergeTree && mergeTree.map.size) {
|
|
46
46
|
var applied = _this.applyMerges(mergeTree, entityRef, fields, context);
|
|
47
47
|
if (isReference(applied)) {
|
|
48
48
|
return;
|
|
@@ -60,7 +60,7 @@ var StoreWriter = (function () {
|
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
var hasMergeFunction_1 = function (storeFieldName) {
|
|
63
|
-
var childTree = mergeTree.map.get(storeFieldName);
|
|
63
|
+
var childTree = mergeTree && mergeTree.map.get(storeFieldName);
|
|
64
64
|
return Boolean(childTree && childTree.info && childTree.info.merge);
|
|
65
65
|
};
|
|
66
66
|
Object.keys(fields).forEach(function (storeFieldName) {
|
|
@@ -169,7 +169,7 @@ var StoreWriter = (function () {
|
|
|
169
169
|
else {
|
|
170
170
|
context.incomingById.set(dataId, {
|
|
171
171
|
fields: incomingFields,
|
|
172
|
-
mergeTree: mergeTree,
|
|
172
|
+
mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,
|
|
173
173
|
selections: selections,
|
|
174
174
|
});
|
|
175
175
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeToStore.js","sourceRoot":"","sources":["../../../src/cache/inmemory/writeToStore.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EACL,iBAAiB,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KAAK,EAAE,YAAY,CAAC,CAAC;YAC1D,IAAI,OAAO,QAAQ,KAAK,QAAQ;gBAC5B,CAAC,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;gBACtC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aAC/B;QACH,CAAC,CAAC,CAAC;KACJ;IAED,SAAS,CAAC,IAAI,CAChB,+CAA6C,SAAS,oBAAe,UAAU,oFAG7E,cAAc,CAAC,MAAM;QACnB,CAAC,CAAC,oCAAoC;YAClC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,6CAA6C;QAChF,CAAC,CAAC,EAAE,gDAEN,WAAW,gFAGC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,sBACvC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,mRAMpD,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { SelectionSetNode, FieldNode, SelectionNode } from 'graphql';\nimport { invariant, InvariantError } from 'ts-invariant';\nimport { equal } from '@wry/equality';\n\nimport {\n createFragmentMap,\n FragmentMap,\n getFragmentFromSelection,\n getDefaultValues,\n getFragmentDefinitions,\n getOperationDefinition,\n getTypenameFromResult,\n makeReference,\n isField,\n resultKeyNameFromField,\n StoreValue,\n StoreObject,\n Reference,\n isReference,\n shouldInclude,\n cloneDeep,\n addTypenameToDocument,\n} from '../../utilities';\n\nimport { NormalizedCache, ReadMergeModifyContext, MergeTree } from './types';\nimport { makeProcessedFieldsMerger, fieldNameFromStoreName, storeValueIsStoreObject } from './helpers';\nimport { StoreReader } from './readFromStore';\nimport { InMemoryCache } from './inMemoryCache';\nimport { EntityStore } from './entityStore';\nimport { Cache } from '../../core';\nimport { canonicalStringify } from './object-canon';\n\nexport interface WriteContext extends ReadMergeModifyContext {\n readonly written: {\n [dataId: string]: SelectionSetNode[];\n };\n readonly fragmentMap?: FragmentMap;\n // General-purpose deep-merge function for use during writes.\n merge<T>(existing: T, incoming: T): T;\n // If true, merge functions will be called with undefined existing data.\n overwrite: boolean;\n incomingById: Map<string, {\n fields: StoreObject;\n mergeTree: MergeTree;\n selections: Set<SelectionNode>;\n }>;\n clientOnly: boolean;\n};\n\ninterface ProcessSelectionSetOptions {\n dataId?: string,\n result: Record<string, any>;\n selectionSet: SelectionSetNode;\n context: WriteContext;\n mergeTree: MergeTree;\n}\n\nexport class StoreWriter {\n constructor(\n public readonly cache: InMemoryCache,\n private reader?: StoreReader,\n ) {}\n\n public writeToStore(store: NormalizedCache, {\n query,\n result,\n dataId,\n variables,\n overwrite,\n }: Cache.WriteOptions): Reference | undefined {\n const operationDefinition = getOperationDefinition(query)!;\n const merger = makeProcessedFieldsMerger();\n\n variables = {\n ...getDefaultValues(operationDefinition),\n ...variables!,\n };\n\n const context: WriteContext = {\n store,\n written: Object.create(null),\n merge<T>(existing: T, incoming: T) {\n return merger.merge(existing, incoming) as T;\n },\n variables,\n varString: canonicalStringify(variables),\n fragmentMap: createFragmentMap(getFragmentDefinitions(query)),\n overwrite: !!overwrite,\n incomingById: new Map,\n clientOnly: false,\n };\n\n const ref = this.processSelectionSet({\n result: result || Object.create(null),\n dataId,\n selectionSet: operationDefinition.selectionSet,\n mergeTree: { map: new Map },\n context,\n });\n\n if (!isReference(ref)) {\n throw new InvariantError(`Could not identify object ${JSON.stringify(result)}`);\n }\n\n // So far, the store has not been modified, so now it's time to process\n // context.incomingById and merge those incoming fields into context.store.\n context.incomingById.forEach(({ fields, mergeTree, selections }, dataId) => {\n const entityRef = makeReference(dataId);\n\n if (mergeTree.map.size) {\n const applied = this.applyMerges(mergeTree, entityRef, fields, context);\n if (isReference(applied)) {\n // Assume References returned by applyMerges have already been merged\n // into the store. See makeMergeObjectsFunction in policies.ts for an\n // example of how this can happen.\n return;\n }\n // Otherwise, applyMerges returned a StoreObject, whose fields we should\n // merge into the store (see store.merge statement below).\n fields = applied;\n }\n\n if (__DEV__ && !context.overwrite) {\n const hasSelectionSet = (storeFieldName: string) =>\n fieldsWithSelectionSets.has(fieldNameFromStoreName(storeFieldName));\n const fieldsWithSelectionSets = new Set<string>();\n selections.forEach(selection => {\n if (isField(selection) && selection.selectionSet) {\n fieldsWithSelectionSets.add(selection.name.value);\n }\n });\n\n const hasMergeFunction = (storeFieldName: string) => {\n const childTree = mergeTree.map.get(storeFieldName);\n return Boolean(childTree && childTree.info && childTree.info.merge);\n };\n\n Object.keys(fields).forEach(storeFieldName => {\n // If a merge function was defined for this field, trust that it\n // did the right thing about (not) clobbering data. If the field\n // has no selection set, it's a scalar field, so it doesn't need\n // a merge function (even if it's an object, like JSON data).\n if (hasSelectionSet(storeFieldName) &&\n !hasMergeFunction(storeFieldName)) {\n warnAboutDataLoss(\n entityRef,\n fields,\n storeFieldName,\n context.store,\n );\n }\n });\n }\n\n store.merge(dataId, fields);\n });\n\n // Any IDs written explicitly to the cache will be retained as\n // reachable root IDs for garbage collection purposes. Although this\n // logic includes root IDs like ROOT_QUERY and ROOT_MUTATION, their\n // retainment counts are effectively ignored because cache.gc() always\n // includes them in its root ID set.\n store.retain(ref.__ref);\n\n return ref;\n }\n\n private processSelectionSet({\n dataId,\n result,\n selectionSet,\n context,\n // This object allows processSelectionSet to report useful information\n // to its callers without explicitly returning that information.\n mergeTree,\n }: ProcessSelectionSetOptions): StoreObject | Reference {\n const { policies } = this.cache;\n\n // Identify the result object, even if dataId was already provided,\n // since we always need keyObject below.\n const [id, keyObject] = policies.identify(\n result, selectionSet, context.fragmentMap);\n\n // If dataId was not provided, fall back to the id just generated by\n // policies.identify.\n dataId = dataId || id;\n\n if (\"string\" === typeof dataId) {\n // Avoid processing the same entity object using the same selection\n // set more than once. We use an array instead of a Set since most\n // entity IDs will be written using only one selection set, so the\n // size of this array is likely to be very small, meaning indexOf is\n // likely to be faster than Set.prototype.has.\n const sets = context.written[dataId] || (context.written[dataId] = []);\n const ref = makeReference(dataId);\n if (sets.indexOf(selectionSet) >= 0) return ref;\n sets.push(selectionSet);\n\n // If we're about to write a result object into the store, but we\n // happen to know that the exact same (===) result object would be\n // returned if we were to reread the result with the same inputs,\n // then we can skip the rest of the processSelectionSet work for\n // this object, and immediately return a Reference to it.\n if (this.reader && this.reader.isFresh(\n result,\n ref,\n selectionSet,\n context,\n )) {\n return ref;\n }\n }\n\n // This variable will be repeatedly updated using context.merge to\n // accumulate all fields that need to be written into the store.\n let incomingFields: StoreObject = Object.create(null);\n\n // Write any key fields that were used during identification, even if\n // they were not mentioned in the original query.\n if (keyObject) {\n incomingFields = context.merge(incomingFields, keyObject);\n }\n\n // If typename was not passed in, infer it. Note that typename is\n // always passed in for tricky-to-infer cases such as \"Query\" for\n // ROOT_QUERY.\n const typename: string | undefined =\n (dataId && policies.rootTypenamesById[dataId]) ||\n getTypenameFromResult(result, selectionSet, context.fragmentMap) ||\n (dataId && context.store.get(dataId, \"__typename\") as string);\n\n if (\"string\" === typeof typename) {\n incomingFields.__typename = typename;\n }\n\n const selections = new Set(selectionSet.selections);\n\n selections.forEach(selection => {\n if (!shouldInclude(selection, context.variables)) return;\n\n if (isField(selection)) {\n const resultFieldKey = resultKeyNameFromField(selection);\n const value = result[resultFieldKey];\n\n const wasClientOnly = context.clientOnly;\n context.clientOnly = wasClientOnly || !!(\n selection.directives &&\n selection.directives.some(d => d.name.value === \"client\")\n );\n\n if (value !== void 0) {\n const storeFieldName = policies.getStoreFieldName({\n typename,\n fieldName: selection.name.value,\n field: selection,\n variables: context.variables,\n });\n\n const childTree = getChildMergeTree(mergeTree, storeFieldName);\n\n let incomingValue =\n this.processFieldValue(value, selection, context, childTree);\n\n // To determine if this field holds a child object with a merge\n // function defined in its type policy (see PR #7070), we need to\n // figure out the child object's __typename.\n let childTypename: string | undefined;\n\n // The field's value can be an object that has a __typename only if\n // the field has a selection set. Otherwise incomingValue is scalar.\n if (selection.selectionSet) {\n // We attempt to find the child __typename first in context.store,\n // but the child object may not exist in the store yet, likely\n // because it's being written for the first time, during this very\n // call to writeToStore. Note: if incomingValue is a non-normalized\n // StoreObject (not a Reference), getFieldValue will read from that\n // object's properties to find its __typename.\n childTypename = context.store.getFieldValue<string>(\n incomingValue as StoreObject | Reference,\n \"__typename\",\n );\n\n // If the child object is being written for the first time, but\n // incomingValue is a Reference, then the entity that Reference\n // identifies should have an entry in context.incomingById, which\n // likely contains a __typename field we can use. After all, how\n // could we know the object's ID if it had no __typename? If we\n // wrote data into context.store as each processSelectionSet call\n // finished processing an entity object, the child object would\n // already be in context.store, so we wouldn't need this extra\n // check, but holding all context.store.merge calls until after\n // we've finished all processSelectionSet work is cleaner and solves\n // other problems, such as issue #8370.\n if (!childTypename && isReference(incomingValue)) {\n const info = context.incomingById.get(incomingValue.__ref);\n childTypename = info && info.fields.__typename;\n }\n }\n\n const merge = policies.getMergeFunction(\n typename,\n selection.name.value,\n childTypename,\n );\n\n if (merge) {\n childTree.info = {\n // TODO Check compatibility against any existing\n // childTree.field?\n field: selection,\n typename,\n merge,\n };\n } else {\n maybeRecycleChildMergeTree(mergeTree, storeFieldName);\n }\n\n incomingFields = context.merge(incomingFields, {\n [storeFieldName]: incomingValue,\n });\n\n } else if (\n !context.clientOnly &&\n !addTypenameToDocument.added(selection)\n ) {\n invariant.error(`Missing field '${\n resultKeyNameFromField(selection)\n }' while writing result ${\n JSON.stringify(result, null, 2)\n }`.substring(0, 1000));\n }\n\n context.clientOnly = wasClientOnly;\n\n } else {\n // This is not a field, so it must be a fragment, either inline or named\n const fragment = getFragmentFromSelection(\n selection,\n context.fragmentMap,\n );\n\n if (fragment &&\n // By passing result and context.variables, we enable\n // policies.fragmentMatches to bend the rules when typename is\n // not a known subtype of the fragment type condition, but the\n // result object contains all the keys requested by the\n // fragment, which strongly suggests the fragment probably\n // matched. This fuzzy matching behavior must be enabled by\n // including a regular expression string (such as \".*\" or\n // \"Prefix.*\" or \".*Suffix\") in the possibleTypes array for\n // specific supertypes; otherwise, all matching remains exact.\n // Fuzzy matches are remembered by the Policies object and\n // later used when reading from the cache. Since there is no\n // incoming result object to check when reading, reading does\n // not involve the same fuzzy inference, so the StoreReader\n // class calls policies.fragmentMatches without passing result\n // or context.variables. The flexibility of fuzzy matching\n // allows existing clients to accommodate previously unknown\n // __typename strings produced by server/schema changes, which\n // would otherwise be breaking changes.\n policies.fragmentMatches(fragment, typename, result, context.variables)) {\n fragment.selectionSet.selections.forEach(selections.add, selections);\n }\n }\n });\n\n if (\"string\" === typeof dataId) {\n const previous = context.incomingById.get(dataId);\n if (previous) {\n previous.fields = context.merge(previous.fields, incomingFields);\n previous.mergeTree = mergeMergeTrees(previous.mergeTree, mergeTree);\n // Add all previous SelectionNode objects, rather than creating a new\n // Set, since the original unmerged selections Set is not going to be\n // needed again (only the merged Set).\n previous.selections.forEach(selections.add, selections);\n previous.selections = selections;\n } else {\n context.incomingById.set(dataId, {\n fields: incomingFields,\n mergeTree,\n selections,\n });\n }\n return makeReference(dataId);\n }\n\n return incomingFields;\n }\n\n private processFieldValue(\n value: any,\n field: FieldNode,\n context: WriteContext,\n mergeTree: MergeTree,\n ): StoreValue {\n if (!field.selectionSet || value === null) {\n // In development, we need to clone scalar values so that they can be\n // safely frozen with maybeDeepFreeze in readFromStore.ts. In production,\n // it's cheaper to store the scalar values directly in the cache.\n return __DEV__ ? cloneDeep(value) : value;\n }\n\n if (Array.isArray(value)) {\n return value.map((item, i) => {\n const value = this.processFieldValue(\n item, field, context, getChildMergeTree(mergeTree, i));\n maybeRecycleChildMergeTree(mergeTree, i);\n return value;\n });\n }\n\n return this.processSelectionSet({\n result: value,\n selectionSet: field.selectionSet,\n context,\n mergeTree,\n });\n }\n\n private applyMerges<T extends StoreValue>(\n mergeTree: MergeTree,\n existing: StoreValue,\n incoming: T,\n context: WriteContext,\n getStorageArgs?: Parameters<EntityStore[\"getStorage\"]>,\n ): T | Reference {\n if (mergeTree.map.size && !isReference(incoming)) {\n const e: StoreObject | Reference | undefined = (\n // Items in the same position in different arrays are not\n // necessarily related to each other, so when incoming is an array\n // we process its elements as if there was no existing data.\n !Array.isArray(incoming) &&\n // Likewise, existing must be either a Reference or a StoreObject\n // in order for its fields to be safe to merge with the fields of\n // the incoming object.\n (isReference(existing) || storeValueIsStoreObject(existing))\n ) ? existing : void 0;\n\n // This narrowing is implied by mergeTree.map.size > 0 and\n // !isReference(incoming), though TypeScript understandably cannot\n // hope to infer this type.\n const i = incoming as StoreObject | StoreValue[];\n\n // The options.storage objects provided to read and merge functions\n // are derived from the identity of the parent object plus a\n // sequence of storeFieldName strings/numbers identifying the nested\n // field name path of each field value to be merged.\n if (e && !getStorageArgs) {\n getStorageArgs = [isReference(e) ? e.__ref : e];\n }\n\n // It's possible that applying merge functions to this subtree will\n // not change the incoming data, so this variable tracks the fields\n // that did change, so we can create a new incoming object when (and\n // only when) at least one incoming field has changed. We use a Map\n // to preserve the type of numeric keys.\n let changedFields: Map<string | number, StoreValue> | undefined;\n\n const getValue = (\n from: typeof e | typeof i,\n name: string | number,\n ): StoreValue => {\n return Array.isArray(from)\n ? (typeof name === \"number\" ? from[name] : void 0)\n : context.store.getFieldValue(from, String(name))\n };\n\n mergeTree.map.forEach((childTree, storeFieldName) => {\n const eVal = getValue(e, storeFieldName);\n const iVal = getValue(i, storeFieldName);\n // If we have no incoming data, leave any existing data untouched.\n if (void 0 === iVal) return;\n if (getStorageArgs) {\n getStorageArgs.push(storeFieldName);\n }\n const aVal = this.applyMerges(\n childTree,\n eVal,\n iVal,\n context,\n getStorageArgs,\n );\n if (aVal !== iVal) {\n changedFields = changedFields || new Map;\n changedFields.set(storeFieldName, aVal);\n }\n if (getStorageArgs) {\n invariant(getStorageArgs.pop() === storeFieldName);\n }\n });\n\n if (changedFields) {\n // Shallow clone i so we can add changed fields to it.\n incoming = (Array.isArray(i) ? i.slice(0) : { ...i }) as T;\n changedFields.forEach((value, name) => {\n (incoming as any)[name] = value;\n });\n }\n }\n\n if (mergeTree.info) {\n return this.cache.policies.runMergeFunction(\n existing,\n incoming,\n mergeTree.info,\n context,\n getStorageArgs && context.store.getStorage(...getStorageArgs),\n );\n }\n\n return incoming;\n }\n}\n\nconst emptyMergeTreePool: MergeTree[] = [];\n\nfunction getChildMergeTree(\n { map }: MergeTree,\n name: string | number,\n): MergeTree {\n if (!map.has(name)) {\n map.set(name, emptyMergeTreePool.pop() || { map: new Map });\n }\n return map.get(name)!;\n}\n\nfunction mergeMergeTrees(\n left: MergeTree | undefined,\n right: MergeTree | undefined,\n): MergeTree {\n if (left === right || !right || mergeTreeIsEmpty(right)) return left!;\n if (!left || mergeTreeIsEmpty(left)) return right;\n\n const info = left.info && right.info ? {\n ...left.info,\n ...right.info,\n } : left.info || right.info;\n\n const needToMergeMaps = left.map.size && right.map.size;\n const map = needToMergeMaps ? new Map :\n left.map.size ? left.map : right.map;\n\n const merged = { info, map };\n\n if (needToMergeMaps) {\n const remainingRightKeys = new Set(right.map.keys());\n\n left.map.forEach((leftTree, key) => {\n merged.map.set(\n key,\n mergeMergeTrees(leftTree, right.map.get(key)),\n );\n remainingRightKeys.delete(key);\n });\n\n remainingRightKeys.forEach(key => {\n merged.map.set(\n key,\n mergeMergeTrees(\n right.map.get(key),\n left.map.get(key),\n ),\n );\n });\n }\n\n return merged;\n}\n\nfunction mergeTreeIsEmpty(tree: MergeTree | undefined): boolean {\n return !tree || !(tree.info || tree.map.size);\n}\n\nfunction maybeRecycleChildMergeTree(\n { map }: MergeTree,\n name: string | number,\n) {\n const childTree = map.get(name);\n if (childTree && mergeTreeIsEmpty(childTree)) {\n emptyMergeTreePool.push(childTree);\n map.delete(name);\n }\n}\n\nconst warnings = new Set<string>();\n\n// Note that this function is unused in production, and thus should be\n// pruned by any well-configured minifier.\nfunction warnAboutDataLoss(\n existingRef: Reference,\n incomingObj: StoreObject,\n storeFieldName: string,\n store: NormalizedCache,\n) {\n const getChild = (objOrRef: StoreObject | Reference): StoreObject | false => {\n const child = store.getFieldValue<StoreObject>(objOrRef, storeFieldName);\n return typeof child === \"object\" && child;\n };\n\n const existing = getChild(existingRef);\n if (!existing) return;\n\n const incoming = getChild(incomingObj);\n if (!incoming) return;\n\n // It's always safe to replace a reference, since it refers to data\n // safely stored elsewhere.\n if (isReference(existing)) return;\n\n // If the values are structurally equivalent, we do not need to worry\n // about incoming replacing existing.\n if (equal(existing, incoming)) return;\n\n // If we're replacing every key of the existing object, then the\n // existing data would be overwritten even if the objects were\n // normalized, so warning would not be helpful here.\n if (Object.keys(existing).every(\n key => store.getFieldValue(incoming, key) !== void 0)) {\n return;\n }\n\n const parentType =\n store.getFieldValue<string>(existingRef, \"__typename\") ||\n store.getFieldValue<string>(incomingObj, \"__typename\");\n const fieldName = fieldNameFromStoreName(storeFieldName);\n const typeDotName = `${parentType}.${fieldName}`;\n // Avoid warning more than once for the same type and field name.\n if (warnings.has(typeDotName)) return;\n warnings.add(typeDotName);\n\n const childTypenames: string[] = [];\n // Arrays do not have __typename fields, and always need a custom merge\n // function, even if their elements are normalized entities.\n if (!Array.isArray(existing) &&\n !Array.isArray(incoming)) {\n [existing, incoming].forEach(child => {\n const typename = store.getFieldValue(child, \"__typename\");\n if (typeof typename === \"string\" &&\n !childTypenames.includes(typename)) {\n childTypenames.push(typename);\n }\n });\n }\n\n invariant.warn(\n`Cache data may be lost when replacing the ${fieldName} field of a ${parentType} object.\n\nTo address this problem (which is not a bug in Apollo Client), ${\n childTypenames.length\n ? \"either ensure all objects of type \" +\n childTypenames.join(\" and \") + \" have an ID or a custom merge function, or \"\n : \"\"\n}define a custom merge function for the ${\n typeDotName\n} field, so InMemoryCache can safely merge these objects:\n\n existing: ${JSON.stringify(existing).slice(0, 1000)}\n incoming: ${JSON.stringify(incoming).slice(0, 1000)}\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n`);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"writeToStore.js","sourceRoot":"","sources":["../../../src/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C,CAAC;IAE1B,IAAM,cAAc,GAAa,EAAE,CAAC;IAGpC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;QACxB,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC5B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,UAAA,KAAK;YAChC,IAAM,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YAC1D,IAAI,OAAO,QAAQ,KAAK,QAAQ;gBAC5B,CAAC,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;gBACtC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aAC/B;QACH,CAAC,CAAC,CAAC;KACJ;IAED,SAAS,CAAC,IAAI,CAChB,+CAA6C,SAAS,oBAAe,UAAU,oFAG7E,cAAc,CAAC,MAAM;QACnB,CAAC,CAAC,oCAAoC;YAClC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,6CAA6C;QAChF,CAAC,CAAC,EAAE,gDAEN,WAAW,gFAGC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,sBACvC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,mRAMpD,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { SelectionSetNode, FieldNode, SelectionNode } from 'graphql';\nimport { invariant, InvariantError } from 'ts-invariant';\nimport { equal } from '@wry/equality';\n\nimport {\n createFragmentMap,\n FragmentMap,\n getFragmentFromSelection,\n getDefaultValues,\n getFragmentDefinitions,\n getOperationDefinition,\n getTypenameFromResult,\n makeReference,\n isField,\n resultKeyNameFromField,\n StoreValue,\n StoreObject,\n Reference,\n isReference,\n shouldInclude,\n cloneDeep,\n addTypenameToDocument,\n} from '../../utilities';\n\nimport { NormalizedCache, ReadMergeModifyContext, MergeTree } from './types';\nimport { makeProcessedFieldsMerger, fieldNameFromStoreName, storeValueIsStoreObject } from './helpers';\nimport { StoreReader } from './readFromStore';\nimport { InMemoryCache } from './inMemoryCache';\nimport { EntityStore } from './entityStore';\nimport { Cache } from '../../core';\nimport { canonicalStringify } from './object-canon';\n\nexport interface WriteContext extends ReadMergeModifyContext {\n readonly written: {\n [dataId: string]: SelectionSetNode[];\n };\n readonly fragmentMap?: FragmentMap;\n // General-purpose deep-merge function for use during writes.\n merge<T>(existing: T, incoming: T): T;\n // If true, merge functions will be called with undefined existing data.\n overwrite: boolean;\n incomingById: Map<string, {\n fields: StoreObject;\n mergeTree?: MergeTree;\n selections: Set<SelectionNode>;\n }>;\n clientOnly: boolean;\n};\n\ninterface ProcessSelectionSetOptions {\n dataId?: string,\n result: Record<string, any>;\n selectionSet: SelectionSetNode;\n context: WriteContext;\n mergeTree: MergeTree;\n}\n\nexport class StoreWriter {\n constructor(\n public readonly cache: InMemoryCache,\n private reader?: StoreReader,\n ) {}\n\n public writeToStore(store: NormalizedCache, {\n query,\n result,\n dataId,\n variables,\n overwrite,\n }: Cache.WriteOptions): Reference | undefined {\n const operationDefinition = getOperationDefinition(query)!;\n const merger = makeProcessedFieldsMerger();\n\n variables = {\n ...getDefaultValues(operationDefinition),\n ...variables!,\n };\n\n const context: WriteContext = {\n store,\n written: Object.create(null),\n merge<T>(existing: T, incoming: T) {\n return merger.merge(existing, incoming) as T;\n },\n variables,\n varString: canonicalStringify(variables),\n fragmentMap: createFragmentMap(getFragmentDefinitions(query)),\n overwrite: !!overwrite,\n incomingById: new Map,\n clientOnly: false,\n };\n\n const ref = this.processSelectionSet({\n result: result || Object.create(null),\n dataId,\n selectionSet: operationDefinition.selectionSet,\n mergeTree: { map: new Map },\n context,\n });\n\n if (!isReference(ref)) {\n throw new InvariantError(`Could not identify object ${JSON.stringify(result)}`);\n }\n\n // So far, the store has not been modified, so now it's time to process\n // context.incomingById and merge those incoming fields into context.store.\n context.incomingById.forEach(({ fields, mergeTree, selections }, dataId) => {\n const entityRef = makeReference(dataId);\n\n if (mergeTree && mergeTree.map.size) {\n const applied = this.applyMerges(mergeTree, entityRef, fields, context);\n if (isReference(applied)) {\n // Assume References returned by applyMerges have already been merged\n // into the store. See makeMergeObjectsFunction in policies.ts for an\n // example of how this can happen.\n return;\n }\n // Otherwise, applyMerges returned a StoreObject, whose fields we should\n // merge into the store (see store.merge statement below).\n fields = applied;\n }\n\n if (__DEV__ && !context.overwrite) {\n const hasSelectionSet = (storeFieldName: string) =>\n fieldsWithSelectionSets.has(fieldNameFromStoreName(storeFieldName));\n const fieldsWithSelectionSets = new Set<string>();\n selections.forEach(selection => {\n if (isField(selection) && selection.selectionSet) {\n fieldsWithSelectionSets.add(selection.name.value);\n }\n });\n\n const hasMergeFunction = (storeFieldName: string) => {\n const childTree = mergeTree && mergeTree.map.get(storeFieldName);\n return Boolean(childTree && childTree.info && childTree.info.merge);\n };\n\n Object.keys(fields).forEach(storeFieldName => {\n // If a merge function was defined for this field, trust that it\n // did the right thing about (not) clobbering data. If the field\n // has no selection set, it's a scalar field, so it doesn't need\n // a merge function (even if it's an object, like JSON data).\n if (hasSelectionSet(storeFieldName) &&\n !hasMergeFunction(storeFieldName)) {\n warnAboutDataLoss(\n entityRef,\n fields,\n storeFieldName,\n context.store,\n );\n }\n });\n }\n\n store.merge(dataId, fields);\n });\n\n // Any IDs written explicitly to the cache will be retained as\n // reachable root IDs for garbage collection purposes. Although this\n // logic includes root IDs like ROOT_QUERY and ROOT_MUTATION, their\n // retainment counts are effectively ignored because cache.gc() always\n // includes them in its root ID set.\n store.retain(ref.__ref);\n\n return ref;\n }\n\n private processSelectionSet({\n dataId,\n result,\n selectionSet,\n context,\n // This object allows processSelectionSet to report useful information\n // to its callers without explicitly returning that information.\n mergeTree,\n }: ProcessSelectionSetOptions): StoreObject | Reference {\n const { policies } = this.cache;\n\n // Identify the result object, even if dataId was already provided,\n // since we always need keyObject below.\n const [id, keyObject] = policies.identify(\n result, selectionSet, context.fragmentMap);\n\n // If dataId was not provided, fall back to the id just generated by\n // policies.identify.\n dataId = dataId || id;\n\n if (\"string\" === typeof dataId) {\n // Avoid processing the same entity object using the same selection\n // set more than once. We use an array instead of a Set since most\n // entity IDs will be written using only one selection set, so the\n // size of this array is likely to be very small, meaning indexOf is\n // likely to be faster than Set.prototype.has.\n const sets = context.written[dataId] || (context.written[dataId] = []);\n const ref = makeReference(dataId);\n if (sets.indexOf(selectionSet) >= 0) return ref;\n sets.push(selectionSet);\n\n // If we're about to write a result object into the store, but we\n // happen to know that the exact same (===) result object would be\n // returned if we were to reread the result with the same inputs,\n // then we can skip the rest of the processSelectionSet work for\n // this object, and immediately return a Reference to it.\n if (this.reader && this.reader.isFresh(\n result,\n ref,\n selectionSet,\n context,\n )) {\n return ref;\n }\n }\n\n // This variable will be repeatedly updated using context.merge to\n // accumulate all fields that need to be written into the store.\n let incomingFields: StoreObject = Object.create(null);\n\n // Write any key fields that were used during identification, even if\n // they were not mentioned in the original query.\n if (keyObject) {\n incomingFields = context.merge(incomingFields, keyObject);\n }\n\n // If typename was not passed in, infer it. Note that typename is\n // always passed in for tricky-to-infer cases such as \"Query\" for\n // ROOT_QUERY.\n const typename: string | undefined =\n (dataId && policies.rootTypenamesById[dataId]) ||\n getTypenameFromResult(result, selectionSet, context.fragmentMap) ||\n (dataId && context.store.get(dataId, \"__typename\") as string);\n\n if (\"string\" === typeof typename) {\n incomingFields.__typename = typename;\n }\n\n const selections = new Set(selectionSet.selections);\n\n selections.forEach(selection => {\n if (!shouldInclude(selection, context.variables)) return;\n\n if (isField(selection)) {\n const resultFieldKey = resultKeyNameFromField(selection);\n const value = result[resultFieldKey];\n\n const wasClientOnly = context.clientOnly;\n context.clientOnly = wasClientOnly || !!(\n selection.directives &&\n selection.directives.some(d => d.name.value === \"client\")\n );\n\n if (value !== void 0) {\n const storeFieldName = policies.getStoreFieldName({\n typename,\n fieldName: selection.name.value,\n field: selection,\n variables: context.variables,\n });\n\n const childTree = getChildMergeTree(mergeTree, storeFieldName);\n\n let incomingValue =\n this.processFieldValue(value, selection, context, childTree);\n\n // To determine if this field holds a child object with a merge\n // function defined in its type policy (see PR #7070), we need to\n // figure out the child object's __typename.\n let childTypename: string | undefined;\n\n // The field's value can be an object that has a __typename only if\n // the field has a selection set. Otherwise incomingValue is scalar.\n if (selection.selectionSet) {\n // We attempt to find the child __typename first in context.store,\n // but the child object may not exist in the store yet, likely\n // because it's being written for the first time, during this very\n // call to writeToStore. Note: if incomingValue is a non-normalized\n // StoreObject (not a Reference), getFieldValue will read from that\n // object's properties to find its __typename.\n childTypename = context.store.getFieldValue<string>(\n incomingValue as StoreObject | Reference,\n \"__typename\",\n );\n\n // If the child object is being written for the first time, but\n // incomingValue is a Reference, then the entity that Reference\n // identifies should have an entry in context.incomingById, which\n // likely contains a __typename field we can use. After all, how\n // could we know the object's ID if it had no __typename? If we\n // wrote data into context.store as each processSelectionSet call\n // finished processing an entity object, the child object would\n // already be in context.store, so we wouldn't need this extra\n // check, but holding all context.store.merge calls until after\n // we've finished all processSelectionSet work is cleaner and solves\n // other problems, such as issue #8370.\n if (!childTypename && isReference(incomingValue)) {\n const info = context.incomingById.get(incomingValue.__ref);\n childTypename = info && info.fields.__typename;\n }\n }\n\n const merge = policies.getMergeFunction(\n typename,\n selection.name.value,\n childTypename,\n );\n\n if (merge) {\n childTree.info = {\n // TODO Check compatibility against any existing\n // childTree.field?\n field: selection,\n typename,\n merge,\n };\n } else {\n maybeRecycleChildMergeTree(mergeTree, storeFieldName);\n }\n\n incomingFields = context.merge(incomingFields, {\n [storeFieldName]: incomingValue,\n });\n\n } else if (\n !context.clientOnly &&\n !addTypenameToDocument.added(selection)\n ) {\n invariant.error(`Missing field '${\n resultKeyNameFromField(selection)\n }' while writing result ${\n JSON.stringify(result, null, 2)\n }`.substring(0, 1000));\n }\n\n context.clientOnly = wasClientOnly;\n\n } else {\n // This is not a field, so it must be a fragment, either inline or named\n const fragment = getFragmentFromSelection(\n selection,\n context.fragmentMap,\n );\n\n if (fragment &&\n // By passing result and context.variables, we enable\n // policies.fragmentMatches to bend the rules when typename is\n // not a known subtype of the fragment type condition, but the\n // result object contains all the keys requested by the\n // fragment, which strongly suggests the fragment probably\n // matched. This fuzzy matching behavior must be enabled by\n // including a regular expression string (such as \".*\" or\n // \"Prefix.*\" or \".*Suffix\") in the possibleTypes array for\n // specific supertypes; otherwise, all matching remains exact.\n // Fuzzy matches are remembered by the Policies object and\n // later used when reading from the cache. Since there is no\n // incoming result object to check when reading, reading does\n // not involve the same fuzzy inference, so the StoreReader\n // class calls policies.fragmentMatches without passing result\n // or context.variables. The flexibility of fuzzy matching\n // allows existing clients to accommodate previously unknown\n // __typename strings produced by server/schema changes, which\n // would otherwise be breaking changes.\n policies.fragmentMatches(fragment, typename, result, context.variables)) {\n fragment.selectionSet.selections.forEach(selections.add, selections);\n }\n }\n });\n\n if (\"string\" === typeof dataId) {\n const previous = context.incomingById.get(dataId);\n if (previous) {\n previous.fields = context.merge(previous.fields, incomingFields);\n previous.mergeTree = mergeMergeTrees(previous.mergeTree, mergeTree);\n // Add all previous SelectionNode objects, rather than creating a new\n // Set, since the original unmerged selections Set is not going to be\n // needed again (only the merged Set).\n previous.selections.forEach(selections.add, selections);\n previous.selections = selections;\n } else {\n context.incomingById.set(dataId, {\n fields: incomingFields,\n // Save a reference to mergeTree only if it is not empty, because\n // empty MergeTrees may be recycled by maybeRecycleChildMergeTree and\n // reused for entirely different parts of the result tree.\n mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,\n selections,\n });\n }\n return makeReference(dataId);\n }\n\n return incomingFields;\n }\n\n private processFieldValue(\n value: any,\n field: FieldNode,\n context: WriteContext,\n mergeTree: MergeTree,\n ): StoreValue {\n if (!field.selectionSet || value === null) {\n // In development, we need to clone scalar values so that they can be\n // safely frozen with maybeDeepFreeze in readFromStore.ts. In production,\n // it's cheaper to store the scalar values directly in the cache.\n return __DEV__ ? cloneDeep(value) : value;\n }\n\n if (Array.isArray(value)) {\n return value.map((item, i) => {\n const value = this.processFieldValue(\n item, field, context, getChildMergeTree(mergeTree, i));\n maybeRecycleChildMergeTree(mergeTree, i);\n return value;\n });\n }\n\n return this.processSelectionSet({\n result: value,\n selectionSet: field.selectionSet,\n context,\n mergeTree,\n });\n }\n\n private applyMerges<T extends StoreValue>(\n mergeTree: MergeTree,\n existing: StoreValue,\n incoming: T,\n context: WriteContext,\n getStorageArgs?: Parameters<EntityStore[\"getStorage\"]>,\n ): T | Reference {\n if (mergeTree.map.size && !isReference(incoming)) {\n const e: StoreObject | Reference | undefined = (\n // Items in the same position in different arrays are not\n // necessarily related to each other, so when incoming is an array\n // we process its elements as if there was no existing data.\n !Array.isArray(incoming) &&\n // Likewise, existing must be either a Reference or a StoreObject\n // in order for its fields to be safe to merge with the fields of\n // the incoming object.\n (isReference(existing) || storeValueIsStoreObject(existing))\n ) ? existing : void 0;\n\n // This narrowing is implied by mergeTree.map.size > 0 and\n // !isReference(incoming), though TypeScript understandably cannot\n // hope to infer this type.\n const i = incoming as StoreObject | StoreValue[];\n\n // The options.storage objects provided to read and merge functions\n // are derived from the identity of the parent object plus a\n // sequence of storeFieldName strings/numbers identifying the nested\n // field name path of each field value to be merged.\n if (e && !getStorageArgs) {\n getStorageArgs = [isReference(e) ? e.__ref : e];\n }\n\n // It's possible that applying merge functions to this subtree will\n // not change the incoming data, so this variable tracks the fields\n // that did change, so we can create a new incoming object when (and\n // only when) at least one incoming field has changed. We use a Map\n // to preserve the type of numeric keys.\n let changedFields: Map<string | number, StoreValue> | undefined;\n\n const getValue = (\n from: typeof e | typeof i,\n name: string | number,\n ): StoreValue => {\n return Array.isArray(from)\n ? (typeof name === \"number\" ? from[name] : void 0)\n : context.store.getFieldValue(from, String(name))\n };\n\n mergeTree.map.forEach((childTree, storeFieldName) => {\n const eVal = getValue(e, storeFieldName);\n const iVal = getValue(i, storeFieldName);\n // If we have no incoming data, leave any existing data untouched.\n if (void 0 === iVal) return;\n if (getStorageArgs) {\n getStorageArgs.push(storeFieldName);\n }\n const aVal = this.applyMerges(\n childTree,\n eVal,\n iVal,\n context,\n getStorageArgs,\n );\n if (aVal !== iVal) {\n changedFields = changedFields || new Map;\n changedFields.set(storeFieldName, aVal);\n }\n if (getStorageArgs) {\n invariant(getStorageArgs.pop() === storeFieldName);\n }\n });\n\n if (changedFields) {\n // Shallow clone i so we can add changed fields to it.\n incoming = (Array.isArray(i) ? i.slice(0) : { ...i }) as T;\n changedFields.forEach((value, name) => {\n (incoming as any)[name] = value;\n });\n }\n }\n\n if (mergeTree.info) {\n return this.cache.policies.runMergeFunction(\n existing,\n incoming,\n mergeTree.info,\n context,\n getStorageArgs && context.store.getStorage(...getStorageArgs),\n );\n }\n\n return incoming;\n }\n}\n\nconst emptyMergeTreePool: MergeTree[] = [];\n\nfunction getChildMergeTree(\n { map }: MergeTree,\n name: string | number,\n): MergeTree {\n if (!map.has(name)) {\n map.set(name, emptyMergeTreePool.pop() || { map: new Map });\n }\n return map.get(name)!;\n}\n\nfunction mergeMergeTrees(\n left: MergeTree | undefined,\n right: MergeTree | undefined,\n): MergeTree {\n if (left === right || !right || mergeTreeIsEmpty(right)) return left!;\n if (!left || mergeTreeIsEmpty(left)) return right;\n\n const info = left.info && right.info ? {\n ...left.info,\n ...right.info,\n } : left.info || right.info;\n\n const needToMergeMaps = left.map.size && right.map.size;\n const map = needToMergeMaps ? new Map :\n left.map.size ? left.map : right.map;\n\n const merged = { info, map };\n\n if (needToMergeMaps) {\n const remainingRightKeys = new Set(right.map.keys());\n\n left.map.forEach((leftTree, key) => {\n merged.map.set(\n key,\n mergeMergeTrees(leftTree, right.map.get(key)),\n );\n remainingRightKeys.delete(key);\n });\n\n remainingRightKeys.forEach(key => {\n merged.map.set(\n key,\n mergeMergeTrees(\n right.map.get(key),\n left.map.get(key),\n ),\n );\n });\n }\n\n return merged;\n}\n\nfunction mergeTreeIsEmpty(tree: MergeTree | undefined): boolean {\n return !tree || !(tree.info || tree.map.size);\n}\n\nfunction maybeRecycleChildMergeTree(\n { map }: MergeTree,\n name: string | number,\n) {\n const childTree = map.get(name);\n if (childTree && mergeTreeIsEmpty(childTree)) {\n emptyMergeTreePool.push(childTree);\n map.delete(name);\n }\n}\n\nconst warnings = new Set<string>();\n\n// Note that this function is unused in production, and thus should be\n// pruned by any well-configured minifier.\nfunction warnAboutDataLoss(\n existingRef: Reference,\n incomingObj: StoreObject,\n storeFieldName: string,\n store: NormalizedCache,\n) {\n const getChild = (objOrRef: StoreObject | Reference): StoreObject | false => {\n const child = store.getFieldValue<StoreObject>(objOrRef, storeFieldName);\n return typeof child === \"object\" && child;\n };\n\n const existing = getChild(existingRef);\n if (!existing) return;\n\n const incoming = getChild(incomingObj);\n if (!incoming) return;\n\n // It's always safe to replace a reference, since it refers to data\n // safely stored elsewhere.\n if (isReference(existing)) return;\n\n // If the values are structurally equivalent, we do not need to worry\n // about incoming replacing existing.\n if (equal(existing, incoming)) return;\n\n // If we're replacing every key of the existing object, then the\n // existing data would be overwritten even if the objects were\n // normalized, so warning would not be helpful here.\n if (Object.keys(existing).every(\n key => store.getFieldValue(incoming, key) !== void 0)) {\n return;\n }\n\n const parentType =\n store.getFieldValue<string>(existingRef, \"__typename\") ||\n store.getFieldValue<string>(incomingObj, \"__typename\");\n const fieldName = fieldNameFromStoreName(storeFieldName);\n const typeDotName = `${parentType}.${fieldName}`;\n // Avoid warning more than once for the same type and field name.\n if (warnings.has(typeDotName)) return;\n warnings.add(typeDotName);\n\n const childTypenames: string[] = [];\n // Arrays do not have __typename fields, and always need a custom merge\n // function, even if their elements are normalized entities.\n if (!Array.isArray(existing) &&\n !Array.isArray(incoming)) {\n [existing, incoming].forEach(child => {\n const typename = store.getFieldValue(child, \"__typename\");\n if (typeof typename === \"string\" &&\n !childTypenames.includes(typename)) {\n childTypenames.push(typename);\n }\n });\n }\n\n invariant.warn(\n`Cache data may be lost when replacing the ${fieldName} field of a ${parentType} object.\n\nTo address this problem (which is not a bug in Apollo Client), ${\n childTypenames.length\n ? \"either ensure all objects of type \" +\n childTypenames.join(\" and \") + \" have an ID or a custom merge function, or \"\n : \"\"\n}define a custom merge function for the ${\n typeDotName\n} field, so InMemoryCache can safely merge these objects:\n\n existing: ${JSON.stringify(existing).slice(0, 1000)}\n incoming: ${JSON.stringify(incoming).slice(0, 1000)}\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n`);\n}\n"]}
|