@apollo/client 3.4.3 → 3.4.7

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.
Files changed (61) hide show
  1. package/apollo-client.cjs.js +901 -29
  2. package/apollo-client.cjs.js.map +1 -1
  3. package/apollo-core.cjs.js +5745 -0
  4. package/apollo-core.cjs.js.map +1 -0
  5. package/apollo-core.cjs.min.js +1 -0
  6. package/cache/cache.cjs.js +3 -3
  7. package/cache/cache.cjs.js.map +1 -1
  8. package/cache/inmemory/writeToStore.d.ts +1 -1
  9. package/cache/inmemory/writeToStore.d.ts.map +1 -1
  10. package/cache/inmemory/writeToStore.js +3 -3
  11. package/cache/inmemory/writeToStore.js.map +1 -1
  12. package/core/ObservableQuery.d.ts +2 -0
  13. package/core/ObservableQuery.d.ts.map +1 -1
  14. package/core/ObservableQuery.js +9 -4
  15. package/core/ObservableQuery.js.map +1 -1
  16. package/core/QueryInfo.d.ts +5 -3
  17. package/core/QueryInfo.d.ts.map +1 -1
  18. package/core/QueryInfo.js +4 -2
  19. package/core/QueryInfo.js.map +1 -1
  20. package/core/QueryManager.d.ts +3 -3
  21. package/core/QueryManager.d.ts.map +1 -1
  22. package/core/QueryManager.js +15 -13
  23. package/core/QueryManager.js.map +1 -1
  24. package/core/core.cjs.js +28 -18
  25. package/core/core.cjs.js.map +1 -1
  26. package/core/watchQueryOptions.d.ts +2 -1
  27. package/core/watchQueryOptions.d.ts.map +1 -1
  28. package/core/watchQueryOptions.js.map +1 -1
  29. package/invariantErrorCodes.js +4 -2
  30. package/link/http/createHttpLink.d.ts.map +1 -1
  31. package/link/http/createHttpLink.js +7 -5
  32. package/link/http/createHttpLink.js.map +1 -1
  33. package/link/http/http.cjs.js +6 -5
  34. package/link/http/http.cjs.js.map +1 -1
  35. package/package.json +8 -11
  36. package/react/data/QueryData.d.ts +2 -1
  37. package/react/data/QueryData.d.ts.map +1 -1
  38. package/react/data/QueryData.js.map +1 -1
  39. package/react/hooks/hooks.cjs.js +1 -0
  40. package/react/hooks/hooks.cjs.js.map +1 -1
  41. package/react/hooks/utils/useBaseQuery.d.ts.map +1 -1
  42. package/react/hooks/utils/useBaseQuery.js +1 -0
  43. package/react/hooks/utils/useBaseQuery.js.map +1 -1
  44. package/testing/testing.cjs.js +0 -5
  45. package/testing/testing.cjs.js.map +1 -1
  46. package/utilities/index.d.ts +1 -0
  47. package/utilities/index.d.ts.map +1 -1
  48. package/utilities/index.js +1 -0
  49. package/utilities/index.js.map +1 -1
  50. package/utilities/testing/index.d.ts +0 -1
  51. package/utilities/testing/index.d.ts.map +1 -1
  52. package/utilities/testing/index.js +0 -1
  53. package/utilities/testing/index.js.map +1 -1
  54. package/utilities/utilities.cjs.js +1 -0
  55. package/utilities/utilities.cjs.js.map +1 -1
  56. package/version.js +1 -1
  57. package/apollo-client.cjs.min.js +0 -1
  58. package/utilities/testing/stripSymbols.d.ts +0 -2
  59. package/utilities/testing/stripSymbols.d.ts.map +0 -1
  60. package/utilities/testing/stripSymbols.js +0 -4
  61. package/utilities/testing/stripSymbols.js.map +0 -1
@@ -13,7 +13,7 @@ export interface WriteContext extends ReadMergeModifyContext {
13
13
  overwrite: boolean;
14
14
  incomingById: Map<string, {
15
15
  fields: StoreObject;
16
- mergeTree: MergeTree;
16
+ mergeTree?: MergeTree;
17
17
  selections: Set<SelectionNode>;
18
18
  }>;
19
19
  clientOnly: boolean;
@@ -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,C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O,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,CAAC,EAAE,SAAS,CAAC;QACtB,UAAU,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;KAChC,CAAC,CAAC;IACH,UAAU,EAAE,OAAO,CAAC;CACrB;AAUD,qBAAa,WAAW;aAEJ,KAAK,EAAE,aAAa;IACpC,OAAO,CAAC,MAAM,CAAC;gBADC,KAAK,EAAE,aAAa,EAC5B,MAAM,CAAC,yBAAa;IAGvB,YAAY,CAAC,KAAK,EAAE,eAAe,EAAE,EAC1C,KAAK,EACL,MAAM,EACN,MAAM,EACN,SAAS,EACT,SAAS,GACV,EAAE,KAAK,CAAC,YAAY,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,EAEjB,wBAAwB,EACxB,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,EACb,OAAO,EACP,sBAAsB,EAItB,WAAW,EACX,aAAa,EACb,SAAS,EACT,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAKvG,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAiBnD,CAAC;AAUF;IACE,qBACkB,KAAoB,EAC5B,MAAoB;QADZ,UAAK,GAAL,KAAK,CAAe;QAC5B,WAAM,GAAN,MAAM,CA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I,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/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,EAEjB,wBAAwB,EACxB,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,EACb,OAAO,EACP,sBAAsB,EAItB,WAAW,EACX,aAAa,EACb,SAAS,EACT,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAKv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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"]}
@@ -6,6 +6,7 @@ import { QueryManager } from './QueryManager';
6
6
  import { ApolloQueryResult, OperationVariables } from './types';
7
7
  import { WatchQueryOptions, FetchMoreQueryOptions, SubscribeToMoreOptions } from './watchQueryOptions';
8
8
  import { QueryInfo } from './QueryInfo';
9
+ import { MissingFieldError } from '../cache';
9
10
  export interface FetchMoreOptions<TData = any, TVariables = OperationVariables> {
10
11
  updateQuery?: (previousQueryResult: TData, options: {
11
12
  fetchMoreResult?: TData;
@@ -60,5 +61,6 @@ export declare class ObservableQuery<TData = any, TVariables = OperationVariable
60
61
  hasObservers(): boolean;
61
62
  private tearDownQuery;
62
63
  }
64
+ export declare function logMissingFieldErrors(missing: MissingFieldError[] | undefined): void;
63
65
  export declare function applyNextFetchPolicy<TData, TVars>(options: Pick<WatchQueryOptions<TVars, TData>, "fetchPolicy" | "nextFetchPolicy">): void;
64
66
  //# sourceMappingURL=ObservableQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ObservableQuery.d.ts","sourceRoot":"","sources":["../../src/core/ObservableQuery.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,aAAa,EAA4B,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAKL,UAAU,EAMX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EAEvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,WAAW,gBAAgB,CAC/B,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,kBAAkB;IAE/B,WAAW,CAAC,EAAE,CACZ,mBAAmB,EAAE,KAAK,EAC1B,OAAO,EAAE;QACP,eAAe,CAAC,EAAE,KAAK,CAAC;QACxB,SAAS,CAAC,EAAE,UAAU,CAAC;KACxB,KACE,KAAK,C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B,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAC/C,OAAO,EAAE,IAAI,CACX,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,EAC7B,aAAa,GACb,iBAAiB,CACpB,QAsBF"}
@@ -3,7 +3,6 @@ import { invariant } from 'ts-invariant';
3
3
  import { equal } from '@wry/equality';
4
4
  import { NetworkStatus, isNetworkRequestInFlight } from "./networkStatus.js";
5
5
  import { compact, cloneDeep, getOperationDefinition, Observable, iterateObserversSafely, isNonEmptyArray, fixObservableSubclass, } from "../utilities/index.js";
6
- import { ApolloError } from "../errors/index.js";
7
6
  var warnedAboutUpdateQuery = false;
8
7
  var ObservableQuery = (function (_super) {
9
8
  __extends(ObservableQuery, _super);
@@ -50,7 +49,7 @@ var ObservableQuery = (function (_super) {
50
49
  };
51
50
  _this.isTornDown = false;
52
51
  _this.options = options;
53
- _this.queryId = queryManager.generateQueryId();
52
+ _this.queryId = queryInfo.queryId || queryManager.generateQueryId();
54
53
  var opDef = getOperationDefinition(options.query);
55
54
  _this.queryName = opDef && opDef.name && opDef.name.value;
56
55
  _this.initialFetchPolicy = options.fetchPolicy || "cache-first";
@@ -107,12 +106,13 @@ var ObservableQuery = (function (_super) {
107
106
  else if (fetchPolicy !== "no-cache") {
108
107
  result.partial = true;
109
108
  }
110
- if (!diff.complete &&
109
+ if (__DEV__ &&
110
+ !diff.complete &&
111
111
  !this.options.partialRefetch &&
112
112
  !result.loading &&
113
113
  !result.data &&
114
114
  !result.error) {
115
- result.error = new ApolloError({ clientErrors: diff.missing });
115
+ logMissingFieldErrors(diff.missing);
116
116
  }
117
117
  }
118
118
  if (saveAsLastResult) {
@@ -389,6 +389,11 @@ fixObservableSubclass(ObservableQuery);
389
389
  function defaultSubscriptionObserverErrorCallback(error) {
390
390
  __DEV__ && invariant.error('Unhandled error', error.message, error.stack);
391
391
  }
392
+ export function logMissingFieldErrors(missing) {
393
+ if (__DEV__ && isNonEmptyArray(missing)) {
394
+ __DEV__ && invariant.debug("Missing cache result fields: " + missing.map(function (m) { return m.path.join('.'); }).join(', '), missing);
395
+ }
396
+ }
392
397
  export function applyNextFetchPolicy(options) {
393
398
  var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, nextFetchPolicy = options.nextFetchPolicy;
394
399
  if (nextFetchPolicy) {
@@ -1 +1 @@
1
- {"version":3,"file":"ObservableQuery.js","sourceRoot":"","sources":["../../src/core/ObservableQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAEL,OAAO,EACP,SAAS,EACT,sBAAsB,EACtB,UAAU,EAGV,sBAAsB,EACtB,eAAe,EACf,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AA4BxC,IAAI,sBAAsB,GAAG,KAAK,CAAC;AAEnC;IAGU,mCAAoC;IA+B5C,yBAAY,EAQX;YAPC,YAAY,kBAAA,EACZ,SAAS,eAAA,EACT,OAAO,aAAA;QAHT,YASE,kBAAM,UAAC,QAA4C;YAGjD,IAAI;gBACF,IAAI,WAAW,GAAI,QAAgB,CAAC,aAAa,CAAC,SAAS,CAAC;gBAC5D,IAAI,WAAW,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE;oBACrC,WAAW,CAAC,KAAK,GAAG,wCAAwC,CAAC;iBAC9D;aACF;YAAC,WAAM,GAAE;YAEV,IAAM,KAAK,GAAG,CAAC,KAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YACnC,KAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAG7B,IAAI,KAAI,CAAC,SAAS,EAAE;gBAClB,QAAQ,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK,CAAC,KAA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AO,YAFkB,EAA3B,WAAW,mBAAG,aAAa,KAAA,EAC3B,eAAe,GACb,OAAO,gBADM,CACL;IAEZ,IAAI,eAAe,EAAE;QAWnB,OAAO,CAAC,WAAW,GAAG,OAAO,eAAe,KAAK,UAAU;YACzD,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC;YAC5C,CAAC,CAAC,eAAe,CAAC;KACrB;AACH,CAAC","sourcesContent":["import { invariant } from 'ts-invariant';\nimport { equal } from '@wry/equality';\n\nimport { NetworkStatus, isNetworkRequestInFlight } from './networkStatus';\nimport {\n Concast,\n compact,\n cloneDeep,\n getOperationDefinition,\n Observable,\n Observer,\n ObservableSubscription,\n iterateObserversSafely,\n isNonEmptyArray,\n fixObservableSubclass,\n} from '../utilities';\nimport { ApolloError } from '../errors';\nimport { QueryManager } from './QueryManager';\nimport { ApolloQueryResult, OperationVariables } from './types';\nimport {\n WatchQueryOptions,\n FetchMoreQueryOptions,\n SubscribeToMoreOptions,\n WatchQueryFetchPolicy,\n} from './watchQueryOptions';\nimport { QueryInfo } from './QueryInfo';\n\nexport interface FetchMoreOptions<\n TData = any,\n TVariables = OperationVariables\n> {\n updateQuery?: (\n previousQueryResult: TData,\n options: {\n fetchMoreResult?: TData;\n variables?: TVariables;\n },\n ) => TData;\n}\n\nexport interface UpdateQueryOptions<TVariables> {\n variables?: TVariables;\n}\n\nlet warnedAboutUpdateQuery = false;\n\nexport class ObservableQuery<\n TData = any,\n TVariables = OperationVariables\n> extends Observable<ApolloQueryResult<TData>> {\n public readonly options: WatchQueryOptions<TVariables, TData>;\n public readonly queryId: string;\n public readonly queryName?: string;\n\n // Computed shorthand for this.options.variables, preserved for\n // backwards compatibility.\n public get variables(): TVariables | undefined {\n return this.options.variables;\n }\n\n // Original value of this.options.fetchPolicy (defaulting to \"cache-first\"),\n // from whenever the ObservableQuery was first created.\n private initialFetchPolicy: WatchQueryFetchPolicy;\n\n private isTornDown: boolean;\n private queryManager: QueryManager<any>;\n private observers = new Set<Observer<ApolloQueryResult<TData>>>();\n private subscriptions = new Set<ObservableSubscription>();\n\n private lastResult: ApolloQueryResult<TData> | undefined;\n private lastResultSnapshot: ApolloQueryResult<TData> | undefined;\n private lastError: ApolloError | undefined;\n private queryInfo: QueryInfo;\n\n private concast?: Concast<ApolloQueryResult<TData>>;\n private pollingInfo?: {\n interval: number;\n timeout: ReturnType<typeof setTimeout>;\n };\n\n constructor({\n queryManager,\n queryInfo,\n options,\n }: {\n queryManager: QueryManager<any>;\n queryInfo: QueryInfo;\n options: WatchQueryOptions<TVariables, TData>;\n }) {\n super((observer: Observer<ApolloQueryResult<TData>>) => {\n // Zen Observable has its own error function, so in order to log correctly\n // we need to provide a custom error callback.\n try {\n var subObserver = (observer as any)._subscription._observer;\n if (subObserver && !subObserver.error) {\n subObserver.error = defaultSubscriptionObserverErrorCallback;\n }\n } catch {}\n\n const first = !this.observers.size;\n this.observers.add(observer);\n\n // Deliver most recent error or result.\n if (this.lastError) {\n observer.error && observer.error(this.lastError);\n } else if (this.lastResult) {\n observer.next && observer.next(this.lastResult);\n }\n\n // Initiate observation of this query if it hasn't been reported to\n // the QueryManager yet.\n if (first) {\n // Blindly catching here prevents unhandled promise rejections,\n // and is safe because the ObservableQuery handles this error with\n // this.observer.error, so we're not just swallowing the error by\n // ignoring it here.\n this.reobserve().catch(() => {});\n }\n\n return () => {\n if (this.observers.delete(observer) && !this.observers.size) {\n this.tearDownQuery();\n }\n };\n });\n\n // active state\n this.isTornDown = false;\n\n // query information\n this.options = options;\n this.queryId = queryManager.generateQueryId();\n\n const opDef = getOperationDefinition(options.query);\n this.queryName = opDef && opDef.name && opDef.name.value;\n\n this.initialFetchPolicy = options.fetchPolicy || \"cache-first\";\n\n // related classes\n this.queryManager = queryManager;\n this.queryInfo = queryInfo;\n }\n\n public result(): Promise<ApolloQueryResult<TData>> {\n return new Promise((resolve, reject) => {\n // TODO: this code doesn’t actually make sense insofar as the observer\n // will never exist in this.observers due how zen-observable wraps observables.\n // https://github.com/zenparsing/zen-observable/blob/master/src/Observable.js#L169\n const observer: Observer<ApolloQueryResult<TData>> = {\n next: (result: ApolloQueryResult<TData>) => {\n resolve(result);\n\n // Stop the query within the QueryManager if we can before\n // this function returns.\n //\n // We do this in order to prevent observers piling up within\n // the QueryManager. Notice that we only fully unsubscribe\n // from the subscription in a setTimeout(..., 0) call. This call can\n // actually be handled by the browser at a much later time. If queries\n // are fired in the meantime, observers that should have been removed\n // from the QueryManager will continue to fire, causing an unnecessary\n // performance hit.\n this.observers.delete(observer);\n if (!this.observers.size) {\n this.queryManager.removeQuery(this.queryId);\n }\n\n setTimeout(() => {\n subscription.unsubscribe();\n }, 0);\n },\n error: reject,\n };\n const subscription = this.subscribe(observer);\n });\n }\n\n public getCurrentResult(saveAsLastResult = true): ApolloQueryResult<TData> {\n const {\n lastResult,\n options: {\n fetchPolicy = \"cache-first\",\n },\n } = this;\n\n const networkStatus =\n this.queryInfo.networkStatus ||\n (lastResult && lastResult.networkStatus) ||\n NetworkStatus.ready;\n\n const result = {\n ...lastResult,\n loading: isNetworkRequestInFlight(networkStatus),\n networkStatus,\n } as ApolloQueryResult<TData>;\n\n // If this.options.query has @client(always: true) fields, we cannot trust\n // diff.result, since it was read from the cache without running local\n // resolvers (and it's too late to run resolvers now, since we must return a\n // result synchronously).\n if (!this.queryManager.transform(this.options.query).hasForcedResolvers) {\n const diff = this.queryInfo.getDiff();\n\n result.data = (\n diff.complete ||\n this.options.returnPartialData\n ) ? diff.result : void 0;\n\n if (diff.complete) {\n // If the diff is complete, and we're using a FetchPolicy that\n // terminates after a complete cache read, we can assume the next\n // result we receive will have NetworkStatus.ready and !loading.\n if (result.networkStatus === NetworkStatus.loading &&\n (fetchPolicy === 'cache-first' ||\n fetchPolicy === 'cache-only')) {\n result.networkStatus = NetworkStatus.ready;\n result.loading = false;\n }\n delete result.partial;\n } else if (fetchPolicy !== \"no-cache\") {\n // Since result.partial comes from diff.complete, and we shouldn't be\n // using cache data to provide a DiffResult when the fetchPolicy is\n // \"no-cache\", avoid annotating result.partial for \"no-cache\" results.\n result.partial = true;\n }\n\n if (\n !diff.complete &&\n !this.options.partialRefetch &&\n !result.loading &&\n !result.data &&\n !result.error\n ) {\n result.error = new ApolloError({ clientErrors: diff.missing });\n }\n }\n\n if (saveAsLastResult) {\n this.updateLastResult(result);\n }\n\n return result;\n }\n\n // Compares newResult to the snapshot we took of this.lastResult when it was\n // first received.\n public isDifferentFromLastResult(newResult: ApolloQueryResult<TData>) {\n return !equal(this.lastResultSnapshot, newResult);\n }\n\n // Returns the last result that observer.next was called with. This is not the same as\n // getCurrentResult! If you're not sure which you need, then you probably need getCurrentResult.\n public getLastResult(): ApolloQueryResult<TData> | undefined {\n return this.lastResult;\n }\n\n public getLastError(): ApolloError | undefined {\n return this.lastError;\n }\n\n public resetLastResults(): void {\n delete this.lastResult;\n delete this.lastResultSnapshot;\n delete this.lastError;\n this.isTornDown = false;\n }\n\n public resetQueryStoreErrors() {\n this.queryManager.resetErrors(this.queryId);\n }\n\n /**\n * Update the variables of this observable query, and fetch the new results.\n * This method should be preferred over `setVariables` in most use cases.\n *\n * @param variables: The new set of variables. If there are missing variables,\n * the previous values of those variables will be used.\n */\n public refetch(variables?: Partial<TVariables>): Promise<ApolloQueryResult<TData>> {\n const reobserveOptions: Partial<WatchQueryOptions<TVariables, TData>> = {\n // Always disable polling for refetches.\n pollInterval: 0,\n };\n\n // Unless the provided fetchPolicy always consults the network\n // (no-cache, network-only, or cache-and-network), override it with\n // network-only to force the refetch for this fetchQuery call.\n const { fetchPolicy } = this.options;\n if (fetchPolicy === 'no-cache') {\n reobserveOptions.fetchPolicy = 'no-cache';\n } else if (fetchPolicy !== 'cache-and-network') {\n reobserveOptions.fetchPolicy = 'network-only';\n }\n\n if (variables && !equal(this.options.variables, variables)) {\n // Update the existing options with new variables\n reobserveOptions.variables = this.options.variables = {\n ...this.options.variables,\n ...variables,\n } as TVariables;\n }\n\n this.queryInfo.resetLastWrite();\n return this.reobserve(reobserveOptions, NetworkStatus.refetch);\n }\n\n public fetchMore(\n fetchMoreOptions: FetchMoreQueryOptions<TVariables, TData> &\n FetchMoreOptions<TData, TVariables>,\n ): Promise<ApolloQueryResult<TData>> {\n const combinedOptions = {\n ...(fetchMoreOptions.query ? fetchMoreOptions : {\n ...this.options,\n ...fetchMoreOptions,\n variables: {\n ...this.options.variables,\n ...fetchMoreOptions.variables,\n },\n }),\n // The fetchMore request goes immediately to the network and does\n // not automatically write its result to the cache (hence no-cache\n // instead of network-only), because we allow the caller of\n // fetchMore to provide an updateQuery callback that determines how\n // the data gets written to the cache.\n fetchPolicy: \"no-cache\",\n } as WatchQueryOptions;\n\n const qid = this.queryManager.generateQueryId();\n\n // Simulate a loading result for the original query with\n // result.networkStatus === NetworkStatus.fetchMore.\n if (combinedOptions.notifyOnNetworkStatusChange) {\n this.queryInfo.networkStatus = NetworkStatus.fetchMore;\n this.observe();\n }\n\n return this.queryManager.fetchQuery(\n qid,\n combinedOptions,\n NetworkStatus.fetchMore,\n ).then(fetchMoreResult => {\n const data = fetchMoreResult.data as TData;\n const { updateQuery } = fetchMoreOptions;\n\n if (updateQuery) {\n if (__DEV__ &&\n !warnedAboutUpdateQuery) {\n invariant.warn(\n`The updateQuery callback for fetchMore is deprecated, and will be removed\nin the next major version of Apollo Client.\n\nPlease convert updateQuery functions to field policies with appropriate\nread and merge functions, or use/adapt a helper function (such as\nconcatPagination, offsetLimitPagination, or relayStylePagination) from\n@apollo/client/utilities.\n\nThe field policy system handles pagination more effectively than a\nhand-written updateQuery function, and you only need to define the policy\nonce, rather than every time you call fetchMore.`);\n warnedAboutUpdateQuery = true;\n }\n this.updateQuery(previous => updateQuery(previous, {\n fetchMoreResult: data,\n variables: combinedOptions.variables as TVariables,\n }));\n } else {\n // If we're using a field policy instead of updateQuery, the only\n // thing we need to do is write the new data to the cache using\n // combinedOptions.variables (instead of this.variables, which is\n // what this.updateQuery uses, because it works by abusing the\n // original field value, keyed by the original variables).\n this.queryManager.cache.writeQuery({\n query: combinedOptions.query,\n variables: combinedOptions.variables,\n data,\n });\n }\n\n return fetchMoreResult as ApolloQueryResult<TData>;\n\n }).finally(() => {\n this.queryManager.stopQuery(qid);\n this.reobserve();\n });\n }\n\n // XXX the subscription variables are separate from the query variables.\n // if you want to update subscription variables, right now you have to do that separately,\n // and you can only do it by stopping the subscription and then subscribing again with new variables.\n public subscribeToMore<\n TSubscriptionData = TData,\n TSubscriptionVariables = TVariables\n >(\n options: SubscribeToMoreOptions<\n TData,\n TSubscriptionVariables,\n TSubscriptionData\n >,\n ) {\n const subscription = this.queryManager\n .startGraphQLSubscription({\n query: options.document,\n variables: options.variables,\n context: options.context,\n })\n .subscribe({\n next: (subscriptionData: { data: TSubscriptionData }) => {\n const { updateQuery } = options;\n if (updateQuery) {\n this.updateQuery<TSubscriptionVariables>(\n (previous, { variables }) =>\n updateQuery(previous, {\n subscriptionData,\n variables,\n }),\n );\n }\n },\n error: (err: any) => {\n if (options.onError) {\n options.onError(err);\n return;\n }\n invariant.error('Unhandled GraphQL subscription error', err);\n },\n });\n\n this.subscriptions.add(subscription);\n\n return () => {\n if (this.subscriptions.delete(subscription)) {\n subscription.unsubscribe();\n }\n };\n }\n\n public setOptions(\n newOptions: Partial<WatchQueryOptions<TVariables, TData>>,\n ): Promise<ApolloQueryResult<TData>> {\n return this.reobserve(newOptions);\n }\n\n /**\n * This is for *internal* use only. Most users should instead use `refetch`\n * in order to be properly notified of results even when they come from cache.\n *\n * Update the variables of this observable query, and fetch the new results\n * if they've changed. If you want to force new results, use `refetch`.\n *\n * Note: the `next` callback will *not* fire if the variables have not changed\n * or if the result is coming from cache.\n *\n * Note: the promise will return the old results immediately if the variables\n * have not changed.\n *\n * Note: the promise will return null immediately if the query is not active\n * (there are no subscribers).\n *\n * @private\n *\n * @param variables: The new set of variables. If there are missing variables,\n * the previous values of those variables will be used.\n */\n public setVariables(\n variables: TVariables,\n ): Promise<ApolloQueryResult<TData> | void> {\n if (equal(this.variables, variables)) {\n // If we have no observers, then we don't actually want to make a network\n // request. As soon as someone observes the query, the request will kick\n // off. For now, we just store any changes. (See #1077)\n return this.observers.size\n ? this.result()\n : Promise.resolve();\n }\n\n this.options.variables = variables;\n\n // See comment above\n if (!this.observers.size) {\n return Promise.resolve();\n }\n\n return this.reobserve({\n // Reset options.fetchPolicy to its original value.\n fetchPolicy: this.initialFetchPolicy,\n variables,\n }, NetworkStatus.setVariables);\n }\n\n public updateQuery<TVars = TVariables>(\n mapFn: (\n previousQueryResult: TData,\n options: Pick<WatchQueryOptions<TVars, TData>, \"variables\">,\n ) => TData,\n ): void {\n const { queryManager } = this;\n const { result } = queryManager.cache.diff<TData>({\n query: this.options.query,\n variables: this.variables,\n previousResult: this.lastResult?.data,\n returnPartialData: true,\n optimistic: false,\n });\n\n const newResult = mapFn(result!, {\n variables: (this as any).variables,\n });\n\n if (newResult) {\n queryManager.cache.writeQuery({\n query: this.options.query,\n data: newResult,\n variables: this.variables,\n });\n\n queryManager.broadcastQueries();\n }\n }\n\n public startPolling(pollInterval: number) {\n this.options.pollInterval = pollInterval;\n this.updatePolling();\n }\n\n public stopPolling() {\n this.options.pollInterval = 0;\n this.updatePolling();\n }\n\n private fetch(\n options: WatchQueryOptions<TVariables, TData>,\n newNetworkStatus?: NetworkStatus,\n ): Concast<ApolloQueryResult<TData>> {\n this.queryManager.setObservableQuery(this);\n return this.queryManager.fetchQueryObservable(\n this.queryId,\n options,\n newNetworkStatus,\n );\n }\n\n // Turns polling on or off based on this.options.pollInterval.\n private updatePolling() {\n // Avoid polling in SSR mode\n if (this.queryManager.ssrMode) {\n return;\n }\n\n const {\n pollingInfo,\n options: {\n pollInterval,\n },\n } = this;\n\n if (!pollInterval) {\n if (pollingInfo) {\n clearTimeout(pollingInfo.timeout);\n delete this.pollingInfo;\n }\n return;\n }\n\n if (pollingInfo &&\n pollingInfo.interval === pollInterval) {\n return;\n }\n\n invariant(\n pollInterval,\n 'Attempted to start a polling query without a polling interval.',\n );\n\n const info = pollingInfo || (this.pollingInfo = {} as any);\n info.interval = pollInterval;\n\n const maybeFetch = () => {\n if (this.pollingInfo) {\n if (!isNetworkRequestInFlight(this.queryInfo.networkStatus)) {\n this.reobserve({\n fetchPolicy: \"network-only\",\n }, NetworkStatus.poll).then(poll, poll);\n } else {\n poll();\n }\n };\n };\n\n const poll = () => {\n const info = this.pollingInfo;\n if (info) {\n clearTimeout(info.timeout);\n info.timeout = setTimeout(maybeFetch, info.interval);\n }\n };\n\n poll();\n }\n\n private updateLastResult(newResult: ApolloQueryResult<TData>) {\n const previousResult = this.lastResult;\n this.lastResult = newResult;\n this.lastResultSnapshot = this.queryManager.assumeImmutableResults\n ? newResult\n : cloneDeep(newResult);\n if (!isNonEmptyArray(newResult.errors)) {\n delete this.lastError;\n }\n return previousResult;\n }\n\n public reobserve(\n newOptions?: Partial<WatchQueryOptions<TVariables, TData>>,\n newNetworkStatus?: NetworkStatus,\n ): Promise<ApolloQueryResult<TData>> {\n this.isTornDown = false;\n\n const useDisposableConcast =\n // Refetching uses a disposable Concast to allow refetches using different\n // options/variables, without permanently altering the options of the\n // original ObservableQuery.\n newNetworkStatus === NetworkStatus.refetch ||\n // The fetchMore method does not actually call the reobserve method, but,\n // if it did, it would definitely use a disposable Concast.\n newNetworkStatus === NetworkStatus.fetchMore ||\n // Polling uses a disposable Concast so the polling options (which force\n // fetchPolicy to be \"network-only\") won't override the original options.\n newNetworkStatus === NetworkStatus.poll;\n\n // Save the old variables, since Object.assign may modify them below.\n const oldVariables = this.options.variables;\n\n const options = useDisposableConcast\n // Disposable Concast fetches receive a shallow copy of this.options\n // (merged with newOptions), leaving this.options unmodified.\n ? compact(this.options, newOptions)\n : Object.assign(this.options, compact(newOptions));\n\n if (!useDisposableConcast) {\n // We can skip calling updatePolling if we're not changing this.options.\n this.updatePolling();\n\n // Reset options.fetchPolicy to its original value when variables change,\n // unless a new fetchPolicy was provided by newOptions.\n if (\n newOptions &&\n newOptions.variables &&\n !newOptions.fetchPolicy &&\n !equal(newOptions.variables, oldVariables)\n ) {\n options.fetchPolicy = this.initialFetchPolicy;\n if (newNetworkStatus === void 0) {\n newNetworkStatus = NetworkStatus.setVariables;\n }\n }\n }\n\n const concast = this.fetch(options, newNetworkStatus);\n\n if (!useDisposableConcast) {\n // We use the {add,remove}Observer methods directly to avoid wrapping\n // observer with an unnecessary SubscriptionObserver object, in part so\n // that we can remove it here without triggering any unsubscriptions,\n // because we just want to ignore the old observable, not prematurely shut\n // it down, since other consumers may be awaiting this.concast.promise.\n if (this.concast) {\n this.concast.removeObserver(this.observer, true);\n }\n\n this.concast = concast;\n }\n\n concast.addObserver(this.observer);\n\n return concast.promise;\n }\n\n // Pass the current result to this.observer.next without applying any\n // fetch policies.\n private observe() {\n // Passing false is important so that this.getCurrentResult doesn't\n // save the fetchMore result as this.lastResult, causing it to be\n // ignored due to the this.isDifferentFromLastResult check in\n // this.observer.next.\n this.observer.next(this.getCurrentResult(false));\n }\n\n private observer = {\n next: (result: ApolloQueryResult<TData>) => {\n if (this.lastError || this.isDifferentFromLastResult(result)) {\n this.updateLastResult(result);\n iterateObserversSafely(this.observers, 'next', result);\n }\n },\n\n error: (error: ApolloError) => {\n // Since we don't get the current result on errors, only the error, we\n // must mirror the updates that occur in QueryStore.markQueryError here\n this.updateLastResult({\n ...this.lastResult,\n error,\n errors: error.graphQLErrors,\n networkStatus: NetworkStatus.error,\n loading: false,\n } as ApolloQueryResult<TData>);\n\n iterateObserversSafely(this.observers, 'error', this.lastError = error);\n },\n };\n\n public hasObservers() {\n return this.observers.size > 0;\n }\n\n private tearDownQuery() {\n if (this.isTornDown) return;\n if (this.concast) {\n this.concast.removeObserver(this.observer);\n delete this.concast;\n }\n\n this.stopPolling();\n // stop all active GraphQL subscriptions\n this.subscriptions.forEach(sub => sub.unsubscribe());\n this.subscriptions.clear();\n this.queryManager.stopQuery(this.queryId);\n this.observers.clear();\n this.isTornDown = true;\n }\n}\n\n// Necessary because the ObservableQuery constructor has a different\n// signature than the Observable constructor.\nfixObservableSubclass(ObservableQuery);\n\nfunction defaultSubscriptionObserverErrorCallback(error: ApolloError) {\n invariant.error('Unhandled error', error.message, error.stack);\n}\n\n// Adopt options.nextFetchPolicy (if defined) as a replacement for\n// options.fetchPolicy. Since this method also removes options.nextFetchPolicy\n// from options, the adoption tends to be idempotent, unless nextFetchPolicy\n// is a function that keeps setting options.nextFetchPolicy (uncommon).\nexport function applyNextFetchPolicy<TData, TVars>(\n options: Pick<\n WatchQueryOptions<TVars, TData>,\n | \"fetchPolicy\"\n | \"nextFetchPolicy\"\n >,\n) {\n const {\n fetchPolicy = \"cache-first\",\n nextFetchPolicy,\n } = options;\n\n if (nextFetchPolicy) {\n // When someone chooses \"cache-and-network\" or \"network-only\" as their\n // initial FetchPolicy, they often do not want future cache updates to\n // trigger unconditional network requests, which is what repeatedly\n // applying the \"cache-and-network\" or \"network-only\" policies would seem\n // to imply. Instead, when the cache reports an update after the initial\n // network request, it may be desirable for subsequent network requests to\n // be triggered only if the cache result is incomplete. To that end, the\n // options.nextFetchPolicy option provides an easy way to update\n // options.fetchPolicy after the intial network request, without having to\n // call observableQuery.setOptions.\n options.fetchPolicy = typeof nextFetchPolicy === \"function\"\n ? nextFetchPolicy.call(options, fetchPolicy)\n : nextFetchPolicy;\n }\n}\n"]}
1
+ {"version":3,"file":"ObservableQuery.js","sourceRoot":"","sources":["../../src/core/ObservableQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAEL,OAAO,EACP,SAAS,EACT,sBAAsB,EACtB,UAAU,EAGV,sBAAsB,EACtB,eAAe,EACf,qBAAqB,GACtB,MAAM,cAAc,CAAC;AA8BtB,IAAI,sBAAsB,GAAG,KAAK,CAAC;AAE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jB,CAAiB,CAAC,CAAC;QACrD,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAC3B,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IACH,sBAAC;AAAD,CAAC,AA5qBD,CAGU,UAAU,GAyqBnB;;AAID,qBAAqB,CAAC,eAAe,CAAC,CAAC;AAEvC,SAAS,wCAAwC,CAAC,KAAkB;IAClE,SAAS,CAAC,KAAK,CAAC,iBAAiB,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,OAAwC;IAExC,IAAI,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE;QACvC,SAAS,CAAC,KAAK,CAAC,kCACd,OAAO,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAhB,CAAgB,CAAC,CAAC,IAAI,CAAC,IAAI,CAC5C,EAAE,OAAO,CAAC,CAAC;KACd;AACH,CAAC;AAMD,MAAM,UAAU,oBAAoB,CAClC,OAIC;IAGC,IAAA,KAEE,OAAO,YAFkB,EAA3B,WAAW,mBAAG,aAAa,KAAA,EAC3B,eAAe,GACb,OAAO,gBADM,CACL;IAEZ,IAAI,eAAe,EAAE;QAWnB,OAAO,CAAC,WAAW,GAAG,OAAO,eAAe,KAAK,UAAU;YACzD,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC;YAC5C,CAAC,CAAC,eAAe,CAAC;KACrB;AACH,CAAC","sourcesContent":["import { invariant } from 'ts-invariant';\nimport { equal } from '@wry/equality';\n\nimport { NetworkStatus, isNetworkRequestInFlight } from './networkStatus';\nimport {\n Concast,\n compact,\n cloneDeep,\n getOperationDefinition,\n Observable,\n Observer,\n ObservableSubscription,\n iterateObserversSafely,\n isNonEmptyArray,\n fixObservableSubclass,\n} from '../utilities';\nimport { ApolloError } from '../errors';\nimport { QueryManager } from './QueryManager';\nimport { ApolloQueryResult, OperationVariables } from './types';\nimport {\n WatchQueryOptions,\n FetchMoreQueryOptions,\n SubscribeToMoreOptions,\n WatchQueryFetchPolicy,\n} from './watchQueryOptions';\nimport { QueryInfo } from './QueryInfo';\nimport { MissingFieldError } from '../cache';\n\nexport interface FetchMoreOptions<\n TData = any,\n TVariables = OperationVariables\n> {\n updateQuery?: (\n previousQueryResult: TData,\n options: {\n fetchMoreResult?: TData;\n variables?: TVariables;\n },\n ) => TData;\n}\n\nexport interface UpdateQueryOptions<TVariables> {\n variables?: TVariables;\n}\n\nlet warnedAboutUpdateQuery = false;\n\nexport class ObservableQuery<\n TData = any,\n TVariables = OperationVariables\n> extends Observable<ApolloQueryResult<TData>> {\n public readonly options: WatchQueryOptions<TVariables, TData>;\n public readonly queryId: string;\n public readonly queryName?: string;\n\n // Computed shorthand for this.options.variables, preserved for\n // backwards compatibility.\n public get variables(): TVariables | undefined {\n return this.options.variables;\n }\n\n // Original value of this.options.fetchPolicy (defaulting to \"cache-first\"),\n // from whenever the ObservableQuery was first created.\n private initialFetchPolicy: WatchQueryFetchPolicy;\n\n private isTornDown: boolean;\n private queryManager: QueryManager<any>;\n private observers = new Set<Observer<ApolloQueryResult<TData>>>();\n private subscriptions = new Set<ObservableSubscription>();\n\n private lastResult: ApolloQueryResult<TData> | undefined;\n private lastResultSnapshot: ApolloQueryResult<TData> | undefined;\n private lastError: ApolloError | undefined;\n private queryInfo: QueryInfo;\n\n private concast?: Concast<ApolloQueryResult<TData>>;\n private pollingInfo?: {\n interval: number;\n timeout: ReturnType<typeof setTimeout>;\n };\n\n constructor({\n queryManager,\n queryInfo,\n options,\n }: {\n queryManager: QueryManager<any>;\n queryInfo: QueryInfo;\n options: WatchQueryOptions<TVariables, TData>;\n }) {\n super((observer: Observer<ApolloQueryResult<TData>>) => {\n // Zen Observable has its own error function, so in order to log correctly\n // we need to provide a custom error callback.\n try {\n var subObserver = (observer as any)._subscription._observer;\n if (subObserver && !subObserver.error) {\n subObserver.error = defaultSubscriptionObserverErrorCallback;\n }\n } catch {}\n\n const first = !this.observers.size;\n this.observers.add(observer);\n\n // Deliver most recent error or result.\n if (this.lastError) {\n observer.error && observer.error(this.lastError);\n } else if (this.lastResult) {\n observer.next && observer.next(this.lastResult);\n }\n\n // Initiate observation of this query if it hasn't been reported to\n // the QueryManager yet.\n if (first) {\n // Blindly catching here prevents unhandled promise rejections,\n // and is safe because the ObservableQuery handles this error with\n // this.observer.error, so we're not just swallowing the error by\n // ignoring it here.\n this.reobserve().catch(() => {});\n }\n\n return () => {\n if (this.observers.delete(observer) && !this.observers.size) {\n this.tearDownQuery();\n }\n };\n });\n\n // active state\n this.isTornDown = false;\n\n // query information\n this.options = options;\n this.queryId = queryInfo.queryId || queryManager.generateQueryId();\n\n const opDef = getOperationDefinition(options.query);\n this.queryName = opDef && opDef.name && opDef.name.value;\n\n this.initialFetchPolicy = options.fetchPolicy || \"cache-first\";\n\n // related classes\n this.queryManager = queryManager;\n this.queryInfo = queryInfo;\n }\n\n public result(): Promise<ApolloQueryResult<TData>> {\n return new Promise((resolve, reject) => {\n // TODO: this code doesn’t actually make sense insofar as the observer\n // will never exist in this.observers due how zen-observable wraps observables.\n // https://github.com/zenparsing/zen-observable/blob/master/src/Observable.js#L169\n const observer: Observer<ApolloQueryResult<TData>> = {\n next: (result: ApolloQueryResult<TData>) => {\n resolve(result);\n\n // Stop the query within the QueryManager if we can before\n // this function returns.\n //\n // We do this in order to prevent observers piling up within\n // the QueryManager. Notice that we only fully unsubscribe\n // from the subscription in a setTimeout(..., 0) call. This call can\n // actually be handled by the browser at a much later time. If queries\n // are fired in the meantime, observers that should have been removed\n // from the QueryManager will continue to fire, causing an unnecessary\n // performance hit.\n this.observers.delete(observer);\n if (!this.observers.size) {\n this.queryManager.removeQuery(this.queryId);\n }\n\n setTimeout(() => {\n subscription.unsubscribe();\n }, 0);\n },\n error: reject,\n };\n const subscription = this.subscribe(observer);\n });\n }\n\n public getCurrentResult(saveAsLastResult = true): ApolloQueryResult<TData> {\n const {\n lastResult,\n options: {\n fetchPolicy = \"cache-first\",\n },\n } = this;\n\n const networkStatus =\n this.queryInfo.networkStatus ||\n (lastResult && lastResult.networkStatus) ||\n NetworkStatus.ready;\n\n const result = {\n ...lastResult,\n loading: isNetworkRequestInFlight(networkStatus),\n networkStatus,\n } as ApolloQueryResult<TData>;\n\n // If this.options.query has @client(always: true) fields, we cannot trust\n // diff.result, since it was read from the cache without running local\n // resolvers (and it's too late to run resolvers now, since we must return a\n // result synchronously).\n if (!this.queryManager.transform(this.options.query).hasForcedResolvers) {\n const diff = this.queryInfo.getDiff();\n\n result.data = (\n diff.complete ||\n this.options.returnPartialData\n ) ? diff.result : void 0;\n\n if (diff.complete) {\n // If the diff is complete, and we're using a FetchPolicy that\n // terminates after a complete cache read, we can assume the next\n // result we receive will have NetworkStatus.ready and !loading.\n if (result.networkStatus === NetworkStatus.loading &&\n (fetchPolicy === 'cache-first' ||\n fetchPolicy === 'cache-only')) {\n result.networkStatus = NetworkStatus.ready;\n result.loading = false;\n }\n delete result.partial;\n } else if (fetchPolicy !== \"no-cache\") {\n // Since result.partial comes from diff.complete, and we shouldn't be\n // using cache data to provide a DiffResult when the fetchPolicy is\n // \"no-cache\", avoid annotating result.partial for \"no-cache\" results.\n result.partial = true;\n }\n\n if (\n __DEV__ &&\n !diff.complete &&\n !this.options.partialRefetch &&\n !result.loading &&\n !result.data &&\n !result.error\n ) {\n logMissingFieldErrors(diff.missing);\n }\n }\n\n if (saveAsLastResult) {\n this.updateLastResult(result);\n }\n\n return result;\n }\n\n // Compares newResult to the snapshot we took of this.lastResult when it was\n // first received.\n public isDifferentFromLastResult(newResult: ApolloQueryResult<TData>) {\n return !equal(this.lastResultSnapshot, newResult);\n }\n\n // Returns the last result that observer.next was called with. This is not the same as\n // getCurrentResult! If you're not sure which you need, then you probably need getCurrentResult.\n public getLastResult(): ApolloQueryResult<TData> | undefined {\n return this.lastResult;\n }\n\n public getLastError(): ApolloError | undefined {\n return this.lastError;\n }\n\n public resetLastResults(): void {\n delete this.lastResult;\n delete this.lastResultSnapshot;\n delete this.lastError;\n this.isTornDown = false;\n }\n\n public resetQueryStoreErrors() {\n this.queryManager.resetErrors(this.queryId);\n }\n\n /**\n * Update the variables of this observable query, and fetch the new results.\n * This method should be preferred over `setVariables` in most use cases.\n *\n * @param variables: The new set of variables. If there are missing variables,\n * the previous values of those variables will be used.\n */\n public refetch(variables?: Partial<TVariables>): Promise<ApolloQueryResult<TData>> {\n const reobserveOptions: Partial<WatchQueryOptions<TVariables, TData>> = {\n // Always disable polling for refetches.\n pollInterval: 0,\n };\n\n // Unless the provided fetchPolicy always consults the network\n // (no-cache, network-only, or cache-and-network), override it with\n // network-only to force the refetch for this fetchQuery call.\n const { fetchPolicy } = this.options;\n if (fetchPolicy === 'no-cache') {\n reobserveOptions.fetchPolicy = 'no-cache';\n } else if (fetchPolicy !== 'cache-and-network') {\n reobserveOptions.fetchPolicy = 'network-only';\n }\n\n if (variables && !equal(this.options.variables, variables)) {\n // Update the existing options with new variables\n reobserveOptions.variables = this.options.variables = {\n ...this.options.variables,\n ...variables,\n } as TVariables;\n }\n\n this.queryInfo.resetLastWrite();\n return this.reobserve(reobserveOptions, NetworkStatus.refetch);\n }\n\n public fetchMore(\n fetchMoreOptions: FetchMoreQueryOptions<TVariables, TData> &\n FetchMoreOptions<TData, TVariables>,\n ): Promise<ApolloQueryResult<TData>> {\n const combinedOptions = {\n ...(fetchMoreOptions.query ? fetchMoreOptions : {\n ...this.options,\n ...fetchMoreOptions,\n variables: {\n ...this.options.variables,\n ...fetchMoreOptions.variables,\n },\n }),\n // The fetchMore request goes immediately to the network and does\n // not automatically write its result to the cache (hence no-cache\n // instead of network-only), because we allow the caller of\n // fetchMore to provide an updateQuery callback that determines how\n // the data gets written to the cache.\n fetchPolicy: \"no-cache\",\n } as WatchQueryOptions;\n\n const qid = this.queryManager.generateQueryId();\n\n // Simulate a loading result for the original query with\n // result.networkStatus === NetworkStatus.fetchMore.\n if (combinedOptions.notifyOnNetworkStatusChange) {\n this.queryInfo.networkStatus = NetworkStatus.fetchMore;\n this.observe();\n }\n\n return this.queryManager.fetchQuery(\n qid,\n combinedOptions,\n NetworkStatus.fetchMore,\n ).then(fetchMoreResult => {\n const data = fetchMoreResult.data as TData;\n const { updateQuery } = fetchMoreOptions;\n\n if (updateQuery) {\n if (__DEV__ &&\n !warnedAboutUpdateQuery) {\n invariant.warn(\n`The updateQuery callback for fetchMore is deprecated, and will be removed\nin the next major version of Apollo Client.\n\nPlease convert updateQuery functions to field policies with appropriate\nread and merge functions, or use/adapt a helper function (such as\nconcatPagination, offsetLimitPagination, or relayStylePagination) from\n@apollo/client/utilities.\n\nThe field policy system handles pagination more effectively than a\nhand-written updateQuery function, and you only need to define the policy\nonce, rather than every time you call fetchMore.`);\n warnedAboutUpdateQuery = true;\n }\n this.updateQuery(previous => updateQuery(previous, {\n fetchMoreResult: data,\n variables: combinedOptions.variables as TVariables,\n }));\n } else {\n // If we're using a field policy instead of updateQuery, the only\n // thing we need to do is write the new data to the cache using\n // combinedOptions.variables (instead of this.variables, which is\n // what this.updateQuery uses, because it works by abusing the\n // original field value, keyed by the original variables).\n this.queryManager.cache.writeQuery({\n query: combinedOptions.query,\n variables: combinedOptions.variables,\n data,\n });\n }\n\n return fetchMoreResult as ApolloQueryResult<TData>;\n\n }).finally(() => {\n this.queryManager.stopQuery(qid);\n this.reobserve();\n });\n }\n\n // XXX the subscription variables are separate from the query variables.\n // if you want to update subscription variables, right now you have to do that separately,\n // and you can only do it by stopping the subscription and then subscribing again with new variables.\n public subscribeToMore<\n TSubscriptionData = TData,\n TSubscriptionVariables = TVariables\n >(\n options: SubscribeToMoreOptions<\n TData,\n TSubscriptionVariables,\n TSubscriptionData\n >,\n ) {\n const subscription = this.queryManager\n .startGraphQLSubscription({\n query: options.document,\n variables: options.variables,\n context: options.context,\n })\n .subscribe({\n next: (subscriptionData: { data: TSubscriptionData }) => {\n const { updateQuery } = options;\n if (updateQuery) {\n this.updateQuery<TSubscriptionVariables>(\n (previous, { variables }) =>\n updateQuery(previous, {\n subscriptionData,\n variables,\n }),\n );\n }\n },\n error: (err: any) => {\n if (options.onError) {\n options.onError(err);\n return;\n }\n invariant.error('Unhandled GraphQL subscription error', err);\n },\n });\n\n this.subscriptions.add(subscription);\n\n return () => {\n if (this.subscriptions.delete(subscription)) {\n subscription.unsubscribe();\n }\n };\n }\n\n public setOptions(\n newOptions: Partial<WatchQueryOptions<TVariables, TData>>,\n ): Promise<ApolloQueryResult<TData>> {\n return this.reobserve(newOptions);\n }\n\n /**\n * This is for *internal* use only. Most users should instead use `refetch`\n * in order to be properly notified of results even when they come from cache.\n *\n * Update the variables of this observable query, and fetch the new results\n * if they've changed. If you want to force new results, use `refetch`.\n *\n * Note: the `next` callback will *not* fire if the variables have not changed\n * or if the result is coming from cache.\n *\n * Note: the promise will return the old results immediately if the variables\n * have not changed.\n *\n * Note: the promise will return null immediately if the query is not active\n * (there are no subscribers).\n *\n * @private\n *\n * @param variables: The new set of variables. If there are missing variables,\n * the previous values of those variables will be used.\n */\n public setVariables(\n variables: TVariables,\n ): Promise<ApolloQueryResult<TData> | void> {\n if (equal(this.variables, variables)) {\n // If we have no observers, then we don't actually want to make a network\n // request. As soon as someone observes the query, the request will kick\n // off. For now, we just store any changes. (See #1077)\n return this.observers.size\n ? this.result()\n : Promise.resolve();\n }\n\n this.options.variables = variables;\n\n // See comment above\n if (!this.observers.size) {\n return Promise.resolve();\n }\n\n return this.reobserve({\n // Reset options.fetchPolicy to its original value.\n fetchPolicy: this.initialFetchPolicy,\n variables,\n }, NetworkStatus.setVariables);\n }\n\n public updateQuery<TVars = TVariables>(\n mapFn: (\n previousQueryResult: TData,\n options: Pick<WatchQueryOptions<TVars, TData>, \"variables\">,\n ) => TData,\n ): void {\n const { queryManager } = this;\n const { result } = queryManager.cache.diff<TData>({\n query: this.options.query,\n variables: this.variables,\n previousResult: this.lastResult?.data,\n returnPartialData: true,\n optimistic: false,\n });\n\n const newResult = mapFn(result!, {\n variables: (this as any).variables,\n });\n\n if (newResult) {\n queryManager.cache.writeQuery({\n query: this.options.query,\n data: newResult,\n variables: this.variables,\n });\n\n queryManager.broadcastQueries();\n }\n }\n\n public startPolling(pollInterval: number) {\n this.options.pollInterval = pollInterval;\n this.updatePolling();\n }\n\n public stopPolling() {\n this.options.pollInterval = 0;\n this.updatePolling();\n }\n\n private fetch(\n options: WatchQueryOptions<TVariables, TData>,\n newNetworkStatus?: NetworkStatus,\n ): Concast<ApolloQueryResult<TData>> {\n this.queryManager.setObservableQuery(this);\n return this.queryManager.fetchQueryObservable(\n this.queryId,\n options,\n newNetworkStatus,\n );\n }\n\n // Turns polling on or off based on this.options.pollInterval.\n private updatePolling() {\n // Avoid polling in SSR mode\n if (this.queryManager.ssrMode) {\n return;\n }\n\n const {\n pollingInfo,\n options: {\n pollInterval,\n },\n } = this;\n\n if (!pollInterval) {\n if (pollingInfo) {\n clearTimeout(pollingInfo.timeout);\n delete this.pollingInfo;\n }\n return;\n }\n\n if (pollingInfo &&\n pollingInfo.interval === pollInterval) {\n return;\n }\n\n invariant(\n pollInterval,\n 'Attempted to start a polling query without a polling interval.',\n );\n\n const info = pollingInfo || (this.pollingInfo = {} as any);\n info.interval = pollInterval;\n\n const maybeFetch = () => {\n if (this.pollingInfo) {\n if (!isNetworkRequestInFlight(this.queryInfo.networkStatus)) {\n this.reobserve({\n fetchPolicy: \"network-only\",\n }, NetworkStatus.poll).then(poll, poll);\n } else {\n poll();\n }\n };\n };\n\n const poll = () => {\n const info = this.pollingInfo;\n if (info) {\n clearTimeout(info.timeout);\n info.timeout = setTimeout(maybeFetch, info.interval);\n }\n };\n\n poll();\n }\n\n private updateLastResult(newResult: ApolloQueryResult<TData>) {\n const previousResult = this.lastResult;\n this.lastResult = newResult;\n this.lastResultSnapshot = this.queryManager.assumeImmutableResults\n ? newResult\n : cloneDeep(newResult);\n if (!isNonEmptyArray(newResult.errors)) {\n delete this.lastError;\n }\n return previousResult;\n }\n\n public reobserve(\n newOptions?: Partial<WatchQueryOptions<TVariables, TData>>,\n newNetworkStatus?: NetworkStatus,\n ): Promise<ApolloQueryResult<TData>> {\n this.isTornDown = false;\n\n const useDisposableConcast =\n // Refetching uses a disposable Concast to allow refetches using different\n // options/variables, without permanently altering the options of the\n // original ObservableQuery.\n newNetworkStatus === NetworkStatus.refetch ||\n // The fetchMore method does not actually call the reobserve method, but,\n // if it did, it would definitely use a disposable Concast.\n newNetworkStatus === NetworkStatus.fetchMore ||\n // Polling uses a disposable Concast so the polling options (which force\n // fetchPolicy to be \"network-only\") won't override the original options.\n newNetworkStatus === NetworkStatus.poll;\n\n // Save the old variables, since Object.assign may modify them below.\n const oldVariables = this.options.variables;\n\n const options = useDisposableConcast\n // Disposable Concast fetches receive a shallow copy of this.options\n // (merged with newOptions), leaving this.options unmodified.\n ? compact(this.options, newOptions)\n : Object.assign(this.options, compact(newOptions));\n\n if (!useDisposableConcast) {\n // We can skip calling updatePolling if we're not changing this.options.\n this.updatePolling();\n\n // Reset options.fetchPolicy to its original value when variables change,\n // unless a new fetchPolicy was provided by newOptions.\n if (\n newOptions &&\n newOptions.variables &&\n !newOptions.fetchPolicy &&\n !equal(newOptions.variables, oldVariables)\n ) {\n options.fetchPolicy = this.initialFetchPolicy;\n if (newNetworkStatus === void 0) {\n newNetworkStatus = NetworkStatus.setVariables;\n }\n }\n }\n\n const concast = this.fetch(options, newNetworkStatus);\n\n if (!useDisposableConcast) {\n // We use the {add,remove}Observer methods directly to avoid wrapping\n // observer with an unnecessary SubscriptionObserver object, in part so\n // that we can remove it here without triggering any unsubscriptions,\n // because we just want to ignore the old observable, not prematurely shut\n // it down, since other consumers may be awaiting this.concast.promise.\n if (this.concast) {\n this.concast.removeObserver(this.observer, true);\n }\n\n this.concast = concast;\n }\n\n concast.addObserver(this.observer);\n\n return concast.promise;\n }\n\n // Pass the current result to this.observer.next without applying any\n // fetch policies.\n private observe() {\n // Passing false is important so that this.getCurrentResult doesn't\n // save the fetchMore result as this.lastResult, causing it to be\n // ignored due to the this.isDifferentFromLastResult check in\n // this.observer.next.\n this.observer.next(this.getCurrentResult(false));\n }\n\n private observer = {\n next: (result: ApolloQueryResult<TData>) => {\n if (this.lastError || this.isDifferentFromLastResult(result)) {\n this.updateLastResult(result);\n iterateObserversSafely(this.observers, 'next', result);\n }\n },\n\n error: (error: ApolloError) => {\n // Since we don't get the current result on errors, only the error, we\n // must mirror the updates that occur in QueryStore.markQueryError here\n this.updateLastResult({\n ...this.lastResult,\n error,\n errors: error.graphQLErrors,\n networkStatus: NetworkStatus.error,\n loading: false,\n } as ApolloQueryResult<TData>);\n\n iterateObserversSafely(this.observers, 'error', this.lastError = error);\n },\n };\n\n public hasObservers() {\n return this.observers.size > 0;\n }\n\n private tearDownQuery() {\n if (this.isTornDown) return;\n if (this.concast) {\n this.concast.removeObserver(this.observer);\n delete this.concast;\n }\n\n this.stopPolling();\n // stop all active GraphQL subscriptions\n this.subscriptions.forEach(sub => sub.unsubscribe());\n this.subscriptions.clear();\n this.queryManager.stopQuery(this.queryId);\n this.observers.clear();\n this.isTornDown = true;\n }\n}\n\n// Necessary because the ObservableQuery constructor has a different\n// signature than the Observable constructor.\nfixObservableSubclass(ObservableQuery);\n\nfunction defaultSubscriptionObserverErrorCallback(error: ApolloError) {\n invariant.error('Unhandled error', error.message, error.stack);\n}\n\nexport function logMissingFieldErrors(\n missing: MissingFieldError[] | undefined,\n) {\n if (__DEV__ && isNonEmptyArray(missing)) {\n invariant.debug(`Missing cache result fields: ${\n missing.map(m => m.path.join('.')).join(', ')\n }`, missing);\n }\n}\n\n// Adopt options.nextFetchPolicy (if defined) as a replacement for\n// options.fetchPolicy. Since this method also removes options.nextFetchPolicy\n// from options, the adoption tends to be idempotent, unless nextFetchPolicy\n// is a function that keeps setting options.nextFetchPolicy (uncommon).\nexport function applyNextFetchPolicy<TData, TVars>(\n options: Pick<\n WatchQueryOptions<TVars, TData>,\n | \"fetchPolicy\"\n | \"nextFetchPolicy\"\n >,\n) {\n const {\n fetchPolicy = \"cache-first\",\n nextFetchPolicy,\n } = options;\n\n if (nextFetchPolicy) {\n // When someone chooses \"cache-and-network\" or \"network-only\" as their\n // initial FetchPolicy, they often do not want future cache updates to\n // trigger unconditional network requests, which is what repeatedly\n // applying the \"cache-and-network\" or \"network-only\" policies would seem\n // to imply. Instead, when the cache reports an update after the initial\n // network request, it may be desirable for subsequent network requests to\n // be triggered only if the cache result is incomplete. To that end, the\n // options.nextFetchPolicy option provides an easy way to update\n // options.fetchPolicy after the intial network request, without having to\n // call observableQuery.setOptions.\n options.fetchPolicy = typeof nextFetchPolicy === \"function\"\n ? nextFetchPolicy.call(options, fetchPolicy)\n : nextFetchPolicy;\n }\n}\n"]}
@@ -1,12 +1,13 @@
1
1
  /// <reference types="zen-observable" />
2
2
  import { DocumentNode, GraphQLError } from 'graphql';
3
- import { Cache, ApolloCache } from '../cache';
3
+ import { Cache } from '../cache';
4
4
  import { WatchQueryOptions, ErrorPolicy } from './watchQueryOptions';
5
5
  import { ObservableQuery } from './ObservableQuery';
6
6
  import { QueryListener } from './types';
7
7
  import { FetchResult } from '../link/core';
8
8
  import { NetworkStatus } from './networkStatus';
9
9
  import { ApolloError } from '../errors';
10
+ import { QueryManager } from './QueryManager';
10
11
  export declare type QueryStoreValue = Pick<QueryInfo, "variables" | "networkStatus" | "networkError" | "graphQLErrors">;
11
12
  export declare const enum CacheWriteBehavior {
12
13
  FORBID = 0,
@@ -14,7 +15,7 @@ export declare const enum CacheWriteBehavior {
14
15
  MERGE = 2
15
16
  }
16
17
  export declare class QueryInfo {
17
- private cache;
18
+ readonly queryId: string;
18
19
  listeners: Set<QueryListener>;
19
20
  document: DocumentNode | null;
20
21
  lastRequestId: number;
@@ -24,7 +25,8 @@ export declare class QueryInfo {
24
25
  networkError?: Error | null;
25
26
  graphQLErrors?: ReadonlyArray<GraphQLError>;
26
27
  stopped: boolean;
27
- constructor(cache: ApolloCache<any>);
28
+ private cache;
29
+ constructor(queryManager: QueryManager<any>, queryId?: string);
28
30
  init(query: {
29
31
  document: DocumentNode;
30
32
  variables: Record<string, any> | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"QueryInfo.d.ts","sourceRoot":"","sources":["../../src/core/QueryInfo.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGrD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAO3C,OAAO,EACL,aAAa,EAEd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,oBAAY,eAAe,GAAG,IAAI,CAAC,SAAS,EACxC,WAAW,GACX,eAAe,GACf,cAAc,GACd,eAAe,CAChB,CAAC;AAEJ,0BAAkB,kBAAkB;IAClC,MAAM,IAAA;IACN,SAAS,IAAA;IACT,KAAK,IAAA;CACN;AA6CD,qBAAa,SAAS;IAWR,OAAO,CAAC,KAAK;IAVzB,SAAS,qBAA4B;IACrC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAQ;IACrC,aAAa,SAAK;IAClB,aAAa,kCAAqC;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,YAA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IAgBZ,UAAU,CAAC,CAAC,EACjB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAC3B,WAAW,GACX,aAAa,GACb,aAAa,CAAC,EAClB,kBAAkB,EAAE,kBAAkB;IA0GjC,SAAS;IAKT,SAAS,CAAC,KAAK,EAAE,WAAW;CAgBpC;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,WAAW,GAAE,WAAoB,WAUlC"}
package/core/QueryInfo.js CHANGED
@@ -20,8 +20,9 @@ function cancelNotifyTimeout(info) {
20
20
  }
21
21
  }
22
22
  var QueryInfo = (function () {
23
- function QueryInfo(cache) {
24
- this.cache = cache;
23
+ function QueryInfo(queryManager, queryId) {
24
+ if (queryId === void 0) { queryId = queryManager.generateQueryId(); }
25
+ this.queryId = queryId;
25
26
  this.listeners = new Set();
26
27
  this.document = null;
27
28
  this.lastRequestId = 1;
@@ -29,6 +30,7 @@ var QueryInfo = (function () {
29
30
  this.stopped = false;
30
31
  this.dirty = false;
31
32
  this.observableQuery = null;
33
+ var cache = this.cache = queryManager.cache;
32
34
  if (!destructiveMethodCounts.has(cache)) {
33
35
  destructiveMethodCounts.set(cache, 0);
34
36
  wrapDestructiveCacheMethod(cache, "evict");