@apollo/client
Advanced tools
Comparing version 3.0.0-beta.12 to 3.0.0-beta.13
import { SelectionSetNode, DocumentNode } from 'graphql'; | ||
import { FragmentMap } from '../../utilities/graphql/fragments'; | ||
import { NormalizedCache, StoreObject } from './types'; | ||
import { Policies, StoreValueMergeFunction } from './policies'; | ||
import { Policies } from './policies'; | ||
export declare type WriteContext = { | ||
@@ -15,7 +15,3 @@ readonly store: NormalizedCache; | ||
}; | ||
declare type StoreObjectMergeFunction = (existing: StoreObject, incoming: StoreObject, overrides?: MergeOverrides) => StoreObject; | ||
declare type MergeOverrides = Record<string, { | ||
merge?: StoreValueMergeFunction; | ||
child?: MergeOverrides; | ||
}>; | ||
declare type StoreObjectMergeFunction = (existing: StoreObject, incoming: StoreObject) => StoreObject; | ||
export interface StoreWriterConfig { | ||
@@ -22,0 +18,0 @@ policies: Policies; |
import { __assign } from 'tslib'; | ||
import { invariant, InvariantError } from 'ts-invariant'; | ||
import { invariant } from 'ts-invariant'; | ||
import { createFragmentMap, getFragmentFromSelection } from '../../utilities/graphql/fragments.js'; | ||
@@ -7,2 +7,3 @@ import { getTypenameFromResult, isField, resultKeyNameFromField, makeReference, isReference } from '../../utilities/graphql/storeUtils.js'; | ||
import { shouldInclude } from '../../utilities/graphql/directives.js'; | ||
import { equal } from '@wry/equality'; | ||
import { cloneDeep } from '../../utilities/common/cloneDeep.js'; | ||
@@ -33,4 +34,4 @@ import { DeepMerger } from '../../utilities/common/mergeDeep.js'; | ||
}, | ||
mergeStoreObjects: function (existing, incoming, overrides) { | ||
return storeObjectMerger.merge(existing, incoming, store, overrides); | ||
mergeStoreObjects: function (existing, incoming) { | ||
return storeObjectMerger.merge(existing, incoming, store); | ||
}, | ||
@@ -59,3 +60,3 @@ variables: __assign(__assign({}, getDefaultValues(operationDefinition)), variables), | ||
} | ||
store.set(dataId, context.mergeStoreObjects(existing, processed.result, processed.mergeOverrides)); | ||
store.set(dataId, context.mergeStoreObjects(existing, processed.result)); | ||
return store; | ||
@@ -130,3 +131,3 @@ }; | ||
overrides_1 = overrides_1 || []; | ||
overrides_1[i] = mergeOverrides; | ||
overrides_1[i] = { child: mergeOverrides }; | ||
} | ||
@@ -170,9 +171,5 @@ return result; | ||
} | ||
var storeObjectReconciler = function (existingObject, incomingObject, property, store, mergeOverrides) { | ||
var storeObjectReconciler = function (existingObject, incomingObject, property, store) { | ||
var existing = existingObject[property]; | ||
var incoming = incomingObject[property]; | ||
var mergeChildObj = mergeOverrides && mergeOverrides[property]; | ||
if (mergeChildObj && typeof mergeChildObj.merge === "function") { | ||
return incoming; | ||
} | ||
if (existing !== incoming && | ||
@@ -188,21 +185,6 @@ this.isObject(existing) && | ||
} | ||
var childMergeOverrides = mergeChildObj && mergeChildObj.child; | ||
if (isReference(incoming)) { | ||
if (isReference(existing)) { | ||
return incoming.__ref === existing.__ref ? existing : incoming; | ||
} | ||
store.set(incoming.__ref, this.merge(existing, store.get(incoming.__ref), store, childMergeOverrides)); | ||
return incoming; | ||
process.env.NODE_ENV === "production" ? invariant(!isReference(existing) || isReference(incoming), 56) : invariant(!isReference(existing) || isReference(incoming), "Store error: the application attempted to write an object with no provided id but the store already contains an id of " + existing.__ref + " for this object."); | ||
if (equal(existing, incoming)) { | ||
return existing; | ||
} | ||
else if (isReference(existing)) { | ||
throw process.env.NODE_ENV === "production" ? new InvariantError(56) : new InvariantError("Store error: the application attempted to write an object with no provided id but the store already contains an id of " + existing.__ref + " for this object."); | ||
} | ||
if (Array.isArray(incoming)) { | ||
if (!Array.isArray(existing)) | ||
return incoming; | ||
if (existing.length > incoming.length) { | ||
return this.merge(existing.slice(0, incoming.length), incoming, store, childMergeOverrides); | ||
} | ||
} | ||
return this.merge(existing, incoming, store, childMergeOverrides); | ||
} | ||
@@ -209,0 +191,0 @@ return incoming; |
@@ -85,3 +85,3 @@ import { __awaiter, __generator, __assign } from 'tslib'; | ||
else { | ||
process.env.NODE_ENV === "production" ? invariant(false, 36) : invariant(false, 'To use context.getCacheKey, you need to use a cache that has ' + | ||
process.env.NODE_ENV === "production" ? invariant(false, 25) : invariant(false, 'To use context.getCacheKey, you need to use a cache that has ' + | ||
'a configurable dataIdFromObject, like apollo-cache-inmemory.'); | ||
@@ -194,3 +194,3 @@ } | ||
fragment = fragmentMap[selection.name.value]; | ||
process.env.NODE_ENV === "production" ? invariant(fragment, 37) : invariant(fragment, "No fragment named " + selection.name.value); | ||
process.env.NODE_ENV === "production" ? invariant(fragment, 26) : invariant(fragment, "No fragment named " + selection.name.value); | ||
} | ||
@@ -197,0 +197,0 @@ if (fragment && fragment.typeCondition) { |
@@ -49,3 +49,3 @@ import { __awaiter, __generator, __assign } from 'tslib'; | ||
this.fetchQueryRejectFns.forEach(function (reject) { | ||
reject(process.env.NODE_ENV === "production" ? new InvariantError(25) : new InvariantError('QueryManager stopped while query was in flight')); | ||
reject(process.env.NODE_ENV === "production" ? new InvariantError(27) : new InvariantError('QueryManager stopped while query was in flight')); | ||
}); | ||
@@ -61,4 +61,4 @@ }; | ||
case 0: | ||
process.env.NODE_ENV === "production" ? invariant(mutation, 26) : invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.'); | ||
process.env.NODE_ENV === "production" ? invariant(!fetchPolicy || fetchPolicy === 'no-cache', 27) : invariant(!fetchPolicy || fetchPolicy === 'no-cache', "Mutations only support a 'no-cache' fetchPolicy. If you don't want to disable the cache, remove your fetchPolicy setting to proceed with the default mutation behavior."); | ||
process.env.NODE_ENV === "production" ? invariant(mutation, 28) : invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.'); | ||
process.env.NODE_ENV === "production" ? invariant(!fetchPolicy || fetchPolicy === 'no-cache', 29) : invariant(!fetchPolicy || fetchPolicy === 'no-cache', "Mutations only support a 'no-cache' fetchPolicy. If you don't want to disable the cache, remove your fetchPolicy setting to proceed with the default mutation behavior."); | ||
mutationId = this.generateQueryId(); | ||
@@ -457,3 +457,3 @@ mutation = this.transform(mutation).document; | ||
if (shouldSubscribe === void 0) { shouldSubscribe = true; } | ||
process.env.NODE_ENV === "production" ? invariant(options.fetchPolicy !== 'standby', 28) : invariant(options.fetchPolicy !== 'standby', 'client.watchQuery cannot be called with fetchPolicy set to "standby"'); | ||
process.env.NODE_ENV === "production" ? invariant(options.fetchPolicy !== 'standby', 30) : invariant(options.fetchPolicy !== 'standby', 'client.watchQuery cannot be called with fetchPolicy set to "standby"'); | ||
options.variables = this.getVariables(options.query, options.variables); | ||
@@ -483,7 +483,7 @@ if (typeof options.notifyOnNetworkStatusChange === 'undefined') { | ||
var _this = this; | ||
process.env.NODE_ENV === "production" ? invariant(options.query, 29) : invariant(options.query, 'query option is required. You must specify your GraphQL document ' + | ||
process.env.NODE_ENV === "production" ? invariant(options.query, 31) : invariant(options.query, 'query option is required. You must specify your GraphQL document ' + | ||
'in the query option.'); | ||
process.env.NODE_ENV === "production" ? invariant(options.query.kind === 'Document', 30) : invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.'); | ||
process.env.NODE_ENV === "production" ? invariant(!options.returnPartialData, 31) : invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.'); | ||
process.env.NODE_ENV === "production" ? invariant(!options.pollInterval, 32) : invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.'); | ||
process.env.NODE_ENV === "production" ? invariant(options.query.kind === 'Document', 32) : invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.'); | ||
process.env.NODE_ENV === "production" ? invariant(!options.returnPartialData, 33) : invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.'); | ||
process.env.NODE_ENV === "production" ? invariant(!options.pollInterval, 34) : invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.'); | ||
return new Promise(function (resolve, reject) { | ||
@@ -556,3 +556,3 @@ var watchedQuery = _this.watchQuery(options, false); | ||
this.fetchQueryRejectFns.forEach(function (reject) { | ||
reject(process.env.NODE_ENV === "production" ? new InvariantError(33) : new InvariantError('Store reset while query was in flight (not completed in link chain)')); | ||
reject(process.env.NODE_ENV === "production" ? new InvariantError(35) : new InvariantError('Store reset while query was in flight (not completed in link chain)')); | ||
}); | ||
@@ -676,3 +676,3 @@ var resetIds = []; | ||
var foundObservableQuery = this.getQuery(queryIdOrObservable).observableQuery; | ||
process.env.NODE_ENV === "production" ? invariant(foundObservableQuery, 34) : invariant(foundObservableQuery, "ObservableQuery with this id doesn't exist: " + queryIdOrObservable); | ||
process.env.NODE_ENV === "production" ? invariant(foundObservableQuery, 36) : invariant(foundObservableQuery, "ObservableQuery with this id doesn't exist: " + queryIdOrObservable); | ||
observableQuery = foundObservableQuery; | ||
@@ -866,3 +866,3 @@ } | ||
var pollInterval = options.pollInterval; | ||
process.env.NODE_ENV === "production" ? invariant(pollInterval, 35) : invariant(pollInterval, 'Attempted to start a polling query without a polling interval.'); | ||
process.env.NODE_ENV === "production" ? invariant(pollInterval, 37) : invariant(pollInterval, 'Attempted to start a polling query without a polling interval.'); | ||
if (!this.ssrMode) { | ||
@@ -869,0 +869,0 @@ var info = this.pollingInfoByQueryId.get(queryId); |
@@ -20,3 +20,3 @@ import { invariant } from 'ts-invariant'; | ||
previousQuery.document === query.document || | ||
equal(previousQuery.document, query.document), 43) : invariant(!previousQuery || | ||
equal(previousQuery.document, query.document), 50) : invariant(!previousQuery || | ||
previousQuery.document === query.document || | ||
@@ -23,0 +23,0 @@ equal(previousQuery.document, query.document), 'Internal Error: may not update existing query string in store'); |
{ | ||
"name": "@apollo/client", | ||
"version": "3.0.0-beta.12", | ||
"version": "3.0.0-beta.13", | ||
"description": "A fully-featured caching GraphQL client.", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -12,3 +12,3 @@ import { invariant } from 'ts-invariant'; | ||
evaledValue = variables[ifArgument.value.name.value]; | ||
process.env.NODE_ENV === "production" ? invariant(evaledValue !== void 0, 44) : invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive."); | ||
process.env.NODE_ENV === "production" ? invariant(evaledValue !== void 0, 43) : invariant(evaledValue !== void 0, "Invalid variable referenced in @" + directive.name.value + " directive."); | ||
} | ||
@@ -46,8 +46,8 @@ else { | ||
var directiveName = directive.name.value; | ||
process.env.NODE_ENV === "production" ? invariant(directiveArguments && directiveArguments.length === 1, 45) : invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive."); | ||
process.env.NODE_ENV === "production" ? invariant(directiveArguments && directiveArguments.length === 1, 44) : invariant(directiveArguments && directiveArguments.length === 1, "Incorrect number of arguments for the @" + directiveName + " directive."); | ||
var ifArgument = directiveArguments[0]; | ||
process.env.NODE_ENV === "production" ? invariant(ifArgument.name && ifArgument.name.value === 'if', 46) : invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive."); | ||
process.env.NODE_ENV === "production" ? invariant(ifArgument.name && ifArgument.name.value === 'if', 45) : invariant(ifArgument.name && ifArgument.name.value === 'if', "Invalid argument for the @" + directiveName + " directive."); | ||
var ifValue = ifArgument.value; | ||
process.env.NODE_ENV === "production" ? invariant(ifValue && | ||
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 47) : invariant(ifValue && | ||
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), 46) : invariant(ifValue && | ||
(ifValue.kind === 'Variable' || ifValue.kind === 'BooleanValue'), "Argument for the @" + directiveName + " directive must be a variable or a boolean value."); | ||
@@ -54,0 +54,0 @@ return { directive: directive, ifArgument: ifArgument }; |
@@ -9,3 +9,3 @@ import { __assign, __spreadArrays } from 'tslib'; | ||
if (definition.kind === 'OperationDefinition') { | ||
throw process.env.NODE_ENV === "production" ? new InvariantError(48) : new InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " + | ||
throw process.env.NODE_ENV === "production" ? new InvariantError(47) : new InvariantError("Found a " + definition.operation + " operation" + (definition.name ? " named '" + definition.name.value + "'" : '') + ". " + | ||
'No operations are allowed when using a fragment as a query. Only fragments are allowed.'); | ||
@@ -18,3 +18,3 @@ } | ||
if (typeof actualFragmentName === 'undefined') { | ||
process.env.NODE_ENV === "production" ? invariant(fragments.length === 1, 49) : invariant(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment."); | ||
process.env.NODE_ENV === "production" ? invariant(fragments.length === 1, 48) : invariant(fragments.length === 1, "Found " + fragments.length + " fragments. `fragmentName` must be provided when there is not exactly 1 fragment."); | ||
actualFragmentName = fragments[0].name.value; | ||
@@ -56,3 +56,3 @@ } | ||
var fragment = fragmentMap && fragmentMap[selection.name.value]; | ||
process.env.NODE_ENV === "production" ? invariant(fragment, 50) : invariant(fragment, "No fragment named " + selection.name.value + "."); | ||
process.env.NODE_ENV === "production" ? invariant(fragment, 49) : invariant(fragment, "No fragment named " + selection.name.value + "."); | ||
return fragment; | ||
@@ -59,0 +59,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1924414
18597