@apollo/client 4.1.0-alpha.8 → 4.1.0-rc.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/CHANGELOG.md +67 -0
- package/__cjs/cache/core/cache.cjs +64 -24
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +47 -0
- package/__cjs/cache/core/types/Cache.d.cts +39 -0
- package/__cjs/cache/index.cjs.map +1 -1
- package/__cjs/cache/index.d.cts +1 -1
- package/__cjs/cache/inmemory/entityStore.cjs +3 -3
- package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs +47 -0
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +47 -0
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +76 -17
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.d.cts +33 -6
- package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/types.d.cts +3 -0
- package/__cjs/cache/inmemory/writeToStore.cjs +24 -9
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/writeToStore.d.cts +1 -1
- package/__cjs/core/ApolloClient.cjs +14 -14
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +21 -1
- package/__cjs/core/ObservableQuery.cjs +22 -8
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +1 -0
- package/__cjs/core/QueryInfo.cjs +9 -1
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +4 -3
- package/__cjs/core/QueryManager.cjs +40 -20
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +19 -2
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +39 -0
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
- package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +1 -0
- package/__cjs/incremental/types.d.cts +9 -0
- package/__cjs/invariantErrorCodes.cjs +39 -33
- package/__cjs/link/error/index.cjs +1 -1
- package/__cjs/link/error/index.cjs.map +1 -1
- package/__cjs/link/error/index.d.cts +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.cjs +1 -0
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.cjs +7 -4
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.cjs +2 -0
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.cjs +41 -1
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/utilities/internal/checkDocument.cjs +2 -4
- package/__cjs/utilities/internal/checkDocument.cjs.map +1 -1
- package/__cjs/utilities/internal/constants.cjs +26 -0
- package/__cjs/utilities/internal/constants.cjs.map +1 -0
- package/__cjs/utilities/internal/constants.d.cts +23 -0
- package/__cjs/utilities/internal/index.cjs +7 -1
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +4 -0
- package/__cjs/utilities/internal/mapObservableFragment.cjs +27 -0
- package/__cjs/utilities/internal/mapObservableFragment.cjs.map +1 -0
- package/__cjs/utilities/internal/mapObservableFragment.d.cts +3 -0
- package/__cjs/utilities/internal/memoize.cjs +31 -0
- package/__cjs/utilities/internal/memoize.cjs.map +1 -0
- package/__cjs/utilities/internal/memoize.d.cts +8 -0
- package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.cjs +61 -0
- package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.cjs.map +1 -0
- package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.d.cts +11 -0
- package/__cjs/utilities/internal/ponyfills/index.cjs +6 -0
- package/__cjs/utilities/internal/ponyfills/index.cjs.map +1 -0
- package/__cjs/utilities/internal/ponyfills/index.d.cts +3 -0
- package/__cjs/utilities/internal/ponyfills/index.react-native.cjs +6 -0
- package/__cjs/utilities/internal/ponyfills/index.react-native.cjs.map +1 -0
- package/__cjs/utilities/internal/ponyfills/index.react-native.d.cts +2 -0
- package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.cjs +3 -0
- package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.cjs.map +1 -0
- package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.d.cts +12 -0
- package/__cjs/utilities/internal/types/StreamInfoTrie.cjs +3 -0
- package/__cjs/utilities/internal/types/StreamInfoTrie.cjs.map +1 -0
- package/__cjs/utilities/internal/types/StreamInfoTrie.d.cts +16 -0
- package/__cjs/version.cjs +1 -1
- package/__cjs/version.cjs.map +1 -1
- package/cache/core/cache.d.ts +47 -0
- package/cache/core/cache.js +65 -25
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +39 -0
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/index.d.ts +1 -1
- package/cache/index.js.map +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +47 -0
- package/cache/inmemory/inMemoryCache.js +47 -0
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.d.ts +33 -6
- package/cache/inmemory/policies.js +65 -7
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.js +3 -3
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +3 -0
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +1 -1
- package/cache/inmemory/writeToStore.js +26 -11
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts +21 -1
- package/core/ApolloClient.js +15 -15
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +1 -0
- package/core/ObservableQuery.js +23 -9
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +4 -3
- package/core/QueryInfo.js +10 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +19 -2
- package/core/QueryManager.js +41 -21
- package/core/QueryManager.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.d.ts +1 -0
- package/incremental/handlers/graphql17Alpha9.js +40 -1
- package/incremental/handlers/graphql17Alpha9.js.map +1 -1
- package/incremental/types.d.ts +9 -0
- package/incremental/types.js.map +1 -1
- package/invariantErrorCodes.js +39 -33
- package/legacyEntryPoints/utilities/internal/ponyfills/index.d.ts +1 -0
- package/legacyEntryPoints/utilities/internal/ponyfills/index.js +1 -0
- package/legacyEntryPoints/utilities/internal/ponyfills/ponyfills.cjs +1 -0
- package/legacyEntryPoints/utilities/internal/ponyfills/ponyfills.d.cts +1 -0
- package/link/error/index.d.ts +1 -1
- package/link/error/index.js +1 -1
- package/link/error/index.js.map +1 -1
- package/link/http/parseAndCheckHttpResponse.js +1 -1
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/package.json +15 -1
- package/react/hooks/useLazyQuery.js +2 -1
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useQuery.js +8 -5
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +2 -0
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.js +2 -1
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useQuery.js +9 -5
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.js +3 -1
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/query-preloader/createQueryPreloader.js +41 -1
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/utilities/internal/checkDocument.js +2 -4
- package/utilities/internal/checkDocument.js.map +1 -1
- package/utilities/internal/constants.d.ts +23 -0
- package/utilities/internal/constants.js +23 -0
- package/utilities/internal/constants.js.map +1 -0
- package/utilities/internal/index.d.ts +4 -0
- package/utilities/internal/index.js +2 -0
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/mapObservableFragment.d.ts +3 -0
- package/utilities/internal/mapObservableFragment.js +24 -0
- package/utilities/internal/mapObservableFragment.js.map +1 -0
- package/utilities/internal/memoize.d.ts +8 -0
- package/utilities/internal/memoize.js +28 -0
- package/utilities/internal/memoize.js.map +1 -0
- package/utilities/internal/ponyfills/FinalizationRegistry.d.ts +11 -0
- package/utilities/internal/ponyfills/FinalizationRegistry.js +57 -0
- package/utilities/internal/ponyfills/FinalizationRegistry.js.map +1 -0
- package/utilities/internal/ponyfills/index.d.ts +3 -0
- package/utilities/internal/ponyfills/index.js +3 -0
- package/utilities/internal/ponyfills/index.js.map +1 -0
- package/utilities/internal/ponyfills/index.react-native.d.ts +2 -0
- package/utilities/internal/ponyfills/index.react-native.js +2 -0
- package/utilities/internal/ponyfills/index.react-native.js.map +1 -0
- package/utilities/internal/types/ExtensionsWithStreamDetails.d.ts +12 -0
- package/utilities/internal/types/ExtensionsWithStreamDetails.js +2 -0
- package/utilities/internal/types/ExtensionsWithStreamDetails.js.map +1 -0
- package/utilities/internal/types/StreamInfoTrie.d.ts +16 -0
- package/utilities/internal/types/StreamInfoTrie.js +2 -0
- package/utilities/internal/types/StreamInfoTrie.js.map +1 -0
- package/version.js +1 -1
- package/version.js.map +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FieldNode, FragmentDefinitionNode, InlineFragmentNode, SelectionSetNode } from "graphql";
|
|
2
2
|
import type { OperationVariables } from "@apollo/client";
|
|
3
|
+
import type { Incremental } from "@apollo/client/incremental";
|
|
3
4
|
import type { Reference, StoreObject, StoreValue } from "@apollo/client/utilities";
|
|
4
5
|
import { isReference } from "@apollo/client/utilities";
|
|
5
6
|
import type { FragmentMap } from "@apollo/client/utilities/internal";
|
|
@@ -36,10 +37,10 @@ export type KeyArgsFunction = (args: Record<string, any> | null, context: {
|
|
|
36
37
|
field: FieldNode | null;
|
|
37
38
|
variables?: Record<string, any>;
|
|
38
39
|
}) => KeySpecifier | false | ReturnType<IdGetter>;
|
|
39
|
-
export type FieldPolicy<TExisting = any, TIncoming = TExisting, TReadResult = TIncoming,
|
|
40
|
+
export type FieldPolicy<TExisting = any, TIncoming = TExisting, TReadResult = TIncoming, TReadOptions extends FieldReadFunctionOptions = FieldReadFunctionOptions, TMergeOptions extends FieldMergeFunctionOptions = FieldMergeFunctionOptions> = {
|
|
40
41
|
keyArgs?: KeySpecifier | KeyArgsFunction | false;
|
|
41
|
-
read?: FieldReadFunction<TExisting, TReadResult,
|
|
42
|
-
merge?: FieldMergeFunction<TExisting, TIncoming,
|
|
42
|
+
read?: FieldReadFunction<TExisting, TReadResult, TReadOptions>;
|
|
43
|
+
merge?: FieldMergeFunction<TExisting, TIncoming, TMergeOptions> | boolean;
|
|
43
44
|
};
|
|
44
45
|
export type StorageType = Record<string, any>;
|
|
45
46
|
export interface FieldFunctionOptions<TArgs = Record<string, any>, TVariables extends OperationVariables = Record<string, any>> {
|
|
@@ -56,9 +57,35 @@ export interface FieldFunctionOptions<TArgs = Record<string, any>, TVariables ex
|
|
|
56
57
|
canRead: CanReadFunction;
|
|
57
58
|
mergeObjects: MergeObjectsFunction;
|
|
58
59
|
}
|
|
60
|
+
export interface FieldReadFunctionOptions<TArgs = Record<string, any>, TVariables extends OperationVariables = Record<string, any>> extends FieldFunctionOptions<TArgs, TVariables> {
|
|
61
|
+
}
|
|
62
|
+
export interface FieldMergeFunctionOptions<TArgs = Record<string, any>, TVariables extends OperationVariables = Record<string, any>> extends FieldFunctionOptions<TArgs, TVariables> {
|
|
63
|
+
/**
|
|
64
|
+
* Any `extensions` provided when writing the cache.
|
|
65
|
+
*/
|
|
66
|
+
extensions: Record<string, unknown> | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Details about the field when the `@stream` directive is used. Useful with
|
|
69
|
+
* custom merge functions to determine how to merge existing cache data with
|
|
70
|
+
* the incoming stream array.
|
|
71
|
+
*
|
|
72
|
+
* This field is only available in `merge` functions when the `@stream`
|
|
73
|
+
* directive is used on the field.
|
|
74
|
+
*
|
|
75
|
+
* > [!NOTE]
|
|
76
|
+
* > This field is not available when using the `Defer20220824Handler`
|
|
77
|
+
*/
|
|
78
|
+
streamFieldInfo?: Incremental.StreamFieldInfo;
|
|
79
|
+
/**
|
|
80
|
+
* The same value as the `existing` argument, but preserves the `existing`
|
|
81
|
+
* value on refetches when `refetchWritePolicy` is `overwrite` (the default).
|
|
82
|
+
*/
|
|
83
|
+
existingData: unknown;
|
|
84
|
+
}
|
|
59
85
|
type MergeObjectsFunction = <T extends StoreObject | Reference>(existing: T, incoming: T) => T;
|
|
60
|
-
export type FieldReadFunction<TExisting = any, TReadResult = TExisting, TOptions extends
|
|
61
|
-
export type FieldMergeFunction<TExisting = any, TIncoming = TExisting, TOptions extends
|
|
86
|
+
export type FieldReadFunction<TExisting = any, TReadResult = TExisting, TOptions extends FieldReadFunctionOptions = FieldReadFunctionOptions> = (existing: SafeReadonly<TExisting> | undefined, options: TOptions) => TReadResult | undefined;
|
|
87
|
+
export type FieldMergeFunction<TExisting = any, TIncoming = TExisting, TOptions extends FieldMergeFunctionOptions = FieldMergeFunctionOptions> = (existing: SafeReadonly<TExisting> | undefined, incoming: SafeReadonly<TIncoming>, options: TOptions) => SafeReadonly<TExisting>;
|
|
88
|
+
export declare const defaultStreamFieldMergeFn: FieldMergeFunction<Array<any>>;
|
|
62
89
|
export type PossibleTypesMap = {
|
|
63
90
|
[supertype: string]: string[];
|
|
64
91
|
};
|
|
@@ -92,7 +119,7 @@ export declare class Policies {
|
|
|
92
119
|
readField<V = StoreValue>(options: ReadFieldOptions, context: ReadMergeModifyContext): SafeReadonly<V> | undefined;
|
|
93
120
|
getReadFunction(typename: string | undefined, fieldName: string): FieldReadFunction | undefined;
|
|
94
121
|
getMergeFunction(parentTypename: string | undefined, fieldName: string, childTypename: string | undefined): FieldMergeFunction | undefined;
|
|
95
|
-
runMergeFunction(existing: StoreValue, incoming: StoreValue, { field, typename, merge }: MergeInfo, context: WriteContext, storage?: StorageType): any;
|
|
122
|
+
runMergeFunction(existing: StoreValue, incoming: StoreValue, { field, typename, merge, path }: MergeInfo, context: WriteContext, storage?: StorageType): any;
|
|
96
123
|
}
|
|
97
124
|
export declare function normalizeReadFieldOptions(readFieldArgs: any[], objectOrReference: StoreObject | Reference | undefined, variables?: ReadMergeModifyContext["variables"]): ReadFieldOptions;
|
|
98
125
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { equal } from "@wry/equality";
|
|
1
2
|
import { disableWarningsSlot } from "@apollo/client/masking";
|
|
2
3
|
import { isReference } from "@apollo/client/utilities";
|
|
3
4
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
5
|
+
import { streamInfoSymbol } from "@apollo/client/utilities/internal";
|
|
4
6
|
import { argumentsObjectFromField, getStoreKeyName, isArray, isNonNullObject, storeKeyNameFromField, stringifyForDisplay, } from "@apollo/client/utilities/internal";
|
|
5
7
|
import { invariant, newInvariantError, } from "@apollo/client/utilities/invariant";
|
|
6
8
|
import { defaultDataIdFromObject, fieldNameFromStoreName, hasOwn, selectionSetMatchesResult, storeValueIsStoreObject, TypeOrFieldNameRegExp, } from "./helpers.js";
|
|
@@ -17,6 +19,20 @@ const simpleKeyArgsFn = (_args, context) => context.fieldName;
|
|
|
17
19
|
// merge:false in a field policy.
|
|
18
20
|
const mergeTrueFn = (existing, incoming, { mergeObjects }) => mergeObjects(existing, incoming);
|
|
19
21
|
const mergeFalseFn = (_, incoming) => incoming;
|
|
22
|
+
export const defaultStreamFieldMergeFn = (existing, incoming, { streamFieldInfo, existingData }) => {
|
|
23
|
+
if (!existing && !existingData) {
|
|
24
|
+
return incoming;
|
|
25
|
+
}
|
|
26
|
+
const results = [];
|
|
27
|
+
const previous = existing ?? existingData;
|
|
28
|
+
const length = streamFieldInfo?.isLastChunk ?
|
|
29
|
+
incoming.length
|
|
30
|
+
: Math.max(previous.length, incoming.length);
|
|
31
|
+
for (let i = 0; i < length; i++) {
|
|
32
|
+
results[i] = incoming[i] === undefined ? previous[i] : incoming[i];
|
|
33
|
+
}
|
|
34
|
+
return results;
|
|
35
|
+
};
|
|
20
36
|
export class Policies {
|
|
21
37
|
config;
|
|
22
38
|
typePolicies = {};
|
|
@@ -204,7 +220,7 @@ export class Policies {
|
|
|
204
220
|
const rootId = "ROOT_" + which.toUpperCase();
|
|
205
221
|
const old = this.rootTypenamesById[rootId];
|
|
206
222
|
if (typename !== old) {
|
|
207
|
-
invariant(!old || old === which,
|
|
223
|
+
invariant(!old || old === which, 103, which);
|
|
208
224
|
// First, delete any old __typename associated with this rootId from
|
|
209
225
|
// rootIdsByTypename.
|
|
210
226
|
if (old)
|
|
@@ -347,7 +363,7 @@ export class Policies {
|
|
|
347
363
|
if (supertypeSet.has(supertype)) {
|
|
348
364
|
if (!typenameSupertypeSet.has(supertype)) {
|
|
349
365
|
if (checkingFuzzySubtypes) {
|
|
350
|
-
__DEV__ && invariant.warn(
|
|
366
|
+
__DEV__ && invariant.warn(104, typename, supertype);
|
|
351
367
|
}
|
|
352
368
|
// Record positive results for faster future lookup.
|
|
353
369
|
// Unfortunately, we cannot safely cache negative results,
|
|
@@ -476,7 +492,9 @@ export class Policies {
|
|
|
476
492
|
}
|
|
477
493
|
return merge;
|
|
478
494
|
}
|
|
479
|
-
runMergeFunction(existing, incoming, { field, typename, merge }, context, storage) {
|
|
495
|
+
runMergeFunction(existing, incoming, { field, typename, merge, path }, context, storage) {
|
|
496
|
+
// Preserve the value in case `context.overwrite` is set.
|
|
497
|
+
const existingData = existing;
|
|
480
498
|
if (merge === mergeTrueFn) {
|
|
481
499
|
// Instead of going to the trouble of creating a full
|
|
482
500
|
// FieldFunctionOptions object and calling mergeTrueFn, we can
|
|
@@ -494,7 +512,18 @@ export class Policies {
|
|
|
494
512
|
if (context.overwrite) {
|
|
495
513
|
existing = void 0;
|
|
496
514
|
}
|
|
497
|
-
|
|
515
|
+
const streamInfo = context.extensions?.[streamInfoSymbol]
|
|
516
|
+
?.deref()
|
|
517
|
+
?.peekArray(path);
|
|
518
|
+
if (streamInfo) {
|
|
519
|
+
const { current, previous } = streamInfo;
|
|
520
|
+
if (previous &&
|
|
521
|
+
equal(previous.incoming, incoming) &&
|
|
522
|
+
equal(previous.streamFieldInfo, current)) {
|
|
523
|
+
return previous.result;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
const result = merge(existing, incoming, makeMergeFieldFunctionOptions(this,
|
|
498
527
|
// Unlike options.readField for read functions, we do not fall
|
|
499
528
|
// back to the current object if no foreignObjOrRef is provided,
|
|
500
529
|
// because it's not clear what the current object should be for
|
|
@@ -511,7 +540,16 @@ export class Policies {
|
|
|
511
540
|
fieldName: field.name.value,
|
|
512
541
|
field,
|
|
513
542
|
variables: context.variables,
|
|
514
|
-
|
|
543
|
+
path,
|
|
544
|
+
}, context, storage || {}, existingData));
|
|
545
|
+
if (streamInfo) {
|
|
546
|
+
streamInfo.previous = {
|
|
547
|
+
incoming,
|
|
548
|
+
streamFieldInfo: streamInfo.current,
|
|
549
|
+
result,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
return result;
|
|
515
553
|
}
|
|
516
554
|
}
|
|
517
555
|
function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, context, storage) {
|
|
@@ -536,6 +574,26 @@ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, contex
|
|
|
536
574
|
mergeObjects: makeMergeObjectsFunction(context.store),
|
|
537
575
|
};
|
|
538
576
|
}
|
|
577
|
+
function makeMergeFieldFunctionOptions(policies, objectOrReference, fieldSpec, context, storage, existingData) {
|
|
578
|
+
const options = {
|
|
579
|
+
...makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, context, storage),
|
|
580
|
+
extensions: context.extensions,
|
|
581
|
+
existingData,
|
|
582
|
+
};
|
|
583
|
+
const extensions = context.extensions;
|
|
584
|
+
if (extensions && streamInfoSymbol in extensions) {
|
|
585
|
+
const { [streamInfoSymbol]: streamInfo, ...otherExtensions } = extensions;
|
|
586
|
+
const streamFieldInfo = streamInfo?.deref()?.peekArray(fieldSpec.path);
|
|
587
|
+
if (streamFieldInfo) {
|
|
588
|
+
options.streamFieldInfo = streamFieldInfo.current;
|
|
589
|
+
}
|
|
590
|
+
// If the only key in `extensions` was the stream details key, we didn't
|
|
591
|
+
// receive any remote extensions, so we reset extensions back to undefined
|
|
592
|
+
options.extensions =
|
|
593
|
+
Object.keys(otherExtensions).length === 0 ? undefined : otherExtensions;
|
|
594
|
+
}
|
|
595
|
+
return options;
|
|
596
|
+
}
|
|
539
597
|
export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables) {
|
|
540
598
|
const { 0: fieldNameOrOptions, 1: from, length: argc } = readFieldArgs;
|
|
541
599
|
let options;
|
|
@@ -557,7 +615,7 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
|
|
|
557
615
|
}
|
|
558
616
|
}
|
|
559
617
|
if (__DEV__ && options.from === void 0) {
|
|
560
|
-
__DEV__ && invariant.warn(
|
|
618
|
+
__DEV__ && invariant.warn(105, stringifyForDisplay(Array.from(readFieldArgs)));
|
|
561
619
|
}
|
|
562
620
|
if (void 0 === options.variables) {
|
|
563
621
|
options.variables = variables;
|
|
@@ -567,7 +625,7 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
|
|
|
567
625
|
function makeMergeObjectsFunction(store) {
|
|
568
626
|
return function mergeObjects(existing, incoming) {
|
|
569
627
|
if (isArray(existing) || isArray(incoming)) {
|
|
570
|
-
throw newInvariantError(
|
|
628
|
+
throw newInvariantError(106);
|
|
571
629
|
}
|
|
572
630
|
// These dynamic checks are necessary because the parameters of a
|
|
573
631
|
// custom merge function can easily have the any type, so the type
|