@apollo/client 4.4.0-alpha.0 → 4.4.0-alpha.1
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/CHANGELOG.md +39 -0
- package/__cjs/cache/core/cache.cjs +50 -15
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +22 -4
- package/__cjs/cache/index.cjs.map +1 -1
- package/__cjs/cache/index.d.cts +1 -1
- package/__cjs/cache/inmemory/entityStore.cjs +4 -4
- package/__cjs/cache/inmemory/helpers.cjs +12 -0
- package/__cjs/cache/inmemory/helpers.cjs.map +1 -1
- package/__cjs/cache/inmemory/helpers.d.cts +10 -5
- package/__cjs/cache/inmemory/inMemoryCache.cjs +13 -2
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +19 -4
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +7 -7
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/readFromStore.cjs +86 -31
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/types.d.cts +11 -2
- package/__cjs/cache/inmemory/writeToStore.cjs +27 -24
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/writeToStore.d.cts +5 -4
- package/__cjs/core/ApolloClient.cjs +19 -15
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +1 -0
- package/__cjs/core/ObservableQuery.cjs +8 -8
- package/__cjs/core/QueryInfo.cjs +1 -1
- package/__cjs/core/QueryManager.cjs +12 -12
- package/__cjs/core/RefetchEventManager.cjs +3 -3
- package/__cjs/errors/CombinedGraphQLErrors.cjs +3 -7
- package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedGraphQLErrors.d.cts +2 -2
- package/__cjs/errors/CombinedProtocolErrors.cjs +3 -8
- package/__cjs/errors/CombinedProtocolErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedProtocolErrors.d.cts +2 -2
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +2 -2
- package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
- package/__cjs/invariantErrorCodes.cjs +125 -120
- package/__cjs/link/core/ApolloLink.cjs +3 -3
- package/__cjs/link/http/checkFetcher.cjs +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
- package/__cjs/link/persisted-queries/index.cjs +2 -2
- package/__cjs/link/ws/index.cjs +1 -1
- package/__cjs/local-state/LocalState.cjs +23 -22
- package/__cjs/local-state/LocalState.cjs.map +1 -1
- package/__cjs/masking/maskDefinition.cjs +20 -2
- package/__cjs/masking/maskDefinition.cjs.map +1 -1
- package/__cjs/masking/maskFragment.cjs +2 -2
- package/__cjs/masking/maskOperation.cjs +1 -1
- package/__cjs/masking/utils.cjs +3 -3
- package/__cjs/react/context/ApolloContext.cjs +1 -1
- package/__cjs/react/context/ApolloProvider.cjs +1 -1
- package/__cjs/react/hooks/internal/validateSuspenseHookOptions.cjs +2 -2
- package/__cjs/react/hooks/useApolloClient.cjs +1 -1
- package/__cjs/react/hooks/useFragment.cjs +8 -2
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
- package/__cjs/react/hooks/useLoadableQuery.cjs +2 -2
- package/__cjs/react/hooks/useSubscription.cjs +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.cjs +10 -4
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
- package/__cjs/react/internal/cache/FragmentReference.cjs +2 -2
- package/__cjs/react/internal/cache/FragmentReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/FragmentReference.d.cts +4 -5
- package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
- package/__cjs/react/internal/cache/SuspenseCache.cjs +3 -3
- package/__cjs/react/internal/cache/SuspenseCache.cjs.map +1 -1
- package/__cjs/react/internal/cache/SuspenseCache.d.cts +4 -5
- package/__cjs/react/internal/cache/types.d.cts +0 -5
- package/__cjs/react/ssr/prerenderStatic.cjs +2 -2
- package/__cjs/testing/core/mocking/mockLink.cjs +4 -4
- package/__cjs/utilities/graphql/DocumentTransform.cjs +1 -1
- package/__cjs/utilities/internal/DeepMerger.cjs +6 -2
- package/__cjs/utilities/internal/DeepMerger.cjs.map +1 -1
- package/__cjs/utilities/internal/DeepMerger.d.cts +13 -3
- package/__cjs/utilities/internal/constants.cjs +33 -1
- package/__cjs/utilities/internal/constants.cjs.map +1 -1
- package/__cjs/utilities/internal/constants.d.cts +32 -0
- package/__cjs/utilities/internal/createArgumentNode.cjs +14 -0
- package/__cjs/utilities/internal/createArgumentNode.cjs.map +1 -0
- package/__cjs/utilities/internal/createArgumentNode.d.cts +3 -0
- package/__cjs/utilities/internal/createDirectiveNode.cjs +14 -0
- package/__cjs/utilities/internal/createDirectiveNode.cjs.map +1 -0
- package/__cjs/utilities/internal/createDirectiveNode.d.cts +3 -0
- package/__cjs/utilities/internal/createFragmentSpreadNode.cjs +4 -1
- package/__cjs/utilities/internal/createFragmentSpreadNode.cjs.map +1 -1
- package/__cjs/utilities/internal/createFragmentSpreadNode.d.cts +3 -2
- package/__cjs/utilities/internal/createValueNode.cjs +27 -0
- package/__cjs/utilities/internal/createValueNode.cjs.map +1 -0
- package/__cjs/utilities/internal/createValueNode.d.cts +12 -0
- package/__cjs/utilities/internal/equalByQuery.cjs +8 -8
- package/__cjs/utilities/internal/equalByQuery.cjs.map +1 -1
- package/__cjs/utilities/internal/equalByQuery.d.cts +2 -3
- package/__cjs/utilities/internal/getFragmentDefinition.cjs +3 -3
- package/__cjs/utilities/internal/getFragmentDefinition.cjs.map +1 -1
- package/__cjs/utilities/internal/getFragmentFromSelection.cjs +1 -1
- package/__cjs/utilities/internal/getFragmentQueryDocument.cjs +10 -2
- package/__cjs/utilities/internal/getFragmentQueryDocument.cjs.map +1 -1
- package/__cjs/utilities/internal/getFragmentScope.cjs +23 -0
- package/__cjs/utilities/internal/getFragmentScope.cjs.map +1 -0
- package/__cjs/utilities/internal/getFragmentScope.d.cts +13 -0
- package/__cjs/utilities/internal/getFragmentVariables.cjs +14 -15
- package/__cjs/utilities/internal/getFragmentVariables.cjs.map +1 -1
- package/__cjs/utilities/internal/getFragmentVariables.d.cts +8 -4
- package/__cjs/utilities/internal/getMainDefinition.cjs +1 -1
- package/__cjs/utilities/internal/getQueryDefinition.cjs +1 -1
- package/__cjs/utilities/internal/index.cjs +9 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +5 -1
- package/__cjs/utilities/internal/isNonEmptyObject.cjs +13 -0
- package/__cjs/utilities/internal/isNonEmptyObject.cjs.map +1 -0
- package/__cjs/utilities/internal/isNonEmptyObject.d.cts +7 -0
- package/__cjs/utilities/internal/isNonNullObject.cjs.map +1 -1
- package/__cjs/utilities/internal/isNonNullObject.d.cts +1 -1
- package/__cjs/utilities/internal/mapObservableFragment.cjs +14 -9
- package/__cjs/utilities/internal/mapObservableFragment.cjs.map +1 -1
- package/__cjs/utilities/internal/mapObservableFragment.d.cts +5 -1
- package/__cjs/utilities/internal/mergeDeepArray.cjs +2 -2
- package/__cjs/utilities/internal/mergeDeepArray.cjs.map +1 -1
- package/__cjs/utilities/internal/mergeDeepArray.d.cts +2 -1
- package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +1 -1
- package/__cjs/utilities/internal/removeFragmentSpreads.cjs +55 -2
- package/__cjs/utilities/internal/removeFragmentSpreads.cjs.map +1 -1
- package/__cjs/utilities/internal/removeFragmentSpreads.d.cts +17 -1
- package/__cjs/utilities/internal/shouldInclude.cjs +4 -4
- package/__cjs/utilities/internal/types/FragmentInfo.cjs +3 -0
- package/__cjs/utilities/internal/types/FragmentInfo.cjs.map +1 -0
- package/__cjs/utilities/internal/types/FragmentInfo.d.cts +14 -0
- package/__cjs/utilities/internal/types/ObjectWithFragmentInfo.cjs +3 -0
- package/__cjs/utilities/internal/types/ObjectWithFragmentInfo.cjs.map +1 -0
- package/__cjs/utilities/internal/types/ObjectWithFragmentInfo.d.cts +13 -0
- package/__cjs/utilities/internal/valueToObjectRepresentation.cjs +1 -1
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +22 -4
- package/cache/core/cache.js +51 -16
- package/cache/core/cache.js.map +1 -1
- package/cache/index.d.ts +1 -1
- package/cache/index.js.map +1 -1
- package/cache/inmemory/entityStore.js +4 -4
- package/cache/inmemory/helpers.d.ts +10 -5
- package/cache/inmemory/helpers.js +12 -1
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +19 -4
- package/cache/inmemory/inMemoryCache.js +14 -3
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.js +7 -7
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.js +89 -34
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +11 -2
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +5 -4
- package/cache/inmemory/writeToStore.js +30 -27
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts +1 -0
- package/core/ApolloClient.js +20 -16
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.js +8 -8
- package/core/QueryInfo.js +1 -1
- package/core/QueryManager.js +12 -12
- package/core/RefetchEventManager.js +3 -3
- package/errors/CombinedGraphQLErrors.d.ts +2 -2
- package/errors/CombinedGraphQLErrors.js +3 -7
- package/errors/CombinedGraphQLErrors.js.map +1 -1
- package/errors/CombinedProtocolErrors.d.ts +2 -2
- package/errors/CombinedProtocolErrors.js +3 -8
- package/errors/CombinedProtocolErrors.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.js +2 -2
- package/incremental/handlers/notImplemented.js +1 -1
- package/invariantErrorCodes.js +125 -120
- package/link/core/ApolloLink.js +3 -3
- package/link/http/checkFetcher.js +1 -1
- package/link/http/parseAndCheckHttpResponse.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/ws/index.js +1 -1
- package/local-state/LocalState.js +24 -23
- package/local-state/LocalState.js.map +1 -1
- package/masking/maskDefinition.js +21 -3
- package/masking/maskDefinition.js.map +1 -1
- package/masking/maskFragment.js +2 -2
- package/masking/maskOperation.js +1 -1
- package/masking/utils.js +3 -3
- package/package.json +1 -1
- package/react/context/ApolloContext.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/hooks/internal/validateSuspenseHookOptions.js +2 -2
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useFragment.js +8 -2
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.js +2 -2
- package/react/hooks/useLoadableQuery.js +2 -2
- package/react/hooks/useSubscription.js +1 -1
- package/react/hooks/useSuspenseFragment.js +10 -4
- package/react/hooks/useSuspenseFragment.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/hooks-compiled/internal/validateSuspenseHookOptions.js +2 -2
- package/react/hooks-compiled/useApolloClient.js +1 -1
- package/react/hooks-compiled/useFragment.js +56 -32
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.js +2 -2
- package/react/hooks-compiled/useLoadableQuery.js +2 -2
- package/react/hooks-compiled/useSubscription.js +1 -1
- package/react/hooks-compiled/useSuspenseFragment.js +10 -4
- package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
- package/react/hooks-compiled/useSyncExternalStore.js +1 -1
- package/react/internal/cache/FragmentReference.d.ts +4 -5
- package/react/internal/cache/FragmentReference.js +2 -2
- package/react/internal/cache/FragmentReference.js.map +1 -1
- package/react/internal/cache/QueryReference.js +1 -1
- package/react/internal/cache/SuspenseCache.d.ts +4 -5
- package/react/internal/cache/SuspenseCache.js +3 -3
- package/react/internal/cache/SuspenseCache.js.map +1 -1
- package/react/internal/cache/types.d.ts +0 -5
- package/react/internal/cache/types.js.map +1 -1
- package/react/ssr/prerenderStatic.js +2 -2
- package/testing/core/mocking/mockLink.js +4 -4
- package/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/internal/DeepMerger.d.ts +13 -3
- package/utilities/internal/DeepMerger.js +6 -2
- package/utilities/internal/DeepMerger.js.map +1 -1
- package/utilities/internal/constants.d.ts +32 -0
- package/utilities/internal/constants.js +32 -0
- package/utilities/internal/constants.js.map +1 -1
- package/utilities/internal/createArgumentNode.d.ts +3 -0
- package/utilities/internal/createArgumentNode.js +11 -0
- package/utilities/internal/createArgumentNode.js.map +1 -0
- package/utilities/internal/createDirectiveNode.d.ts +3 -0
- package/utilities/internal/createDirectiveNode.js +11 -0
- package/utilities/internal/createDirectiveNode.js.map +1 -0
- package/utilities/internal/createFragmentSpreadNode.d.ts +3 -2
- package/utilities/internal/createFragmentSpreadNode.js +4 -1
- package/utilities/internal/createFragmentSpreadNode.js.map +1 -1
- package/utilities/internal/createValueNode.d.ts +12 -0
- package/utilities/internal/createValueNode.js +24 -0
- package/utilities/internal/createValueNode.js.map +1 -0
- package/utilities/internal/equalByQuery.d.ts +2 -3
- package/utilities/internal/equalByQuery.js +8 -8
- package/utilities/internal/equalByQuery.js.map +1 -1
- package/utilities/internal/getFragmentDefinition.js +3 -3
- package/utilities/internal/getFragmentDefinition.js.map +1 -1
- package/utilities/internal/getFragmentFromSelection.js +1 -1
- package/utilities/internal/getFragmentQueryDocument.js +10 -2
- package/utilities/internal/getFragmentQueryDocument.js.map +1 -1
- package/utilities/internal/getFragmentScope.d.ts +13 -0
- package/utilities/internal/getFragmentScope.js +20 -0
- package/utilities/internal/getFragmentScope.js.map +1 -0
- package/utilities/internal/getFragmentVariables.d.ts +9 -5
- package/utilities/internal/getFragmentVariables.js +15 -16
- package/utilities/internal/getFragmentVariables.js.map +1 -1
- package/utilities/internal/getMainDefinition.js +1 -1
- package/utilities/internal/getQueryDefinition.js +1 -1
- package/utilities/internal/index.d.ts +5 -1
- package/utilities/internal/index.js +3 -1
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/isNonEmptyObject.d.ts +7 -0
- package/utilities/internal/isNonEmptyObject.js +10 -0
- package/utilities/internal/isNonEmptyObject.js.map +1 -0
- package/utilities/internal/isNonNullObject.d.ts +1 -1
- package/utilities/internal/isNonNullObject.js.map +1 -1
- package/utilities/internal/mapObservableFragment.d.ts +5 -1
- package/utilities/internal/mapObservableFragment.js +14 -9
- package/utilities/internal/mapObservableFragment.js.map +1 -1
- package/utilities/internal/mergeDeepArray.d.ts +2 -1
- package/utilities/internal/mergeDeepArray.js +2 -2
- package/utilities/internal/mergeDeepArray.js.map +1 -1
- package/utilities/internal/removeDirectivesFromDocument.js +1 -1
- package/utilities/internal/removeFragmentSpreads.d.ts +18 -2
- package/utilities/internal/removeFragmentSpreads.js +56 -3
- package/utilities/internal/removeFragmentSpreads.js.map +1 -1
- package/utilities/internal/shouldInclude.js +4 -4
- package/utilities/internal/types/FragmentInfo.d.ts +14 -0
- package/utilities/internal/types/FragmentInfo.js +2 -0
- package/utilities/internal/types/FragmentInfo.js.map +1 -0
- package/utilities/internal/types/ObjectWithFragmentInfo.d.ts +13 -0
- package/utilities/internal/types/ObjectWithFragmentInfo.js +2 -0
- package/utilities/internal/types/ObjectWithFragmentInfo.js.map +1 -0
- package/utilities/internal/valueToObjectRepresentation.js +1 -1
- package/version.js +1 -1
|
@@ -131,13 +131,22 @@ export interface MergeTree {
|
|
|
131
131
|
export interface ReadMergeModifyContext {
|
|
132
132
|
store: NormalizedCache;
|
|
133
133
|
variables?: OperationVariables;
|
|
134
|
-
|
|
134
|
+
variablesScope?: OperationVariables;
|
|
135
|
+
varString?: VarString;
|
|
135
136
|
extensions?: ExtensionsWithStreamInfo;
|
|
136
137
|
isDeferPending?: (path: Incremental.Path, label: string | undefined) => boolean;
|
|
137
|
-
operationVariables?: OperationVariables;
|
|
138
138
|
}
|
|
139
139
|
type ListOf<T extends string> = `[${T}]`;
|
|
140
140
|
type NestedScalarName<T extends string> = T | ListOf<T> | ListOf<ListOf<T>> | ListOf<ListOf<ListOf<T>>> | ListOf<ListOf<ListOf<ListOf<T>>>>;
|
|
141
141
|
export type KnownScalars = RemoveIndexSignature<ApolloCache.Scalars>;
|
|
142
142
|
export type ScalarType = NestedScalarName<keyof KnownScalars & string> | (string extends keyof ApolloCache.Scalars ? string & {} : never);
|
|
143
|
+
declare const varStringBrand: unique symbol;
|
|
144
|
+
/**
|
|
145
|
+
* @internal
|
|
146
|
+
*
|
|
147
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
148
|
+
*/
|
|
149
|
+
export type VarString = string & {
|
|
150
|
+
readonly [varStringBrand]: true;
|
|
151
|
+
};
|
|
143
152
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -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 { OperationVariables } from \"@apollo/client\";\nimport type { Incremental } from \"@apollo/client/incremental\";\nimport type {\n Reference,\n StoreObject,\n StoreValue,\n} from \"@apollo/client/utilities\";\nimport type {\n ExtensionsWithStreamInfo,\n handleIncrementalSymbol,\n RemoveIndexSignature,\n StreamInfoTrie,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { ApolloCache, Transaction } from \"../core/cache.js\";\nimport type {\n AllFieldsModifier,\n CanReadFunction,\n Modifiers,\n ToReferenceFunction,\n} from \"../core/types/common.js\";\n\nimport type { FieldValueGetter } from \"./entityStore.js\";\nimport type { FragmentRegistryAPI } from \"./fragmentRegistry.js\";\nimport type { InMemoryCache } from \"./inMemoryCache.js\";\nimport type {\n FieldMergeFunction,\n KeyFieldsFunction,\n PossibleTypesMap,\n StorageType,\n TypePolicies,\n} from \"./policies.js\";\n\nexport type { Reference, StoreObject, StoreValue };\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 exact: boolean\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;\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 rootId?: string;\n config?: ApolloReducerConfig;\n};\n\n/** @internal */\nexport interface DiffIncrementalInfo {\n streamInfo?: StreamInfoTrie;\n isDeferPending?: (\n path: Incremental.Path,\n label: string | undefined\n ) => boolean;\n}\n\nexport interface WithHandleIncremental {\n [handleIncrementalSymbol]?: DiffIncrementalInfo | undefined;\n}\n\nexport type DiffQueryAgainstStoreOptions = ReadQueryOptions & {\n returnPartialData?: boolean;\n};\n\nexport type ApolloReducerConfig = {\n dataIdFromObject?: KeyFieldsFunction;\n};\n\nexport interface InputObjectConfig {\n fields: Record<string, string>;\n}\n\nexport interface InputObjectsOption {\n [inputObjectName: string]: InputObjectConfig;\n}\n\nexport type InMemoryCacheConfig = ApolloReducerConfig & {\n resultCaching?: boolean;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n fragments?: FragmentRegistryAPI;\n inputObjects?: InputObjectsOption;\n} & ({} extends InMemoryCache.ScalarsOption ?\n InMemoryCache.ScalarsOption extends Record<string, never> ?\n {\n scalars?: Record<\n string,\n `Scalar types must be declared in ApolloCache.Scalars before usage. See https://www.apollographql.com/docs/react/data/typescript#declaring-scalar-types.`\n >;\n }\n : { scalars?: InMemoryCache.ScalarsOption }\n : { scalars: InMemoryCache.ScalarsOption });\n\nexport interface MergeInfo {\n field: FieldNode;\n typename: string | undefined;\n merge: FieldMergeFunction;\n path: Array<string | number>;\n variables: OperationVariables | undefined;\n}\n\nexport interface MergeTree {\n info?: MergeInfo;\n map: Map<string | number, MergeTree>;\n}\n\nexport interface ReadMergeModifyContext {\n store: NormalizedCache;\n variables?: OperationVariables;\n // A
|
|
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 { OperationVariables } from \"@apollo/client\";\nimport type { Incremental } from \"@apollo/client/incremental\";\nimport type {\n Reference,\n StoreObject,\n StoreValue,\n} from \"@apollo/client/utilities\";\nimport type {\n ExtensionsWithStreamInfo,\n handleIncrementalSymbol,\n RemoveIndexSignature,\n StreamInfoTrie,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { ApolloCache, Transaction } from \"../core/cache.js\";\nimport type {\n AllFieldsModifier,\n CanReadFunction,\n Modifiers,\n ToReferenceFunction,\n} from \"../core/types/common.js\";\n\nimport type { FieldValueGetter } from \"./entityStore.js\";\nimport type { FragmentRegistryAPI } from \"./fragmentRegistry.js\";\nimport type { InMemoryCache } from \"./inMemoryCache.js\";\nimport type {\n FieldMergeFunction,\n KeyFieldsFunction,\n PossibleTypesMap,\n StorageType,\n TypePolicies,\n} from \"./policies.js\";\n\nexport type { Reference, StoreObject, StoreValue };\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 exact: boolean\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;\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 rootId?: string;\n config?: ApolloReducerConfig;\n};\n\n/** @internal */\nexport interface DiffIncrementalInfo {\n streamInfo?: StreamInfoTrie;\n isDeferPending?: (\n path: Incremental.Path,\n label: string | undefined\n ) => boolean;\n}\n\nexport interface WithHandleIncremental {\n [handleIncrementalSymbol]?: DiffIncrementalInfo | undefined;\n}\n\nexport type DiffQueryAgainstStoreOptions = ReadQueryOptions & {\n returnPartialData?: boolean;\n};\n\nexport type ApolloReducerConfig = {\n dataIdFromObject?: KeyFieldsFunction;\n};\n\nexport interface InputObjectConfig {\n fields: Record<string, string>;\n}\n\nexport interface InputObjectsOption {\n [inputObjectName: string]: InputObjectConfig;\n}\n\nexport type InMemoryCacheConfig = ApolloReducerConfig & {\n resultCaching?: boolean;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n fragments?: FragmentRegistryAPI;\n inputObjects?: InputObjectsOption;\n} & ({} extends InMemoryCache.ScalarsOption ?\n InMemoryCache.ScalarsOption extends Record<string, never> ?\n {\n scalars?: Record<\n string,\n `Scalar types must be declared in ApolloCache.Scalars before usage. See https://www.apollographql.com/docs/react/data/typescript#declaring-scalar-types.`\n >;\n }\n : { scalars?: InMemoryCache.ScalarsOption }\n : { scalars: InMemoryCache.ScalarsOption });\n\nexport interface MergeInfo {\n field: FieldNode;\n typename: string | undefined;\n merge: FieldMergeFunction;\n path: Array<string | number>;\n variables: OperationVariables | undefined;\n}\n\nexport interface MergeTree {\n info?: MergeInfo;\n map: Map<string | number, MergeTree>;\n}\n\nexport interface ReadMergeModifyContext {\n store: NormalizedCache;\n // The operation variables.\n variables?: OperationVariables;\n // The variables in scope for the current selection set. This is the same as\n // variables except in fragments that have arguments.\n variablesScope?: OperationVariables;\n // A serialized version of variablesScope and variables.\n varString?: VarString;\n extensions?: ExtensionsWithStreamInfo;\n isDeferPending?: (\n path: Incremental.Path,\n label: string | undefined\n ) => boolean;\n}\n\ntype ListOf<T extends string> = `[${T}]`;\n\ntype NestedScalarName<T extends string> =\n | T\n | ListOf<T>\n | ListOf<ListOf<T>>\n | ListOf<ListOf<ListOf<T>>>\n | ListOf<ListOf<ListOf<ListOf<T>>>>;\n\nexport type KnownScalars = RemoveIndexSignature<ApolloCache.Scalars>;\n\nexport type ScalarType =\n | NestedScalarName<keyof KnownScalars & string>\n | (string extends keyof ApolloCache.Scalars ? string & {} : never);\n\ndeclare const varStringBrand: unique symbol;\n\n/** @internal */\nexport type VarString = string & { readonly [varStringBrand]: true };\n"]}
|
|
@@ -2,15 +2,15 @@ import type { FieldNode, SelectionSetNode } from "graphql";
|
|
|
2
2
|
import type { Cache, OperationVariables } from "@apollo/client";
|
|
3
3
|
import type { Reference, StoreObject } from "@apollo/client/utilities";
|
|
4
4
|
import type { FragmentMap, FragmentMapFunction } from "@apollo/client/utilities/internal";
|
|
5
|
-
import { handleIncrementalSymbol } from "@apollo/client/utilities/internal";
|
|
5
|
+
import { handleIncrementalSymbol, rootFragmentVariablesSymbol } from "@apollo/client/utilities/internal";
|
|
6
6
|
import type { InMemoryCache } from "./inMemoryCache.js";
|
|
7
7
|
import type { StoreReader } from "./readFromStore.js";
|
|
8
|
-
import type { DiffIncrementalInfo, InMemoryCacheConfig, MergeTree, NormalizedCache, ReadMergeModifyContext } from "./types.js";
|
|
8
|
+
import type { DiffIncrementalInfo, InMemoryCacheConfig, MergeTree, NormalizedCache, ReadMergeModifyContext, VarString } from "./types.js";
|
|
9
9
|
export interface WriteContext extends ReadMergeModifyContext {
|
|
10
10
|
readonly written: {
|
|
11
11
|
[dataId: string]: Array<{
|
|
12
12
|
selectionSet: SelectionSetNode;
|
|
13
|
-
varString:
|
|
13
|
+
varString: VarString | undefined;
|
|
14
14
|
}>;
|
|
15
15
|
};
|
|
16
16
|
readonly fragmentMap: FragmentMap;
|
|
@@ -32,8 +32,9 @@ export declare class StoreWriter {
|
|
|
32
32
|
private reader?;
|
|
33
33
|
private fragments?;
|
|
34
34
|
constructor(cache: InMemoryCache, reader?: StoreReader | undefined, fragments?: InMemoryCacheConfig["fragments"]);
|
|
35
|
-
writeToStore<TData = unknown, TVariables extends OperationVariables = OperationVariables>(store: NormalizedCache, { query, result, dataId, variables, overwrite, extensions, [handleIncrementalSymbol]: incrementalInfo, }: Cache.WriteOptions<TData, TVariables> & {
|
|
35
|
+
writeToStore<TData = unknown, TVariables extends OperationVariables = OperationVariables>(store: NormalizedCache, { query, result, dataId, variables, overwrite, extensions, [handleIncrementalSymbol]: incrementalInfo, [rootFragmentVariablesSymbol]: rootFragmentVariables, }: Cache.WriteOptions<TData, TVariables> & {
|
|
36
36
|
[handleIncrementalSymbol]?: DiffIncrementalInfo;
|
|
37
|
+
[rootFragmentVariablesSymbol]?: OperationVariables;
|
|
37
38
|
}): Reference | undefined;
|
|
38
39
|
private processSelectionSet;
|
|
39
40
|
private processFieldValue;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { equal } from "@wry/equality";
|
|
2
2
|
import { Trie } from "@wry/trie";
|
|
3
3
|
import { Kind } from "graphql";
|
|
4
|
-
import { addTypenameToDocument,
|
|
4
|
+
import { addTypenameToDocument, isReference } from "@apollo/client/utilities";
|
|
5
5
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
6
|
-
import { argumentsObjectFromField, cloneDeep, getDefaultValues, getFragmentFromSelection,
|
|
6
|
+
import { argumentsObjectFromField, cloneDeep, getDefaultValues, getFragmentFromSelection, getFragmentScope, getOperationDefinition, handleIncrementalSymbol, isArray, isField, isNonEmptyArray, isStreamField, makeReference, resultKeyNameFromField, rootFragmentVariablesSymbol, shouldInclude, streamInfoSymbol, } from "@apollo/client/utilities/internal";
|
|
7
7
|
import { invariant, newInvariantError, } from "@apollo/client/utilities/invariant";
|
|
8
|
-
import { extractFragmentContext, fieldNameFromStoreName, makeProcessedFieldsMerger, storeValueIsStoreObject, } from "./helpers.js";
|
|
8
|
+
import { extractFragmentContext, fieldNameFromStoreName, makeProcessedFieldsMerger, makeVarString, storeValueIsStoreObject, } from "./helpers.js";
|
|
9
9
|
import { defaultStreamFieldMergeFn, normalizeReadFieldOptions, } from "./policies.js";
|
|
10
10
|
// Since there are only four possible combinations of context.clientOnly and
|
|
11
11
|
// context.deferred values, we should need at most four "flavors" of any given
|
|
@@ -37,7 +37,7 @@ export class StoreWriter {
|
|
|
37
37
|
this.reader = reader;
|
|
38
38
|
this.fragments = fragments;
|
|
39
39
|
}
|
|
40
|
-
writeToStore(store, { query, result, dataId, variables, overwrite, extensions, [handleIncrementalSymbol]: incrementalInfo, }) {
|
|
40
|
+
writeToStore(store, { query, result, dataId, variables, overwrite, extensions, [handleIncrementalSymbol]: incrementalInfo, [rootFragmentVariablesSymbol]: rootFragmentVariables, }) {
|
|
41
41
|
const operationDefinition = getOperationDefinition(query);
|
|
42
42
|
const merger = makeProcessedFieldsMerger();
|
|
43
43
|
variables = {
|
|
@@ -50,9 +50,9 @@ export class StoreWriter {
|
|
|
50
50
|
merge(existing, incoming) {
|
|
51
51
|
return merger.merge(existing, incoming);
|
|
52
52
|
},
|
|
53
|
-
variables
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
variables,
|
|
54
|
+
variablesScope: rootFragmentVariables ?? variables,
|
|
55
|
+
varString: makeVarString({ variables, scope: rootFragmentVariables }),
|
|
56
56
|
...extractFragmentContext(query, this.fragments),
|
|
57
57
|
overwrite: !!overwrite,
|
|
58
58
|
incomingById: new Map(),
|
|
@@ -71,7 +71,7 @@ export class StoreWriter {
|
|
|
71
71
|
path: [],
|
|
72
72
|
});
|
|
73
73
|
if (!isReference(ref)) {
|
|
74
|
-
throw newInvariantError(
|
|
74
|
+
throw newInvariantError(125, result);
|
|
75
75
|
}
|
|
76
76
|
// So far, the store has not been modified, so now it's time to process
|
|
77
77
|
// context.incomingById and merge those incoming fields into context.store.
|
|
@@ -149,7 +149,7 @@ export class StoreWriter {
|
|
|
149
149
|
// need to be extracted from a child object that processSelectionSet has
|
|
150
150
|
// turned into a Reference.
|
|
151
151
|
const readField = (...args) => {
|
|
152
|
-
const options = normalizeReadFieldOptions(args, incoming, context.
|
|
152
|
+
const options = normalizeReadFieldOptions(args, incoming, context.variablesScope);
|
|
153
153
|
if (isReference(options.from)) {
|
|
154
154
|
const info = context.incomingById.get(options.from.__ref);
|
|
155
155
|
if (info) {
|
|
@@ -179,7 +179,7 @@ export class StoreWriter {
|
|
|
179
179
|
typename,
|
|
180
180
|
fieldName: field.name.value,
|
|
181
181
|
field,
|
|
182
|
-
variables: context.
|
|
182
|
+
variables: context.variablesScope,
|
|
183
183
|
});
|
|
184
184
|
const childTree = getChildMergeTree(mergeTree, storeFieldName);
|
|
185
185
|
let incomingValue = this.processFieldValue(value, field,
|
|
@@ -211,18 +211,18 @@ export class StoreWriter {
|
|
|
211
211
|
typename,
|
|
212
212
|
merge,
|
|
213
213
|
path,
|
|
214
|
-
variables: context.
|
|
214
|
+
variables: context.variablesScope,
|
|
215
215
|
};
|
|
216
216
|
}
|
|
217
217
|
else if (context.extensions?.[streamInfoSymbol] &&
|
|
218
218
|
Array.isArray(incomingValue) &&
|
|
219
|
-
isStreamField(field, context.
|
|
219
|
+
isStreamField(field, context.variablesScope)) {
|
|
220
220
|
childTree.info = {
|
|
221
221
|
field,
|
|
222
222
|
typename,
|
|
223
223
|
merge: defaultStreamFieldMergeFn,
|
|
224
224
|
path,
|
|
225
|
-
variables: context.
|
|
225
|
+
variables: context.variablesScope,
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
228
|
else {
|
|
@@ -240,7 +240,7 @@ export class StoreWriter {
|
|
|
240
240
|
// provide a default value, so its absence from the written data should
|
|
241
241
|
// not be cause for alarm.
|
|
242
242
|
!policies.getReadFunction(typename, field.name.value)) {
|
|
243
|
-
invariant.error(
|
|
243
|
+
invariant.error(126, resultKeyNameFromField(field), result);
|
|
244
244
|
}
|
|
245
245
|
});
|
|
246
246
|
// Identify the result object, even if dataId was already provided,
|
|
@@ -353,7 +353,7 @@ export class StoreWriter {
|
|
|
353
353
|
return;
|
|
354
354
|
visitedNode.visited = true;
|
|
355
355
|
selectionSet.selections.forEach((selection) => {
|
|
356
|
-
if (!shouldInclude(selection, inheritedContext.
|
|
356
|
+
if (!shouldInclude(selection, inheritedContext.variablesScope))
|
|
357
357
|
return;
|
|
358
358
|
let { clientOnly, deferred } = inheritedContext;
|
|
359
359
|
if (
|
|
@@ -367,7 +367,7 @@ export class StoreWriter {
|
|
|
367
367
|
if (name === "client")
|
|
368
368
|
clientOnly = true;
|
|
369
369
|
if (name === "defer") {
|
|
370
|
-
const args = argumentsObjectFromField(dir, inheritedContext.
|
|
370
|
+
const args = argumentsObjectFromField(dir, inheritedContext.variablesScope);
|
|
371
371
|
// The @defer directive takes an optional args.if boolean
|
|
372
372
|
// argument, similar to @include(if: boolean). Note that
|
|
373
373
|
// @defer(if: false) does not make context.deferred false, but
|
|
@@ -403,25 +403,28 @@ export class StoreWriter {
|
|
|
403
403
|
else {
|
|
404
404
|
const fragment = getFragmentFromSelection(selection, context.lookupFragment);
|
|
405
405
|
if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
|
|
406
|
-
throw newInvariantError(
|
|
406
|
+
throw newInvariantError(127, selection.name.value);
|
|
407
407
|
}
|
|
408
408
|
if (!fragment)
|
|
409
409
|
return;
|
|
410
|
-
const
|
|
410
|
+
const variablesScope = (selection.kind === Kind.FRAGMENT_SPREAD &&
|
|
411
411
|
fragment.kind === Kind.FRAGMENT_DEFINITION) ?
|
|
412
|
-
|
|
412
|
+
getFragmentScope(selection, {
|
|
413
413
|
fragment,
|
|
414
|
-
variables: context.
|
|
415
|
-
parentScope: inheritedContext.
|
|
414
|
+
variables: context.variables,
|
|
415
|
+
parentScope: inheritedContext.variablesScope,
|
|
416
416
|
})
|
|
417
|
-
: inheritedContext.
|
|
418
|
-
if (policies.fragmentMatches(fragment, typename, result,
|
|
417
|
+
: inheritedContext.variablesScope;
|
|
418
|
+
if (policies.fragmentMatches(fragment, typename, result, variablesScope)) {
|
|
419
419
|
let fragmentContext = getContextFlavor(inheritedContext, clientOnly, deferred);
|
|
420
|
-
if (
|
|
420
|
+
if (variablesScope !== inheritedContext.variablesScope) {
|
|
421
421
|
fragmentContext = {
|
|
422
422
|
...fragmentContext,
|
|
423
|
-
|
|
424
|
-
varString:
|
|
423
|
+
variablesScope,
|
|
424
|
+
varString: makeVarString({
|
|
425
|
+
variables: context.variables,
|
|
426
|
+
scope: variablesScope,
|
|
427
|
+
}),
|
|
425
428
|
flavors: new Map(),
|
|
426
429
|
};
|
|
427
430
|
}
|
|
@@ -593,7 +596,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
593
596
|
}
|
|
594
597
|
});
|
|
595
598
|
}
|
|
596
|
-
__DEV__ && invariant.warn(
|
|
599
|
+
__DEV__ && invariant.warn(128, fieldName, parentType, childTypenames.length ?
|
|
597
600
|
"either ensure all objects of type " +
|
|
598
601
|
childTypenames.join(" and ") +
|
|
599
602
|
" have an ID or a custom merge function, or "
|