@apollo/client 3.13.8 → 3.14.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/chilled-cameras-scream.md +5 -0
- package/.changeset/great-suns-cover.md +5 -0
- package/.changeset/perfect-donuts-roll.md +5 -0
- package/.changeset/popular-waves-drop.md +5 -0
- package/.changeset/pre.json +16 -0
- package/.changeset/shy-dragons-tease.md +5 -0
- package/.changeset/smooth-countries-cough.md +5 -0
- package/.changeset/spotty-walls-repair.md +5 -0
- package/CHANGELOG.md +20 -0
- package/README.md +80 -31
- package/apollo-client.cjs +354 -132
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +78 -21
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +78 -21
- package/cache/core/cache.js +27 -4
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +4 -4
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +2 -2
- package/cache/inmemory/inMemoryCache.js +15 -4
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/policies.js +18 -13
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +7 -0
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +14 -3
- package/cache/inmemory/types.js.map +1 -1
- package/core/ApolloClient.d.ts +191 -2
- package/core/ApolloClient.js +93 -7
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +2 -2
- package/core/ObservableQuery.js +10 -6
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.js +8 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.js +15 -12
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +93 -30
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +93 -30
- package/core/watchQueryOptions.d.ts +2 -2
- package/dev/dev.cjs +144 -84
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +144 -84
- package/invariantErrorCodes.js +158 -83
- package/link/core/ApolloLink.js +2 -2
- package/link/core/core.cjs +2 -2
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +2 -2
- package/link/http/checkFetcher.js +1 -1
- package/link/http/createHttpLink.js +1 -1
- package/link/http/http.cjs +3 -3
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +3 -3
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/persisted-queries/persisted-queries.cjs +2 -2
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
- package/link/utils/toPromise.js +1 -1
- package/link/utils/utils.cjs +2 -2
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +2 -2
- package/link/utils/validateOperation.js +1 -1
- package/masking/maskDefinition.js +2 -2
- package/masking/maskFragment.js +2 -2
- package/masking/maskOperation.js +1 -1
- package/masking/masking.cjs +6 -6
- package/masking/masking.cjs.map +1 -1
- package/masking/masking.cjs.native.js +6 -6
- package/masking/utils.js +1 -1
- package/package.json +1 -1
- package/react/components/Mutation.js +5 -0
- package/react/components/Mutation.js.map +1 -1
- package/react/components/Query.js +5 -0
- package/react/components/Query.js.map +1 -1
- package/react/components/Subscription.js +5 -0
- package/react/components/Subscription.js.map +1 -1
- package/react/components/components.cjs +34 -0
- package/react/components/components.cjs.map +1 -1
- package/react/components/components.cjs.native.js +34 -0
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloContext.js +7 -2
- package/react/context/ApolloContext.js.map +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/context.cjs +9 -4
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +9 -4
- package/react/hoc/graphql.js +17 -4
- package/react/hoc/graphql.js.map +1 -1
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/hoc.cjs +55 -9
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +55 -9
- package/react/hoc/mutation-hoc.js +8 -1
- package/react/hoc/mutation-hoc.js.map +1 -1
- package/react/hoc/query-hoc.js +8 -1
- package/react/hoc/query-hoc.js.map +1 -1
- package/react/hoc/subscription-hoc.js +8 -1
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/hoc/withApollo.js +1 -1
- package/react/hooks/hooks.cjs +264 -31
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +264 -31
- package/react/hooks/internal/index.d.ts +2 -0
- package/react/hooks/internal/index.js +2 -0
- package/react/hooks/internal/index.js.map +1 -1
- package/react/hooks/internal/useWarnRemoved.d.ts +2 -0
- package/react/hooks/internal/useWarnRemoved.js +14 -0
- package/react/hooks/internal/useWarnRemoved.js.map +1 -0
- package/react/hooks/internal/useWarnRemovedOption.d.ts +2 -0
- package/react/hooks/internal/useWarnRemovedOption.js +14 -0
- package/react/hooks/internal/useWarnRemovedOption.js.map +1 -0
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useBackgroundQuery.js +11 -3
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.js +30 -21
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.js +65 -0
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.js +12 -5
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.js +5 -1
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +2 -2
- package/react/hooks/useQuery.js +25 -7
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.js +3 -3
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +12 -6
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/internal/cache/QueryReference.d.ts +16 -0
- package/react/internal/cache/QueryReference.js +1 -1
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/internal.cjs +2 -2
- package/react/internal/internal.cjs.map +1 -1
- package/react/internal/internal.cjs.native.js +2 -2
- package/react/parser/index.d.ts +7 -0
- package/react/parser/index.js +17 -7
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs +28 -7
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +28 -7
- package/react/query-preloader/createQueryPreloader.d.ts +2 -1
- package/react/query-preloader/createQueryPreloader.js +14 -5
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/react.cjs +40 -6
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +40 -6
- package/react/types/types.d.ts +303 -9
- package/react/types/types.documentation.d.ts +2 -3
- package/react/types/types.documentation.js.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/core.cjs +2 -2
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +2 -2
- package/testing/core/mocking/mockLink.js +2 -2
- package/testing/react/MockedProvider.d.ts +27 -1
- package/testing/react/MockedProvider.js +16 -10
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +42 -11
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +42 -11
- package/utilities/deprecation/index.d.ts +11 -0
- package/utilities/deprecation/index.js +28 -0
- package/utilities/deprecation/index.js.map +1 -0
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/graphql/directives.js +7 -7
- package/utilities/graphql/fragments.js +3 -3
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/storeUtils.js +1 -1
- package/utilities/graphql/transform.js +2 -2
- package/utilities/utilities.cjs +22 -22
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +22 -22
- package/version.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readFromStore.js","sourceRoot":"","sources":["../../../src/cache/inmemory/readFromStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAGhF,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAQhC,OAAO,EACL,OAAO,EACP,sBAAsB,EACtB,WAAW,EACX,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,cAAc,EACd,UAAU,EACV,eAAe,EACf,aAAa,EACb,OAAO,EACP,kBAAkB,EAClB,UAAU,GAEX,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EACL,8BAA8B,EAC9B,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,OAAO,EACP,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAItB,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAgDhD,SAAS,uBAAuB,CAC9B,OAAgC;IAEhC,OAAO;QACL,OAAO,CAAC,YAAY;QACpB,OAAO,CAAC,iBAAiB;QACzB,OAAO,CAAC,OAAO;QACf,6DAA6D;QAC7D,0DAA0D;QAC1D,OAAO,CAAC,OAAO,CAAC,eAAe;KAChC,CAAC;AACJ,CAAC;AAED;IAiCE,qBAAY,MAAyB;QAArC,iBAwFC;QAlGO,iBAAY,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAGvD,CAAC;QAQF,IAAI,C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AAE,KAAK,CAAC,EACxC,KAAK,CAAC,IAAI,CAAC,KAAK,CACjB,CAAC;gBACF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,SAAO,CAAC,GAAG,EAAE,SAAO,CAAC,CAAC;YACrD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import { invariant, newInvariantError } from \"../../utilities/globals/index.js\";\n\nimport type { DocumentNode, FieldNode, SelectionSetNode } from \"graphql\";\nimport { Kind } from \"graphql\";\nimport type { OptimisticWrapperFunction } from \"optimism\";\nimport { wrap } from \"optimism\";\n\nimport type {\n Reference,\n StoreObject,\n FragmentMap,\n FragmentMapFunction,\n} from \"../../utilities/index.js\";\nimport {\n isField,\n resultKeyNameFromField,\n isReference,\n makeReference,\n shouldInclude,\n addTypenameToDocument,\n getDefaultValues,\n getMainDefinition,\n getQueryDefinition,\n getFragmentFromSelection,\n maybeDeepFreeze,\n mergeDeepArray,\n DeepMerger,\n isNonNullObject,\n canUseWeakMap,\n compact,\n canonicalStringify,\n cacheSizes,\n defaultCacheSizes,\n} from \"../../utilities/index.js\";\nimport type { Cache } from \"../core/types/Cache.js\";\nimport type {\n DiffQueryAgainstStoreOptions,\n InMemoryCacheConfig,\n NormalizedCache,\n ReadMergeModifyContext,\n} from \"./types.js\";\nimport {\n maybeDependOnExistenceOfEntity,\n supportsResultCaching,\n} from \"./entityStore.js\";\nimport {\n isArray,\n extractFragmentContext,\n getTypenameFromStoreObject,\n shouldCanonizeResults,\n} from \"./helpers.js\";\nimport type { Policies } from \"./policies.js\";\nimport type { InMemoryCache } from \"./inMemoryCache.js\";\nimport type { MissingTree } from \"../core/types/common.js\";\nimport { MissingFieldError } from \"../core/types/common.js\";\nimport { ObjectCanon } from \"./object-canon.js\";\n\nexport type VariableMap = { [name: string]: any };\n\ninterface ReadContext extends ReadMergeModifyContext {\n query: DocumentNode;\n policies: Policies;\n canonizeResults: boolean;\n fragmentMap: FragmentMap;\n lookupFragment: FragmentMapFunction;\n}\n\nexport type ExecResult<R = any> = {\n result: R;\n missing?: MissingTree;\n};\n\ntype ExecSelectionSetOptions = {\n selectionSet: SelectionSetNode;\n objectOrReference: StoreObject | Reference;\n enclosingRef: Reference;\n context: ReadContext;\n};\n\ntype ExecSubSelectedArrayOptions = {\n field: FieldNode;\n array: readonly any[];\n enclosingRef: Reference;\n context: ReadContext;\n};\n\nexport interface StoreReaderConfig {\n cache: InMemoryCache;\n addTypename?: boolean;\n resultCacheMaxSize?: number;\n canonizeResults?: boolean;\n canon?: ObjectCanon;\n fragments?: InMemoryCacheConfig[\"fragments\"];\n}\n\n// Arguments type after keyArgs translation.\ntype ExecSelectionSetKeyArgs = [\n SelectionSetNode,\n StoreObject | Reference,\n ReadMergeModifyContext,\n boolean,\n];\n\nfunction execSelectionSetKeyArgs(\n options: ExecSelectionSetOptions\n): ExecSelectionSetKeyArgs {\n return [\n options.selectionSet,\n options.objectOrReference,\n options.context,\n // We split out this property so we can pass different values\n // independently without modifying options.context itself.\n options.context.canonizeResults,\n ];\n}\n\nexport class StoreReader {\n // cached version of executeSelectionSet\n private executeSelectionSet: OptimisticWrapperFunction<\n [ExecSelectionSetOptions], // Actual arguments tuple type.\n ExecResult, // Actual return type.\n ExecSelectionSetKeyArgs\n >;\n\n // cached version of executeSubSelectedArray\n private executeSubSelectedArray: OptimisticWrapperFunction<\n [ExecSubSelectedArrayOptions],\n ExecResult<any>,\n [ExecSubSelectedArrayOptions]\n >;\n\n private config: {\n cache: InMemoryCache;\n addTypename: boolean;\n resultCacheMaxSize?: number;\n canonizeResults: boolean;\n fragments?: InMemoryCacheConfig[\"fragments\"];\n };\n\n private knownResults = new (canUseWeakMap ? WeakMap : Map)<\n Record<string, any>,\n SelectionSetNode\n >();\n\n public canon: ObjectCanon;\n public resetCanon() {\n this.canon = new ObjectCanon();\n }\n\n constructor(config: StoreReaderConfig) {\n this.config = compact(config, {\n addTypename: config.addTypename !== false,\n canonizeResults: shouldCanonizeResults(config),\n });\n\n this.canon = config.canon || new ObjectCanon();\n\n // memoized functions in this class will be \"garbage-collected\"\n // by recreating the whole `StoreReader` in\n // `InMemoryCache.resetResultsCache`\n // (triggered from `InMemoryCache.gc` with `resetResultCache: true`)\n this.executeSelectionSet = wrap(\n (options) => {\n const { canonizeResults } = options.context;\n\n const peekArgs = execSelectionSetKeyArgs(options);\n\n // Negate this boolean option so we can find out if we've already read\n // this result using the other boolean value.\n peekArgs[3] = !canonizeResults;\n\n const other = this.executeSelectionSet.peek(...peekArgs);\n\n if (other) {\n if (canonizeResults) {\n return {\n ...other,\n // If we previously read this result without canonizing it, we can\n // reuse that result simply by canonizing it now.\n result: this.canon.admit(other.result),\n };\n }\n // If we previously read this result with canonization enabled, we can\n // return that canonized result as-is.\n return other;\n }\n\n maybeDependOnExistenceOfEntity(\n options.context.store,\n options.enclosingRef.__ref\n );\n\n // Finally, if we didn't find any useful previous results, run the real\n // execSelectionSetImpl method with the given options.\n return this.execSelectionSetImpl(options);\n },\n {\n max:\n this.config.resultCacheMaxSize ||\n cacheSizes[\"inMemoryCache.executeSelectionSet\"] ||\n defaultCacheSizes[\"inMemoryCache.executeSelectionSet\"],\n keyArgs: execSelectionSetKeyArgs,\n // Note that the parameters of makeCacheKey are determined by the\n // array returned by keyArgs.\n makeCacheKey(selectionSet, parent, context, canonizeResults) {\n if (supportsResultCaching(context.store)) {\n return context.store.makeCacheKey(\n selectionSet,\n isReference(parent) ? parent.__ref : parent,\n context.varString,\n canonizeResults\n );\n }\n },\n }\n );\n\n this.executeSubSelectedArray = wrap(\n (options: ExecSubSelectedArrayOptions) => {\n maybeDependOnExistenceOfEntity(\n options.context.store,\n options.enclosingRef.__ref\n );\n return this.execSubSelectedArrayImpl(options);\n },\n {\n max:\n this.config.resultCacheMaxSize ||\n cacheSizes[\"inMemoryCache.executeSubSelectedArray\"] ||\n defaultCacheSizes[\"inMemoryCache.executeSubSelectedArray\"],\n makeCacheKey({ field, array, context }) {\n if (supportsResultCaching(context.store)) {\n return context.store.makeCacheKey(field, array, context.varString);\n }\n },\n }\n );\n }\n\n /**\n * Given a store and a query, return as much of the result as possible and\n * identify if any data was missing from the store.\n */\n public diffQueryAgainstStore<T>({\n store,\n query,\n rootId = \"ROOT_QUERY\",\n variables,\n returnPartialData = true,\n canonizeResults = this.config.canonizeResults,\n }: DiffQueryAgainstStoreOptions): Cache.DiffResult<T> {\n const policies = this.config.cache.policies;\n\n variables = {\n ...getDefaultValues(getQueryDefinition(query)),\n ...variables!,\n };\n\n const rootRef = makeReference(rootId);\n const execResult = this.executeSelectionSet({\n selectionSet: getMainDefinition(query).selectionSet,\n objectOrReference: rootRef,\n enclosingRef: rootRef,\n context: {\n store,\n query,\n policies,\n variables,\n varString: canonicalStringify(variables),\n canonizeResults,\n ...extractFragmentContext(query, this.config.fragments),\n },\n });\n\n let missing: MissingFieldError[] | undefined;\n if (execResult.missing) {\n // For backwards compatibility we still report an array of\n // MissingFieldError objects, even though there will only ever be at most\n // one of them, now that all missing field error messages are grouped\n // together in the execResult.missing tree.\n missing = [\n new MissingFieldError(\n firstMissing(execResult.missing)!,\n execResult.missing,\n query,\n variables\n ),\n ];\n if (!returnPartialData) {\n throw missing[0];\n }\n }\n\n return {\n result: execResult.result,\n complete: !missing,\n missing,\n };\n }\n\n public isFresh(\n result: Record<string, any>,\n parent: StoreObject | Reference,\n selectionSet: SelectionSetNode,\n context: ReadMergeModifyContext\n ): boolean {\n if (\n supportsResultCaching(context.store) &&\n this.knownResults.get(result) === selectionSet\n ) {\n const latest = this.executeSelectionSet.peek(\n selectionSet,\n parent,\n context,\n // If result is canonical, then it could only have been previously\n // cached by the canonizing version of executeSelectionSet, so we can\n // avoid checking both possibilities here.\n this.canon.isKnown(result)\n );\n if (latest && result === latest.result) {\n return true;\n }\n }\n return false;\n }\n\n // Uncached version of executeSelectionSet.\n private execSelectionSetImpl({\n selectionSet,\n objectOrReference,\n enclosingRef,\n context,\n }: ExecSelectionSetOptions): ExecResult {\n if (\n isReference(objectOrReference) &&\n !context.policies.rootTypenamesById[objectOrReference.__ref] &&\n !context.store.has(objectOrReference.__ref)\n ) {\n return {\n result: this.canon.empty,\n missing: `Dangling reference to missing ${objectOrReference.__ref} object`,\n };\n }\n\n const { variables, policies, store } = context;\n const typename = store.getFieldValue<string>(\n objectOrReference,\n \"__typename\"\n );\n\n const objectsToMerge: Record<string, any>[] = [];\n let missing: MissingTree | undefined;\n const missingMerger = new DeepMerger();\n\n if (\n this.config.addTypename &&\n typeof typename === \"string\" &&\n !policies.rootIdsByTypename[typename]\n ) {\n // Ensure we always include a default value for the __typename\n // field, if we have one, and this.config.addTypename is true. Note\n // that this field can be overridden by other merged objects.\n objectsToMerge.push({ __typename: typename });\n }\n\n function handleMissing<T>(result: ExecResult<T>, resultName: string): T {\n if (result.missing) {\n missing = missingMerger.merge(missing, {\n [resultName]: result.missing,\n });\n }\n return result.result;\n }\n\n const workSet = new Set(selectionSet.selections);\n\n workSet.forEach((selection) => {\n // Omit fields with directives @skip(if: <truthy value>) or\n // @include(if: <falsy value>).\n if (!shouldInclude(selection, variables)) return;\n\n if (isField(selection)) {\n let fieldValue = policies.readField(\n {\n fieldName: selection.name.value,\n field: selection,\n variables: context.variables,\n from: objectOrReference,\n },\n context\n );\n\n const resultName = resultKeyNameFromField(selection);\n\n if (fieldValue === void 0) {\n if (!addTypenameToDocument.added(selection)) {\n missing = missingMerger.merge(missing, {\n [resultName]: `Can't find field '${selection.name.value}' on ${\n isReference(objectOrReference) ?\n objectOrReference.__ref + \" object\"\n : \"object \" + JSON.stringify(objectOrReference, null, 2)\n }`,\n });\n }\n } else if (isArray(fieldValue)) {\n if (fieldValue.length > 0) {\n fieldValue = handleMissing(\n this.executeSubSelectedArray({\n field: selection,\n array: fieldValue,\n enclosingRef,\n context,\n }),\n resultName\n );\n }\n } else if (!selection.selectionSet) {\n // If the field does not have a selection set, then we handle it\n // as a scalar value. To keep this.canon from canonicalizing\n // this value, we use this.canon.pass to wrap fieldValue in a\n // Pass object that this.canon.admit will later unwrap as-is.\n if (context.canonizeResults) {\n fieldValue = this.canon.pass(fieldValue);\n }\n } else if (fieldValue != null) {\n // In this case, because we know the field has a selection set,\n // it must be trying to query a GraphQLObjectType, which is why\n // fieldValue must be != null.\n fieldValue = handleMissing(\n this.executeSelectionSet({\n selectionSet: selection.selectionSet,\n objectOrReference: fieldValue as StoreObject | Reference,\n enclosingRef: isReference(fieldValue) ? fieldValue : enclosingRef,\n context,\n }),\n resultName\n );\n }\n\n if (fieldValue !== void 0) {\n objectsToMerge.push({ [resultName]: fieldValue });\n }\n } else {\n const fragment = getFragmentFromSelection(\n selection,\n context.lookupFragment\n );\n\n if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {\n throw newInvariantError(`No fragment named %s`, selection.name.value);\n }\n\n if (fragment && policies.fragmentMatches(fragment, typename)) {\n fragment.selectionSet.selections.forEach(workSet.add, workSet);\n }\n }\n });\n\n const result = mergeDeepArray(objectsToMerge);\n const finalResult: ExecResult = { result, missing };\n const frozen =\n context.canonizeResults ?\n this.canon.admit(finalResult)\n // Since this.canon is normally responsible for freezing results (only in\n // development), freeze them manually if canonization is disabled.\n : maybeDeepFreeze(finalResult);\n\n // Store this result with its selection set so that we can quickly\n // recognize it again in the StoreReader#isFresh method.\n if (frozen.result) {\n this.knownResults.set(frozen.result, selectionSet);\n }\n\n return frozen;\n }\n\n // Uncached version of executeSubSelectedArray.\n private execSubSelectedArrayImpl({\n field,\n array,\n enclosingRef,\n context,\n }: ExecSubSelectedArrayOptions): ExecResult {\n let missing: MissingTree | undefined;\n let missingMerger = new DeepMerger<MissingTree[]>();\n\n function handleMissing<T>(childResult: ExecResult<T>, i: number): T {\n if (childResult.missing) {\n missing = missingMerger.merge(missing, { [i]: childResult.missing });\n }\n return childResult.result;\n }\n\n if (field.selectionSet) {\n array = array.filter(context.store.canRead);\n }\n\n array = array.map((item, i) => {\n // null value in array\n if (item === null) {\n return null;\n }\n\n // This is a nested array, recurse\n if (isArray(item)) {\n return handleMissing(\n this.executeSubSelectedArray({\n field,\n array: item,\n enclosingRef,\n context,\n }),\n i\n );\n }\n\n // This is an object, run the selection set on it\n if (field.selectionSet) {\n return handleMissing(\n this.executeSelectionSet({\n selectionSet: field.selectionSet,\n objectOrReference: item,\n enclosingRef: isReference(item) ? item : enclosingRef,\n context,\n }),\n i\n );\n }\n\n if (__DEV__) {\n assertSelectionSetForIdValue(context.store, field, item);\n }\n\n return item;\n });\n\n return {\n result: context.canonizeResults ? this.canon.admit(array) : array,\n missing,\n };\n }\n}\n\nfunction firstMissing(tree: MissingTree): string | undefined {\n try {\n JSON.stringify(tree, (_, value) => {\n if (typeof value === \"string\") throw value;\n return value;\n });\n } catch (result) {\n return result as string;\n }\n}\n\nfunction assertSelectionSetForIdValue(\n store: NormalizedCache,\n field: FieldNode,\n fieldValue: any\n) {\n if (!field.selectionSet) {\n const workSet = new Set([fieldValue]);\n workSet.forEach((value) => {\n if (isNonNullObject(value)) {\n invariant(\n !isReference(value),\n `Missing selection set for object of type %s returned for query field %s`,\n getTypenameFromStoreObject(store, value),\n field.name.value\n );\n Object.values(value).forEach(workSet.add, workSet);\n }\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"readFromStore.js","sourceRoot":"","sources":["../../../src/cache/inmemory/readFromStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAGhF,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAQhC,OAAO,EACL,OAAO,EACP,sBAAsB,EACtB,WAAW,EACX,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,cAAc,EACd,UAAU,EACV,eAAe,EACf,aAAa,EACb,OAAO,EACP,kBAAkB,EAClB,UAAU,GA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AAY,CAAC,IAAiB;IACrC,IAAI,CAAC;QACH,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,UAAC,CAAC,EAAE,KAAK;YAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ;gBAAE,MAAM,KAAK,CAAC;YAC3C,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,OAAO,MAAgB,CAAC;IAC1B,CAAC;AACH,CAAC;AAED,SAAS,4BAA4B,CACnC,KAAsB,EACtB,KAAgB,EAChB,UAAe;IAEf,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;QACxB,IAAM,SAAO,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;QACtC,SAAO,CAAC,OAAO,CAAC,UAAC,KAAK;YACpB,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3B,SAAS,CACP,CAAC,WAAW,CAAC,KAAK,CAAC,EACnB,yEAAyE,EACzE,0BAA0B,CAAC,KAAK,EAAE,KAAK,CAAC,EACxC,KAAK,CAAC,IAAI,CAAC,KAAK,CACjB,CAAC;gBACF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,SAAO,CAAC,GAAG,EAAE,SAAO,CAAC,CAAC;YACrD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import { invariant, newInvariantError } from \"../../utilities/globals/index.js\";\n\nimport type { DocumentNode, FieldNode, SelectionSetNode } from \"graphql\";\nimport { Kind } from \"graphql\";\nimport type { OptimisticWrapperFunction } from \"optimism\";\nimport { wrap } from \"optimism\";\n\nimport type {\n Reference,\n StoreObject,\n FragmentMap,\n FragmentMapFunction,\n} from \"../../utilities/index.js\";\nimport {\n isField,\n resultKeyNameFromField,\n isReference,\n makeReference,\n shouldInclude,\n addTypenameToDocument,\n getDefaultValues,\n getMainDefinition,\n getQueryDefinition,\n getFragmentFromSelection,\n maybeDeepFreeze,\n mergeDeepArray,\n DeepMerger,\n isNonNullObject,\n canUseWeakMap,\n compact,\n canonicalStringify,\n cacheSizes,\n defaultCacheSizes,\n} from \"../../utilities/index.js\";\nimport type { Cache } from \"../core/types/Cache.js\";\nimport type {\n DiffQueryAgainstStoreOptions,\n InMemoryCacheConfig,\n NormalizedCache,\n ReadMergeModifyContext,\n} from \"./types.js\";\nimport {\n maybeDependOnExistenceOfEntity,\n supportsResultCaching,\n} from \"./entityStore.js\";\nimport {\n isArray,\n extractFragmentContext,\n getTypenameFromStoreObject,\n shouldCanonizeResults,\n} from \"./helpers.js\";\nimport type { Policies } from \"./policies.js\";\nimport type { InMemoryCache } from \"./inMemoryCache.js\";\nimport type { MissingTree } from \"../core/types/common.js\";\nimport { MissingFieldError } from \"../core/types/common.js\";\nimport { ObjectCanon } from \"./object-canon.js\";\n\nexport type VariableMap = { [name: string]: any };\n\ninterface ReadContext extends ReadMergeModifyContext {\n query: DocumentNode;\n policies: Policies;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#canonizeResults:member} */\n canonizeResults: boolean;\n fragmentMap: FragmentMap;\n lookupFragment: FragmentMapFunction;\n}\n\nexport type ExecResult<R = any> = {\n result: R;\n missing?: MissingTree;\n};\n\ntype ExecSelectionSetOptions = {\n selectionSet: SelectionSetNode;\n objectOrReference: StoreObject | Reference;\n enclosingRef: Reference;\n context: ReadContext;\n};\n\ntype ExecSubSelectedArrayOptions = {\n field: FieldNode;\n array: readonly any[];\n enclosingRef: Reference;\n context: ReadContext;\n};\n\nexport interface StoreReaderConfig {\n cache: InMemoryCache;\n addTypename?: boolean;\n resultCacheMaxSize?: number;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#canonizeResults:member} */\n canonizeResults?: boolean;\n canon?: ObjectCanon;\n fragments?: InMemoryCacheConfig[\"fragments\"];\n}\n\n// Arguments type after keyArgs translation.\ntype ExecSelectionSetKeyArgs = [\n SelectionSetNode,\n StoreObject | Reference,\n ReadMergeModifyContext,\n boolean,\n];\n\nfunction execSelectionSetKeyArgs(\n options: ExecSelectionSetOptions\n): ExecSelectionSetKeyArgs {\n return [\n options.selectionSet,\n options.objectOrReference,\n options.context,\n // We split out this property so we can pass different values\n // independently without modifying options.context itself.\n options.context.canonizeResults,\n ];\n}\n\nexport class StoreReader {\n // cached version of executeSelectionSet\n private executeSelectionSet: OptimisticWrapperFunction<\n [ExecSelectionSetOptions], // Actual arguments tuple type.\n ExecResult, // Actual return type.\n ExecSelectionSetKeyArgs\n >;\n\n // cached version of executeSubSelectedArray\n private executeSubSelectedArray: OptimisticWrapperFunction<\n [ExecSubSelectedArrayOptions],\n ExecResult<any>,\n [ExecSubSelectedArrayOptions]\n >;\n\n private config: {\n cache: InMemoryCache;\n addTypename: boolean;\n resultCacheMaxSize?: number;\n canonizeResults: boolean;\n fragments?: InMemoryCacheConfig[\"fragments\"];\n };\n\n private knownResults = new (canUseWeakMap ? WeakMap : Map)<\n Record<string, any>,\n SelectionSetNode\n >();\n\n public canon: ObjectCanon;\n public resetCanon() {\n this.canon = new ObjectCanon();\n }\n\n constructor(config: StoreReaderConfig) {\n this.config = compact(config, {\n addTypename: config.addTypename !== false,\n canonizeResults: shouldCanonizeResults(config),\n });\n\n this.canon = config.canon || new ObjectCanon();\n\n // memoized functions in this class will be \"garbage-collected\"\n // by recreating the whole `StoreReader` in\n // `InMemoryCache.resetResultsCache`\n // (triggered from `InMemoryCache.gc` with `resetResultCache: true`)\n this.executeSelectionSet = wrap(\n (options) => {\n const { canonizeResults } = options.context;\n\n const peekArgs = execSelectionSetKeyArgs(options);\n\n // Negate this boolean option so we can find out if we've already read\n // this result using the other boolean value.\n peekArgs[3] = !canonizeResults;\n\n const other = this.executeSelectionSet.peek(...peekArgs);\n\n if (other) {\n if (canonizeResults) {\n return {\n ...other,\n // If we previously read this result without canonizing it, we can\n // reuse that result simply by canonizing it now.\n result: this.canon.admit(other.result),\n };\n }\n // If we previously read this result with canonization enabled, we can\n // return that canonized result as-is.\n return other;\n }\n\n maybeDependOnExistenceOfEntity(\n options.context.store,\n options.enclosingRef.__ref\n );\n\n // Finally, if we didn't find any useful previous results, run the real\n // execSelectionSetImpl method with the given options.\n return this.execSelectionSetImpl(options);\n },\n {\n max:\n this.config.resultCacheMaxSize ||\n cacheSizes[\"inMemoryCache.executeSelectionSet\"] ||\n defaultCacheSizes[\"inMemoryCache.executeSelectionSet\"],\n keyArgs: execSelectionSetKeyArgs,\n // Note that the parameters of makeCacheKey are determined by the\n // array returned by keyArgs.\n makeCacheKey(selectionSet, parent, context, canonizeResults) {\n if (supportsResultCaching(context.store)) {\n return context.store.makeCacheKey(\n selectionSet,\n isReference(parent) ? parent.__ref : parent,\n context.varString,\n canonizeResults\n );\n }\n },\n }\n );\n\n this.executeSubSelectedArray = wrap(\n (options: ExecSubSelectedArrayOptions) => {\n maybeDependOnExistenceOfEntity(\n options.context.store,\n options.enclosingRef.__ref\n );\n return this.execSubSelectedArrayImpl(options);\n },\n {\n max:\n this.config.resultCacheMaxSize ||\n cacheSizes[\"inMemoryCache.executeSubSelectedArray\"] ||\n defaultCacheSizes[\"inMemoryCache.executeSubSelectedArray\"],\n makeCacheKey({ field, array, context }) {\n if (supportsResultCaching(context.store)) {\n return context.store.makeCacheKey(field, array, context.varString);\n }\n },\n }\n );\n }\n\n /**\n * Given a store and a query, return as much of the result as possible and\n * identify if any data was missing from the store.\n */\n public diffQueryAgainstStore<T>({\n store,\n query,\n rootId = \"ROOT_QUERY\",\n variables,\n returnPartialData = true,\n canonizeResults = this.config.canonizeResults,\n }: DiffQueryAgainstStoreOptions): Cache.DiffResult<T> {\n const policies = this.config.cache.policies;\n\n variables = {\n ...getDefaultValues(getQueryDefinition(query)),\n ...variables!,\n };\n\n const rootRef = makeReference(rootId);\n const execResult = this.executeSelectionSet({\n selectionSet: getMainDefinition(query).selectionSet,\n objectOrReference: rootRef,\n enclosingRef: rootRef,\n context: {\n store,\n query,\n policies,\n variables,\n varString: canonicalStringify(variables),\n canonizeResults,\n ...extractFragmentContext(query, this.config.fragments),\n },\n });\n\n let missing: MissingFieldError[] | undefined;\n if (execResult.missing) {\n // For backwards compatibility we still report an array of\n // MissingFieldError objects, even though there will only ever be at most\n // one of them, now that all missing field error messages are grouped\n // together in the execResult.missing tree.\n missing = [\n new MissingFieldError(\n firstMissing(execResult.missing)!,\n execResult.missing,\n query,\n variables\n ),\n ];\n if (!returnPartialData) {\n throw missing[0];\n }\n }\n\n return {\n result: execResult.result,\n complete: !missing,\n missing,\n };\n }\n\n public isFresh(\n result: Record<string, any>,\n parent: StoreObject | Reference,\n selectionSet: SelectionSetNode,\n context: ReadMergeModifyContext\n ): boolean {\n if (\n supportsResultCaching(context.store) &&\n this.knownResults.get(result) === selectionSet\n ) {\n const latest = this.executeSelectionSet.peek(\n selectionSet,\n parent,\n context,\n // If result is canonical, then it could only have been previously\n // cached by the canonizing version of executeSelectionSet, so we can\n // avoid checking both possibilities here.\n this.canon.isKnown(result)\n );\n if (latest && result === latest.result) {\n return true;\n }\n }\n return false;\n }\n\n // Uncached version of executeSelectionSet.\n private execSelectionSetImpl({\n selectionSet,\n objectOrReference,\n enclosingRef,\n context,\n }: ExecSelectionSetOptions): ExecResult {\n if (\n isReference(objectOrReference) &&\n !context.policies.rootTypenamesById[objectOrReference.__ref] &&\n !context.store.has(objectOrReference.__ref)\n ) {\n return {\n result: this.canon.empty,\n missing: `Dangling reference to missing ${objectOrReference.__ref} object`,\n };\n }\n\n const { variables, policies, store } = context;\n const typename = store.getFieldValue<string>(\n objectOrReference,\n \"__typename\"\n );\n\n const objectsToMerge: Record<string, any>[] = [];\n let missing: MissingTree | undefined;\n const missingMerger = new DeepMerger();\n\n if (\n this.config.addTypename &&\n typeof typename === \"string\" &&\n !policies.rootIdsByTypename[typename]\n ) {\n // Ensure we always include a default value for the __typename\n // field, if we have one, and this.config.addTypename is true. Note\n // that this field can be overridden by other merged objects.\n objectsToMerge.push({ __typename: typename });\n }\n\n function handleMissing<T>(result: ExecResult<T>, resultName: string): T {\n if (result.missing) {\n missing = missingMerger.merge(missing, {\n [resultName]: result.missing,\n });\n }\n return result.result;\n }\n\n const workSet = new Set(selectionSet.selections);\n\n workSet.forEach((selection) => {\n // Omit fields with directives @skip(if: <truthy value>) or\n // @include(if: <falsy value>).\n if (!shouldInclude(selection, variables)) return;\n\n if (isField(selection)) {\n let fieldValue = policies.readField(\n {\n fieldName: selection.name.value,\n field: selection,\n variables: context.variables,\n from: objectOrReference,\n },\n context\n );\n\n const resultName = resultKeyNameFromField(selection);\n\n if (fieldValue === void 0) {\n if (!addTypenameToDocument.added(selection)) {\n missing = missingMerger.merge(missing, {\n [resultName]: `Can't find field '${selection.name.value}' on ${\n isReference(objectOrReference) ?\n objectOrReference.__ref + \" object\"\n : \"object \" + JSON.stringify(objectOrReference, null, 2)\n }`,\n });\n }\n } else if (isArray(fieldValue)) {\n if (fieldValue.length > 0) {\n fieldValue = handleMissing(\n this.executeSubSelectedArray({\n field: selection,\n array: fieldValue,\n enclosingRef,\n context,\n }),\n resultName\n );\n }\n } else if (!selection.selectionSet) {\n // If the field does not have a selection set, then we handle it\n // as a scalar value. To keep this.canon from canonicalizing\n // this value, we use this.canon.pass to wrap fieldValue in a\n // Pass object that this.canon.admit will later unwrap as-is.\n if (context.canonizeResults) {\n fieldValue = this.canon.pass(fieldValue);\n }\n } else if (fieldValue != null) {\n // In this case, because we know the field has a selection set,\n // it must be trying to query a GraphQLObjectType, which is why\n // fieldValue must be != null.\n fieldValue = handleMissing(\n this.executeSelectionSet({\n selectionSet: selection.selectionSet,\n objectOrReference: fieldValue as StoreObject | Reference,\n enclosingRef: isReference(fieldValue) ? fieldValue : enclosingRef,\n context,\n }),\n resultName\n );\n }\n\n if (fieldValue !== void 0) {\n objectsToMerge.push({ [resultName]: fieldValue });\n }\n } else {\n const fragment = getFragmentFromSelection(\n selection,\n context.lookupFragment\n );\n\n if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {\n throw newInvariantError(`No fragment named %s`, selection.name.value);\n }\n\n if (fragment && policies.fragmentMatches(fragment, typename)) {\n fragment.selectionSet.selections.forEach(workSet.add, workSet);\n }\n }\n });\n\n const result = mergeDeepArray(objectsToMerge);\n const finalResult: ExecResult = { result, missing };\n const frozen =\n context.canonizeResults ?\n this.canon.admit(finalResult)\n // Since this.canon is normally responsible for freezing results (only in\n // development), freeze them manually if canonization is disabled.\n : maybeDeepFreeze(finalResult);\n\n // Store this result with its selection set so that we can quickly\n // recognize it again in the StoreReader#isFresh method.\n if (frozen.result) {\n this.knownResults.set(frozen.result, selectionSet);\n }\n\n return frozen;\n }\n\n // Uncached version of executeSubSelectedArray.\n private execSubSelectedArrayImpl({\n field,\n array,\n enclosingRef,\n context,\n }: ExecSubSelectedArrayOptions): ExecResult {\n let missing: MissingTree | undefined;\n let missingMerger = new DeepMerger<MissingTree[]>();\n\n function handleMissing<T>(childResult: ExecResult<T>, i: number): T {\n if (childResult.missing) {\n missing = missingMerger.merge(missing, { [i]: childResult.missing });\n }\n return childResult.result;\n }\n\n if (field.selectionSet) {\n array = array.filter(context.store.canRead);\n }\n\n array = array.map((item, i) => {\n // null value in array\n if (item === null) {\n return null;\n }\n\n // This is a nested array, recurse\n if (isArray(item)) {\n return handleMissing(\n this.executeSubSelectedArray({\n field,\n array: item,\n enclosingRef,\n context,\n }),\n i\n );\n }\n\n // This is an object, run the selection set on it\n if (field.selectionSet) {\n return handleMissing(\n this.executeSelectionSet({\n selectionSet: field.selectionSet,\n objectOrReference: item,\n enclosingRef: isReference(item) ? item : enclosingRef,\n context,\n }),\n i\n );\n }\n\n if (__DEV__) {\n assertSelectionSetForIdValue(context.store, field, item);\n }\n\n return item;\n });\n\n return {\n result: context.canonizeResults ? this.canon.admit(array) : array,\n missing,\n };\n }\n}\n\nfunction firstMissing(tree: MissingTree): string | undefined {\n try {\n JSON.stringify(tree, (_, value) => {\n if (typeof value === \"string\") throw value;\n return value;\n });\n } catch (result) {\n return result as string;\n }\n}\n\nfunction assertSelectionSetForIdValue(\n store: NormalizedCache,\n field: FieldNode,\n fieldValue: any\n) {\n if (!field.selectionSet) {\n const workSet = new Set([fieldValue]);\n workSet.forEach((value) => {\n if (isNonNullObject(value)) {\n invariant(\n !isReference(value),\n `Missing selection set for object of type %s returned for query field %s`,\n getTypenameFromStoreObject(store, value),\n field.name.value\n );\n Object.values(value).forEach(workSet.add, workSet);\n }\n });\n }\n}\n"]}
|
|
@@ -89,6 +89,16 @@ export type DiffQueryAgainstStoreOptions = ReadQueryOptions & {
|
|
|
89
89
|
};
|
|
90
90
|
export type ApolloReducerConfig = {
|
|
91
91
|
dataIdFromObject?: KeyFieldsFunction;
|
|
92
|
+
/**
|
|
93
|
+
* @defaultValue true
|
|
94
|
+
*
|
|
95
|
+
* @deprecated `addTypename` will be removed in Apollo Client 4.0.
|
|
96
|
+
*
|
|
97
|
+
* **Recommended now**
|
|
98
|
+
*
|
|
99
|
+
* Please set `addTypename` to `true` or remove the option entirely to use the
|
|
100
|
+
* default.
|
|
101
|
+
*/
|
|
92
102
|
addTypename?: boolean;
|
|
93
103
|
};
|
|
94
104
|
export interface InMemoryCacheConfig extends ApolloReducerConfig {
|
|
@@ -101,10 +111,11 @@ export interface InMemoryCacheConfig extends ApolloReducerConfig {
|
|
|
101
111
|
*/
|
|
102
112
|
resultCacheMaxSize?: number;
|
|
103
113
|
/**
|
|
114
|
+
* Whether to canonize cache results before returning them. Canonization takes some extra time, but it speeds up future deep equality comparisons. Defaults to false.
|
|
115
|
+
*
|
|
104
116
|
* @deprecated
|
|
105
|
-
*
|
|
106
|
-
* recommend using this option
|
|
107
|
-
* A future version of Apollo Client will contain a similar feature.
|
|
117
|
+
*
|
|
118
|
+
* Using `canonizeResults` can result in memory leaks so we generally do not recommend using this option. `canonizeResults` will be removed in Apollo Client 4.0.
|
|
108
119
|
*/
|
|
109
120
|
canonizeResults?: boolean;
|
|
110
121
|
fragments?: FragmentRegistryAPI;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/cache/inmemory/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentNode, FieldNode } from \"graphql\";\n\nimport type { Transaction } from \"../core/cache.js\";\nimport type {\n StoreObject,\n StoreValue,\n Reference,\n} from \"../../utilities/index.js\";\nimport type { FieldValueGetter } from \"./entityStore.js\";\nimport type {\n TypePolicies,\n PossibleTypesMap,\n KeyFieldsFunction,\n StorageType,\n FieldMergeFunction,\n} from \"./policies.js\";\nimport type {\n Modifiers,\n ToReferenceFunction,\n CanReadFunction,\n AllFieldsModifier,\n} from \"../core/types/common.js\";\n\nimport type { FragmentRegistryAPI } from \"./fragmentRegistry.js\";\n\nexport type { StoreObject, StoreValue, Reference };\n\nexport interface IdGetterObj extends Object {\n __typename?: string;\n id?: string;\n _id?: string;\n}\n\nexport declare type IdGetter = (value: IdGetterObj) => string | undefined;\n\n/**\n * This is an interface used to access, set and remove\n * StoreObjects from the cache\n */\nexport interface NormalizedCache {\n has(dataId: string): boolean;\n get(dataId: string, fieldName: string): StoreValue;\n\n // The store.merge method allows either argument to be a string ID, but\n // the other argument has to be a StoreObject. Either way, newer fields\n // always take precedence over older fields.\n merge(olderId: string, newerObject: StoreObject): void;\n merge(olderObject: StoreObject, newerId: string): void;\n\n modify<Entity extends Record<string, any>>(\n dataId: string,\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>\n ): boolean;\n delete(dataId: string, fieldName?: string): boolean;\n clear(): void;\n\n // non-Map elements:\n /**\n * returns an Object with key-value pairs matching the contents of the store\n */\n toObject(): NormalizedCacheObject;\n /**\n * replace the state of the store\n */\n replace(newData: NormalizedCacheObject): void;\n\n /**\n * Retain (or release) a given root ID to protect (or expose) it and its\n * transitive child entities from (or to) garbage collection. The current\n * retainment count is returned by both methods. Note that releasing a root\n * ID does not cause that entity to be garbage collected, but merely removes\n * it from the set of root IDs that will be considered during the next\n * mark-and-sweep collection.\n */\n retain(rootId: string): number;\n release(rootId: string): number;\n\n getFieldValue: FieldValueGetter;\n toReference: ToReferenceFunction;\n canRead: CanReadFunction;\n\n getStorage(\n idOrObj: string | StoreObject,\n ...storeFieldNames: (string | number)[]\n ): StorageType;\n}\n\n/**\n * This is a normalized representation of the Apollo query result cache. It consists of\n * a flattened representation of query result trees.\n */\nexport interface NormalizedCacheObject {\n __META?: {\n // Well-known singleton IDs like ROOT_QUERY and ROOT_MUTATION are\n // always considered to be root IDs during cache.gc garbage\n // collection, but other IDs can become roots if they are written\n // directly with cache.writeFragment or retained explicitly with\n // cache.retain. When such IDs exist, we include them in the __META\n // section so that they can survive cache.{extract,restore}.\n extraRootIds: string[];\n };\n [dataId: string]: StoreObject | undefined;\n}\n\nexport type OptimisticStoreItem = {\n id: string;\n data: NormalizedCacheObject;\n transaction: Transaction<NormalizedCacheObject>;\n};\n\nexport type ReadQueryOptions = {\n /**\n * The Apollo Client store object.\n */\n store: NormalizedCache;\n /**\n * A parsed GraphQL query document.\n */\n query: DocumentNode;\n variables?: Object;\n previousResult?: any;\n /**\n * @deprecated\n * Using `canonizeResults` can result in memory leaks so we generally do not\n * recommend using this option anymore.\n * A future version of Apollo Client will contain a similar feature without\n * the risk of memory leaks.\n */\n canonizeResults?: boolean;\n rootId?: string;\n config?: ApolloReducerConfig;\n};\n\nexport type DiffQueryAgainstStoreOptions = ReadQueryOptions & {\n returnPartialData?: boolean;\n};\n\nexport type ApolloReducerConfig = {\n dataIdFromObject?: KeyFieldsFunction;\n addTypename?: boolean;\n};\n\nexport interface InMemoryCacheConfig extends ApolloReducerConfig {\n resultCaching?: boolean;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n /**\n * @deprecated\n * Please use `cacheSizes` instead.\n */\n resultCacheMaxSize?: number;\n
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/cache/inmemory/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentNode, FieldNode } from \"graphql\";\n\nimport type { Transaction } from \"../core/cache.js\";\nimport type {\n StoreObject,\n StoreValue,\n Reference,\n} from \"../../utilities/index.js\";\nimport type { FieldValueGetter } from \"./entityStore.js\";\nimport type {\n TypePolicies,\n PossibleTypesMap,\n KeyFieldsFunction,\n StorageType,\n FieldMergeFunction,\n} from \"./policies.js\";\nimport type {\n Modifiers,\n ToReferenceFunction,\n CanReadFunction,\n AllFieldsModifier,\n} from \"../core/types/common.js\";\n\nimport type { FragmentRegistryAPI } from \"./fragmentRegistry.js\";\n\nexport type { StoreObject, StoreValue, Reference };\n\nexport interface IdGetterObj extends Object {\n __typename?: string;\n id?: string;\n _id?: string;\n}\n\nexport declare type IdGetter = (value: IdGetterObj) => string | undefined;\n\n/**\n * This is an interface used to access, set and remove\n * StoreObjects from the cache\n */\nexport interface NormalizedCache {\n has(dataId: string): boolean;\n get(dataId: string, fieldName: string): StoreValue;\n\n // The store.merge method allows either argument to be a string ID, but\n // the other argument has to be a StoreObject. Either way, newer fields\n // always take precedence over older fields.\n merge(olderId: string, newerObject: StoreObject): void;\n merge(olderObject: StoreObject, newerId: string): void;\n\n modify<Entity extends Record<string, any>>(\n dataId: string,\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>\n ): boolean;\n delete(dataId: string, fieldName?: string): boolean;\n clear(): void;\n\n // non-Map elements:\n /**\n * returns an Object with key-value pairs matching the contents of the store\n */\n toObject(): NormalizedCacheObject;\n /**\n * replace the state of the store\n */\n replace(newData: NormalizedCacheObject): void;\n\n /**\n * Retain (or release) a given root ID to protect (or expose) it and its\n * transitive child entities from (or to) garbage collection. The current\n * retainment count is returned by both methods. Note that releasing a root\n * ID does not cause that entity to be garbage collected, but merely removes\n * it from the set of root IDs that will be considered during the next\n * mark-and-sweep collection.\n */\n retain(rootId: string): number;\n release(rootId: string): number;\n\n getFieldValue: FieldValueGetter;\n toReference: ToReferenceFunction;\n canRead: CanReadFunction;\n\n getStorage(\n idOrObj: string | StoreObject,\n ...storeFieldNames: (string | number)[]\n ): StorageType;\n}\n\n/**\n * This is a normalized representation of the Apollo query result cache. It consists of\n * a flattened representation of query result trees.\n */\nexport interface NormalizedCacheObject {\n __META?: {\n // Well-known singleton IDs like ROOT_QUERY and ROOT_MUTATION are\n // always considered to be root IDs during cache.gc garbage\n // collection, but other IDs can become roots if they are written\n // directly with cache.writeFragment or retained explicitly with\n // cache.retain. When such IDs exist, we include them in the __META\n // section so that they can survive cache.{extract,restore}.\n extraRootIds: string[];\n };\n [dataId: string]: StoreObject | undefined;\n}\n\nexport type OptimisticStoreItem = {\n id: string;\n data: NormalizedCacheObject;\n transaction: Transaction<NormalizedCacheObject>;\n};\n\nexport type ReadQueryOptions = {\n /**\n * The Apollo Client store object.\n */\n store: NormalizedCache;\n /**\n * A parsed GraphQL query document.\n */\n query: DocumentNode;\n variables?: Object;\n previousResult?: any;\n /**\n * @deprecated\n * Using `canonizeResults` can result in memory leaks so we generally do not\n * recommend using this option anymore.\n * A future version of Apollo Client will contain a similar feature without\n * the risk of memory leaks.\n */\n canonizeResults?: boolean;\n rootId?: string;\n config?: ApolloReducerConfig;\n};\n\nexport type DiffQueryAgainstStoreOptions = ReadQueryOptions & {\n returnPartialData?: boolean;\n};\n\nexport type ApolloReducerConfig = {\n dataIdFromObject?: KeyFieldsFunction;\n /**\n * @defaultValue true\n *\n * @deprecated `addTypename` will be removed in Apollo Client 4.0.\n *\n * **Recommended now**\n *\n * Please set `addTypename` to `true` or remove the option entirely to use the\n * default.\n */\n addTypename?: boolean;\n};\n\nexport interface InMemoryCacheConfig extends ApolloReducerConfig {\n resultCaching?: boolean;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n /**\n * @deprecated\n * Please use `cacheSizes` instead.\n */\n resultCacheMaxSize?: number;\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#canonizeResults:member} */\n canonizeResults?: boolean;\n fragments?: FragmentRegistryAPI;\n}\n\nexport interface MergeInfo {\n field: FieldNode;\n typename: string | undefined;\n merge: FieldMergeFunction;\n}\n\nexport interface MergeTree {\n info?: MergeInfo;\n map: Map<string | number, MergeTree>;\n}\n\nexport interface ReadMergeModifyContext {\n store: NormalizedCache;\n variables?: Record<string, any>;\n // A JSON.stringify-serialized version of context.variables.\n varString?: string;\n}\n"]}
|
package/core/ApolloClient.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { ObservableQuery } from "./ObservableQuery.js";
|
|
|
9
9
|
import type { ApolloQueryResult, DefaultContext, OperationVariables, Resolvers, RefetchQueriesOptions, RefetchQueriesResult, RefetchQueriesInclude } from "./types.js";
|
|
10
10
|
import type { QueryOptions, WatchQueryOptions, MutationOptions, SubscriptionOptions } from "./watchQueryOptions.js";
|
|
11
11
|
import type { FragmentMatcher } from "./LocalState.js";
|
|
12
|
+
import { LocalState } from "./LocalState.js";
|
|
12
13
|
export interface DefaultOptions {
|
|
13
14
|
watchQuery?: Partial<WatchQueryOptions<any, any>>;
|
|
14
15
|
query?: Partial<QueryOptions<any, any>>;
|
|
@@ -33,13 +34,56 @@ export interface ApolloClientOptions<TCacheShape> {
|
|
|
33
34
|
* The URI of the GraphQL endpoint that Apollo Client will communicate with.
|
|
34
35
|
*
|
|
35
36
|
* One of `uri` or `link` is **required**. If you provide both, `link` takes precedence.
|
|
37
|
+
*
|
|
38
|
+
* @deprecated `uri` will be removed in Apollo Client 4.0.
|
|
39
|
+
*
|
|
40
|
+
* **Recommended now**
|
|
41
|
+
*
|
|
42
|
+
* Instantiate an instance of `HttpClient` and pass `uri` as an option.
|
|
43
|
+
*
|
|
44
|
+
* ```js
|
|
45
|
+
* import { HttpLink } from "@apollo/client";
|
|
46
|
+
*
|
|
47
|
+
* new ApolloClient({
|
|
48
|
+
* link: new HttpLink({ uri })
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
36
51
|
*/
|
|
37
52
|
uri?: string | UriFunction;
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated `credentials` will be removed in Apollo Client 4.0.
|
|
55
|
+
*
|
|
56
|
+
* **Recommended now**
|
|
57
|
+
*
|
|
58
|
+
* Instantiate an instance of `HttpClient` and pass `credentials` as an option.
|
|
59
|
+
*
|
|
60
|
+
* ```js
|
|
61
|
+
* import { HttpLink } from "@apollo/client";
|
|
62
|
+
*
|
|
63
|
+
* new ApolloClient({
|
|
64
|
+
* link: new HttpLink({ credentials })
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
38
68
|
credentials?: string;
|
|
39
69
|
/**
|
|
40
70
|
* An object representing headers to include in every HTTP request, such as `{Authorization: 'Bearer 1234'}`
|
|
41
71
|
*
|
|
42
72
|
* This value will be ignored when using the `link` option.
|
|
73
|
+
*
|
|
74
|
+
* @deprecated `headers` will be removed in Apollo Client 4.0.
|
|
75
|
+
*
|
|
76
|
+
* **Recommended now**
|
|
77
|
+
*
|
|
78
|
+
* Instantiate an instance of `HttpClient` and pass `headers` as an option.
|
|
79
|
+
*
|
|
80
|
+
* ```js
|
|
81
|
+
* import { HttpLink } from "@apollo/client";
|
|
82
|
+
*
|
|
83
|
+
* new ApolloClient({
|
|
84
|
+
* link: new HttpLink({ headers })
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
43
87
|
*/
|
|
44
88
|
headers?: Record<string, string>;
|
|
45
89
|
/**
|
|
@@ -70,7 +114,18 @@ export interface ApolloClientOptions<TCacheShape> {
|
|
|
70
114
|
* If `true`, the [Apollo Client Devtools](https://www.apollographql.com/docs/react/development-testing/developer-tooling/#apollo-client-devtools) browser extension can connect to Apollo Client.
|
|
71
115
|
*
|
|
72
116
|
* The default value is `false` in production and `true` in development (if there is a `window` object).
|
|
73
|
-
*
|
|
117
|
+
*
|
|
118
|
+
* @deprecated `connectToDevTools` will be removed in Apollo Client 4.0.
|
|
119
|
+
*
|
|
120
|
+
* **Recommended now**
|
|
121
|
+
*
|
|
122
|
+
* Use the `devtools.enabled` option instead.
|
|
123
|
+
*
|
|
124
|
+
* ```ts
|
|
125
|
+
* new ApolloClient({
|
|
126
|
+
* devtools: { enabled: true }
|
|
127
|
+
* });
|
|
128
|
+
* ```
|
|
74
129
|
*/
|
|
75
130
|
connectToDevTools?: boolean;
|
|
76
131
|
/**
|
|
@@ -92,19 +147,86 @@ export interface ApolloClientOptions<TCacheShape> {
|
|
|
92
147
|
* @defaultValue `false`
|
|
93
148
|
*/
|
|
94
149
|
assumeImmutableResults?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* @deprecated `resolvers` has been moved in Apollo Client 4.0. This option is
|
|
152
|
+
* safe to use in Apollo Client 3.x.
|
|
153
|
+
*
|
|
154
|
+
* **Recommended now**
|
|
155
|
+
*
|
|
156
|
+
* No action needed
|
|
157
|
+
*
|
|
158
|
+
* **When upgrading**
|
|
159
|
+
*
|
|
160
|
+
* `resolvers` will need to be passed as the `resolvers` option to an instance
|
|
161
|
+
* of `LocalState`. That `LocalState` instance should be provided as the
|
|
162
|
+
* `localState` option to the `ApolloClient` constructor.
|
|
163
|
+
*/
|
|
95
164
|
resolvers?: Resolvers | Resolvers[];
|
|
165
|
+
/**
|
|
166
|
+
* @deprecated `typeDefs` will be removed in Apollo Client 4.0. It is safe to
|
|
167
|
+
* stop using this option in Apollo Client 3.x.
|
|
168
|
+
*/
|
|
96
169
|
typeDefs?: string | string[] | DocumentNode | DocumentNode[];
|
|
170
|
+
/**
|
|
171
|
+
* @deprecated Custom fragment matchers will no longer be supported in Apollo
|
|
172
|
+
* Client 4.0 and has been replaced by `cache.fragmentMatches`. It is safe to
|
|
173
|
+
* continue using this in Apollo Client 3.x.
|
|
174
|
+
*
|
|
175
|
+
* **Recommended now**
|
|
176
|
+
*
|
|
177
|
+
* No action needed
|
|
178
|
+
*
|
|
179
|
+
* **When upgrading**
|
|
180
|
+
*
|
|
181
|
+
* Leverage `possibleTypes` with `InMemoryCache` to ensure fragments match
|
|
182
|
+
* correctly. Ensure `possibleTypes` include local types if needed. This
|
|
183
|
+
* option should then be removed. If working with a 3rd party cache
|
|
184
|
+
* implementation, ensure the 3rd party cache implements the
|
|
185
|
+
* `cache.fragmentMatches` method.
|
|
186
|
+
*/
|
|
97
187
|
fragmentMatcher?: FragmentMatcher;
|
|
98
188
|
/**
|
|
99
189
|
* A custom name (e.g., `iOS`) that identifies this particular client among your set of clients. Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.
|
|
190
|
+
*
|
|
191
|
+
* @deprecated `name` has been moved to `clientAwareness.name` in Apollo Client 4.0.
|
|
192
|
+
*
|
|
193
|
+
* **Recommended now**
|
|
194
|
+
*
|
|
195
|
+
* Use `clientAwareness.name` to set the client awareness name.
|
|
196
|
+
*
|
|
197
|
+
* ```ts
|
|
198
|
+
* new ApolloClient({ clientAwareness: { name } });
|
|
199
|
+
* ```
|
|
100
200
|
*/
|
|
101
201
|
name?: string;
|
|
102
202
|
/**
|
|
103
203
|
* A custom version that identifies the current version of this particular client (e.g., `1.2`). Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.
|
|
104
204
|
*
|
|
105
205
|
* This is **not** the version of Apollo Client that you are using, but rather any version string that helps you differentiate between versions of your client.
|
|
206
|
+
*
|
|
207
|
+
* @deprecated `name` has been moved to `clientAwareness.version` in Apollo Client 4.0.
|
|
208
|
+
*
|
|
209
|
+
* **Recommended now**
|
|
210
|
+
*
|
|
211
|
+
* Use `clientAwareness.version` to set the client awareness version.
|
|
212
|
+
*
|
|
213
|
+
* ```ts
|
|
214
|
+
* new ApolloClient({ clientAwareness: { version } });
|
|
215
|
+
* ```
|
|
106
216
|
*/
|
|
107
217
|
version?: string;
|
|
218
|
+
clientAwareness?: {
|
|
219
|
+
/**
|
|
220
|
+
* A custom name (e.g., `iOS`) that identifies this particular client among your set of clients. Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.
|
|
221
|
+
*/
|
|
222
|
+
name?: string;
|
|
223
|
+
/**
|
|
224
|
+
* A custom version that identifies the current version of this particular client (e.g., `1.2`). Apollo Server and Apollo Studio use this property as part of the [client awareness](https://www.apollographql.com/docs/apollo-server/monitoring/metrics#identifying-distinct-clients) feature.
|
|
225
|
+
*
|
|
226
|
+
* This is **not** the version of Apollo Client that you are using, but rather any version string that helps you differentiate between versions of your client.
|
|
227
|
+
*/
|
|
228
|
+
version?: string;
|
|
229
|
+
};
|
|
108
230
|
documentTransform?: DocumentTransform;
|
|
109
231
|
/**
|
|
110
232
|
* Configuration used by the [Apollo Client Devtools extension](https://www.apollographql.com/docs/react/development-testing/developer-tooling/#apollo-client-devtools) for this client.
|
|
@@ -133,6 +255,14 @@ export { mergeOptions };
|
|
|
133
255
|
export declare class ApolloClient<TCacheShape> implements DataProxy {
|
|
134
256
|
link: ApolloLink;
|
|
135
257
|
cache: ApolloCache<TCacheShape>;
|
|
258
|
+
/**
|
|
259
|
+
* @deprecated `disableNetworkFetches` has been renamed to `prioritizeCacheValues`
|
|
260
|
+
* in Apollo Client 4.0.
|
|
261
|
+
*
|
|
262
|
+
* **Recommended now**
|
|
263
|
+
*
|
|
264
|
+
* Access `client.prioritizeCacheValues` instead.
|
|
265
|
+
*/
|
|
136
266
|
disableNetworkFetches: boolean;
|
|
137
267
|
version: string;
|
|
138
268
|
queryDeduplication: boolean;
|
|
@@ -143,7 +273,16 @@ export declare class ApolloClient<TCacheShape> implements DataProxy {
|
|
|
143
273
|
private devToolsHookCb?;
|
|
144
274
|
private resetStoreCallbacks;
|
|
145
275
|
private clearStoreCallbacks;
|
|
146
|
-
|
|
276
|
+
localState: LocalState<TCacheShape>;
|
|
277
|
+
/**
|
|
278
|
+
* Whether to prioritize cache values over network results when `query` or `watchQuery` is called.
|
|
279
|
+
* This will essentially turn a `"network-only"` or `"cache-and-network"` fetchPolicy into a `"cache-first"` fetchPolicy,
|
|
280
|
+
* but without influencing the `fetchPolicy` of the created `ObservableQuery` long-term.
|
|
281
|
+
*
|
|
282
|
+
* This can e.g. be used to prioritize the cache during the first render after SSR.
|
|
283
|
+
*/
|
|
284
|
+
get prioritizeCacheValues(): boolean;
|
|
285
|
+
set prioritizeCacheValues(value: boolean);
|
|
147
286
|
/**
|
|
148
287
|
* Constructs an instance of `ApolloClient`.
|
|
149
288
|
*
|
|
@@ -374,18 +513,68 @@ export declare class ApolloClient<TCacheShape> implements DataProxy {
|
|
|
374
513
|
restore(serializedState: TCacheShape): ApolloCache<TCacheShape>;
|
|
375
514
|
/**
|
|
376
515
|
* Add additional local resolvers.
|
|
516
|
+
*
|
|
517
|
+
* @deprecated `addResolvers` will been removed in Apollo Client 4.0. It is
|
|
518
|
+
* safe to continue using this method in Apollo Client 3.x.
|
|
519
|
+
*
|
|
520
|
+
* **Recommended now**
|
|
521
|
+
*
|
|
522
|
+
* No action needed
|
|
523
|
+
*
|
|
524
|
+
* **When upgrading**
|
|
525
|
+
*
|
|
526
|
+
* Use `client.localState.addResolvers(resolvers)`. Alternatively, store
|
|
527
|
+
* the `LocalState` instance in a separate variable and call `addResolvers` on
|
|
528
|
+
* that.
|
|
377
529
|
*/
|
|
378
530
|
addResolvers(resolvers: Resolvers | Resolvers[]): void;
|
|
379
531
|
/**
|
|
380
532
|
* Set (override existing) local resolvers.
|
|
533
|
+
*
|
|
534
|
+
* @deprecated `setResolvers` will been removed in Apollo Client 4.0. It is
|
|
535
|
+
* safe to continue using this method in Apollo Client 3.x.
|
|
536
|
+
*
|
|
537
|
+
* **Recommended now**
|
|
538
|
+
*
|
|
539
|
+
* If possible, stop using the `setResolvers` method.
|
|
540
|
+
*
|
|
541
|
+
* **When upgrading**
|
|
542
|
+
*
|
|
543
|
+
* Remove the use of `setResolvers`.
|
|
381
544
|
*/
|
|
382
545
|
setResolvers(resolvers: Resolvers | Resolvers[]): void;
|
|
383
546
|
/**
|
|
384
547
|
* Get all registered local resolvers.
|
|
548
|
+
*
|
|
549
|
+
* @deprecated `getResolvers` will be removed in Apollo Client 4.0. It is
|
|
550
|
+
* safe to continue using this method in Apollo Client 3.x.
|
|
551
|
+
*
|
|
552
|
+
* **Recommended now**
|
|
553
|
+
*
|
|
554
|
+
* If possible, stop using the `getResolvers` method.
|
|
555
|
+
*
|
|
556
|
+
* **When upgrading**
|
|
557
|
+
*
|
|
558
|
+
* Remove the use of `getResolvers`.
|
|
385
559
|
*/
|
|
386
560
|
getResolvers(): Resolvers;
|
|
387
561
|
/**
|
|
388
562
|
* Set a custom local state fragment matcher.
|
|
563
|
+
*
|
|
564
|
+
* @deprecated Custom fragment matchers will no longer be supported in Apollo
|
|
565
|
+
* Client 4.0 and has been replaced by `cache.fragmentMatches`. It is safe to
|
|
566
|
+
* continue using `setLocalStateFragmentMatcher` in Apollo Client 3.x.
|
|
567
|
+
*
|
|
568
|
+
* **Recommended now**
|
|
569
|
+
*
|
|
570
|
+
* No action needed
|
|
571
|
+
*
|
|
572
|
+
* **When upgrading**
|
|
573
|
+
*
|
|
574
|
+
* Leverage `possibleTypes` with `InMemoryCache` to ensure fragments match
|
|
575
|
+
* correctly. Ensure `possibleTypes` include local types if needed. If working
|
|
576
|
+
* with a 3rd party cache implementation, ensure the 3rd party cache implements
|
|
577
|
+
* the `cache.fragmentMatches` method. This function should no longer be used.
|
|
389
578
|
*/
|
|
390
579
|
setLocalStateFragmentMatcher(fragmentMatcher: FragmentMatcher): void;
|
|
391
580
|
/**
|
package/core/ApolloClient.js
CHANGED
|
@@ -12,6 +12,7 @@ var hasSuggestedDevtools = false;
|
|
|
12
12
|
// solution is to reexport mergeOptions where it was previously declared (here).
|
|
13
13
|
import { mergeOptions } from "../utilities/index.js";
|
|
14
14
|
import { getApolloClientMemoryInternals } from "../utilities/caching/getMemoryInternals.js";
|
|
15
|
+
import { warnRemovedOption } from "../utilities/deprecation/index.js";
|
|
15
16
|
export { mergeOptions };
|
|
16
17
|
/**
|
|
17
18
|
* This is the primary Apollo Client class. It is used to send GraphQL documents (i.e. queries
|
|
@@ -48,17 +49,29 @@ var ApolloClient = /** @class */ (function () {
|
|
|
48
49
|
*/
|
|
49
50
|
function ApolloClient(options) {
|
|
50
51
|
var _this = this;
|
|
51
|
-
var _a;
|
|
52
|
+
var _a, _b, _c;
|
|
52
53
|
this.resetStoreCallbacks = [];
|
|
53
54
|
this.clearStoreCallbacks = [];
|
|
54
55
|
if (!options.cache) {
|
|
55
56
|
throw newInvariantError(16);
|
|
56
57
|
}
|
|
57
|
-
var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, documentTransform = options.documentTransform,
|
|
58
|
+
var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, documentTransform = options.documentTransform, _d = options.ssrMode, ssrMode = _d === void 0 ? false : _d, _e = options.ssrForceFetchDelay, ssrForceFetchDelay = _e === void 0 ? 0 : _e,
|
|
58
59
|
// Expose the client instance as window.__APOLLO_CLIENT__ and call
|
|
59
60
|
// onBroadcast in queryManager.broadcastQueries to enable browser
|
|
60
61
|
// devtools, but disable them by default in production.
|
|
61
|
-
connectToDevTools = options.connectToDevTools,
|
|
62
|
+
connectToDevTools = options.connectToDevTools, _f = options.queryDeduplication, queryDeduplication = _f === void 0 ? true : _f, defaultOptions = options.defaultOptions, defaultContext = options.defaultContext, _g = options.assumeImmutableResults, assumeImmutableResults = _g === void 0 ? cache.assumeImmutableResults : _g, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwareness = options.clientAwareness, clientAwarenessName = options.name, clientAwarenessVersion = options.version, devtools = options.devtools, dataMasking = options.dataMasking;
|
|
63
|
+
if (globalThis.__DEV__ !== false) {
|
|
64
|
+
warnRemovedOption(options, "connectToDevTools", "ApolloClient", "Please use `devtools.enabled` instead.");
|
|
65
|
+
warnRemovedOption(options, "uri", "ApolloClient", "Please initialize an instance of `HttpLink` with `uri` instead.");
|
|
66
|
+
warnRemovedOption(options, "credentials", "ApolloClient", "Please initialize an instance of `HttpLink` with `credentials` instead.");
|
|
67
|
+
warnRemovedOption(options, "headers", "ApolloClient", "Please initialize an instance of `HttpLink` with `headers` instead.");
|
|
68
|
+
warnRemovedOption(options, "name", "ApolloClient", "Please use the `clientAwareness.name` option instead.");
|
|
69
|
+
warnRemovedOption(options, "version", "ApolloClient", "Please use the `clientAwareness.version` option instead.");
|
|
70
|
+
warnRemovedOption(options, "typeDefs", "ApolloClient");
|
|
71
|
+
if (!options.link) {
|
|
72
|
+
globalThis.__DEV__ !== false && invariant.warn(17);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
62
75
|
var link = options.link;
|
|
63
76
|
if (!link) {
|
|
64
77
|
link =
|
|
@@ -100,8 +113,8 @@ var ApolloClient = /** @class */ (function () {
|
|
|
100
113
|
ssrMode: ssrMode,
|
|
101
114
|
dataMasking: !!dataMasking,
|
|
102
115
|
clientAwareness: {
|
|
103
|
-
name: clientAwarenessName,
|
|
104
|
-
version: clientAwarenessVersion,
|
|
116
|
+
name: (_b = clientAwareness === null || clientAwareness === void 0 ? void 0 : clientAwareness.name) !== null && _b !== void 0 ? _b : clientAwarenessName,
|
|
117
|
+
version: (_c = clientAwareness === null || clientAwareness === void 0 ? void 0 : clientAwareness.version) !== null && _c !== void 0 ? _c : clientAwarenessVersion,
|
|
105
118
|
},
|
|
106
119
|
localState: this.localState,
|
|
107
120
|
assumeImmutableResults: assumeImmutableResults,
|
|
@@ -123,6 +136,23 @@ var ApolloClient = /** @class */ (function () {
|
|
|
123
136
|
if (this.devtoolsConfig.enabled)
|
|
124
137
|
this.connectToDevTools();
|
|
125
138
|
}
|
|
139
|
+
Object.defineProperty(ApolloClient.prototype, "prioritizeCacheValues", {
|
|
140
|
+
/**
|
|
141
|
+
* Whether to prioritize cache values over network results when `query` or `watchQuery` is called.
|
|
142
|
+
* This will essentially turn a `"network-only"` or `"cache-and-network"` fetchPolicy into a `"cache-first"` fetchPolicy,
|
|
143
|
+
* but without influencing the `fetchPolicy` of the created `ObservableQuery` long-term.
|
|
144
|
+
*
|
|
145
|
+
* This can e.g. be used to prioritize the cache during the first render after SSR.
|
|
146
|
+
*/
|
|
147
|
+
get: function () {
|
|
148
|
+
return this.disableNetworkFetches;
|
|
149
|
+
},
|
|
150
|
+
set: function (value) {
|
|
151
|
+
this.disableNetworkFetches = value;
|
|
152
|
+
},
|
|
153
|
+
enumerable: false,
|
|
154
|
+
configurable: true
|
|
155
|
+
});
|
|
126
156
|
ApolloClient.prototype.connectToDevTools = function () {
|
|
127
157
|
if (typeof window === "undefined") {
|
|
128
158
|
return;
|
|
@@ -213,6 +243,9 @@ var ApolloClient = /** @class */ (function () {
|
|
|
213
243
|
options.fetchPolicy === "cache-and-network")) {
|
|
214
244
|
options = __assign(__assign({}, options), { fetchPolicy: "cache-first" });
|
|
215
245
|
}
|
|
246
|
+
if (globalThis.__DEV__ !== false) {
|
|
247
|
+
warnRemovedOption(options, "canonizeResults", "client.watchQuery");
|
|
248
|
+
}
|
|
216
249
|
return this.queryManager.watchQuery(options);
|
|
217
250
|
};
|
|
218
251
|
/**
|
|
@@ -228,10 +261,13 @@ var ApolloClient = /** @class */ (function () {
|
|
|
228
261
|
if (this.defaultOptions.query) {
|
|
229
262
|
options = mergeOptions(this.defaultOptions.query, options);
|
|
230
263
|
}
|
|
231
|
-
invariant(options.fetchPolicy !== "cache-and-network",
|
|
264
|
+
invariant(options.fetchPolicy !== "cache-and-network", 18);
|
|
232
265
|
if (this.disableNetworkFetches && options.fetchPolicy === "network-only") {
|
|
233
266
|
options = __assign(__assign({}, options), { fetchPolicy: "cache-first" });
|
|
234
267
|
}
|
|
268
|
+
if (globalThis.__DEV__ !== false) {
|
|
269
|
+
warnRemovedOption(options, "canonizeResults", "client.query");
|
|
270
|
+
}
|
|
235
271
|
return this.queryManager.query(options);
|
|
236
272
|
};
|
|
237
273
|
/**
|
|
@@ -459,7 +495,7 @@ var ApolloClient = /** @class */ (function () {
|
|
|
459
495
|
// result.queries and result.results instead, you shouldn't have to worry
|
|
460
496
|
// about preventing uncaught rejections for the Promise.all result.
|
|
461
497
|
result.catch(function (error) {
|
|
462
|
-
globalThis.__DEV__ !== false && invariant.debug(
|
|
498
|
+
globalThis.__DEV__ !== false && invariant.debug(19, error);
|
|
463
499
|
});
|
|
464
500
|
return result;
|
|
465
501
|
};
|
|
@@ -496,24 +532,74 @@ var ApolloClient = /** @class */ (function () {
|
|
|
496
532
|
};
|
|
497
533
|
/**
|
|
498
534
|
* Add additional local resolvers.
|
|
535
|
+
*
|
|
536
|
+
* @deprecated `addResolvers` will been removed in Apollo Client 4.0. It is
|
|
537
|
+
* safe to continue using this method in Apollo Client 3.x.
|
|
538
|
+
*
|
|
539
|
+
* **Recommended now**
|
|
540
|
+
*
|
|
541
|
+
* No action needed
|
|
542
|
+
*
|
|
543
|
+
* **When upgrading**
|
|
544
|
+
*
|
|
545
|
+
* Use `client.localState.addResolvers(resolvers)`. Alternatively, store
|
|
546
|
+
* the `LocalState` instance in a separate variable and call `addResolvers` on
|
|
547
|
+
* that.
|
|
499
548
|
*/
|
|
500
549
|
ApolloClient.prototype.addResolvers = function (resolvers) {
|
|
501
550
|
this.localState.addResolvers(resolvers);
|
|
502
551
|
};
|
|
503
552
|
/**
|
|
504
553
|
* Set (override existing) local resolvers.
|
|
554
|
+
*
|
|
555
|
+
* @deprecated `setResolvers` will been removed in Apollo Client 4.0. It is
|
|
556
|
+
* safe to continue using this method in Apollo Client 3.x.
|
|
557
|
+
*
|
|
558
|
+
* **Recommended now**
|
|
559
|
+
*
|
|
560
|
+
* If possible, stop using the `setResolvers` method.
|
|
561
|
+
*
|
|
562
|
+
* **When upgrading**
|
|
563
|
+
*
|
|
564
|
+
* Remove the use of `setResolvers`.
|
|
505
565
|
*/
|
|
506
566
|
ApolloClient.prototype.setResolvers = function (resolvers) {
|
|
507
567
|
this.localState.setResolvers(resolvers);
|
|
508
568
|
};
|
|
509
569
|
/**
|
|
510
570
|
* Get all registered local resolvers.
|
|
571
|
+
*
|
|
572
|
+
* @deprecated `getResolvers` will be removed in Apollo Client 4.0. It is
|
|
573
|
+
* safe to continue using this method in Apollo Client 3.x.
|
|
574
|
+
*
|
|
575
|
+
* **Recommended now**
|
|
576
|
+
*
|
|
577
|
+
* If possible, stop using the `getResolvers` method.
|
|
578
|
+
*
|
|
579
|
+
* **When upgrading**
|
|
580
|
+
*
|
|
581
|
+
* Remove the use of `getResolvers`.
|
|
511
582
|
*/
|
|
512
583
|
ApolloClient.prototype.getResolvers = function () {
|
|
513
584
|
return this.localState.getResolvers();
|
|
514
585
|
};
|
|
515
586
|
/**
|
|
516
587
|
* Set a custom local state fragment matcher.
|
|
588
|
+
*
|
|
589
|
+
* @deprecated Custom fragment matchers will no longer be supported in Apollo
|
|
590
|
+
* Client 4.0 and has been replaced by `cache.fragmentMatches`. It is safe to
|
|
591
|
+
* continue using `setLocalStateFragmentMatcher` in Apollo Client 3.x.
|
|
592
|
+
*
|
|
593
|
+
* **Recommended now**
|
|
594
|
+
*
|
|
595
|
+
* No action needed
|
|
596
|
+
*
|
|
597
|
+
* **When upgrading**
|
|
598
|
+
*
|
|
599
|
+
* Leverage `possibleTypes` with `InMemoryCache` to ensure fragments match
|
|
600
|
+
* correctly. Ensure `possibleTypes` include local types if needed. If working
|
|
601
|
+
* with a 3rd party cache implementation, ensure the 3rd party cache implements
|
|
602
|
+
* the `cache.fragmentMatches` method. This function should no longer be used.
|
|
517
603
|
*/
|
|
518
604
|
ApolloClient.prototype.setLocalStateFragmentMatcher = function (fragmentMatcher) {
|
|
519
605
|
this.localState.setFragmentMatcher(fragmentMatcher);
|