Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
variables?: Object;
dataIdFromObject?: IdGetter;
fragmentMatcherFunction?: FragmentMatcher;
}): NormalizedCache {
// XXX TODO REFACTOR: this is a temporary workaround until query normalization is made to work with documents.
const operationDefinition = getOperationDefinition(document)!;
try {
return this.writeSelectionSetToStore({
result,
dataId,
selectionSet: operationDefinition.selectionSet,
context: {
store,
processedData: {},
variables: assign(
{},
getDefaultValues(operationDefinition),
variables,
),
dataIdFromObject,
fragmentMap: createFragmentMap(getFragmentDefinitions(document)),
fragmentMatcherFunction,
},
});
} catch (e) {
throw enhanceErrorWithDocument(e, document);
}
}
optimisticResponse,
updateQueries: updateQueriesByName,
refetchQueries = [],
update: updateWithProxyFn,
errorPolicy = 'ignore',
}: MutationOptions): Promise> {
if (!mutation) {
throw new Error(
'mutation option is required. You must specify your GraphQL document in the mutation option.',
);
}
const mutationId = this.generateQueryId();
mutation = this.dataStore.getCache().transformDocument(mutation);
variables = assign(
{},
getDefaultValues(getMutationDefinition(mutation)),
variables,
);
const mutationString = print(mutation);
const request = {
query: mutation,
variables,
operationName: getOperationName(mutation) || undefined,
} as Request;
this.setQuery(mutationId, () => ({ document: mutation }));
// Create a map of update queries by id to the query instead of by name.
const generateUpdateQueriesInfo: () => {
public diffQueryAgainstStore({
store,
query,
variables,
previousResult,
returnPartialData = true,
rootId = 'ROOT_QUERY',
fragmentMatcherFunction,
config,
}: DiffQueryAgainstStoreOptions): Cache.DiffResult {
// Throw the right validation error by trying to find a query in the document
const queryDefinition = getQueryDefinition(query);
variables = assign({}, getDefaultValues(queryDefinition), variables);
const context: ReadStoreContext = {
// Global settings
store,
dataIdFromObject: config && config.dataIdFromObject,
cacheRedirects: (config && config.cacheRedirects) || {},
};
const execResult = this.executeStoreQuery({
query,
rootValue: {
type: 'id',
id: rootId,
generated: true,
typename: 'Query',
},
throw new Error(
'client.watchQuery cannot be called with fetchPolicy set to "standby"',
);
}
// get errors synchronously
const queryDefinition = getQueryDefinition(options.query);
// assign variable default values if supplied
if (
queryDefinition.variableDefinitions &&
queryDefinition.variableDefinitions.length
) {
const defaultValues = getDefaultValues(queryDefinition);
options.variables = assign({}, defaultValues, options.variables);
}
if (typeof options.notifyOnNetworkStatusChange === 'undefined') {
options.notifyOnNetworkStatusChange = false;
}
let transformedOptions = { ...options } as WatchQueryOptions;
return new ObservableQuery({
scheduler: this.scheduler,
options: transformedOptions,
shouldSubscribe: shouldSubscribe,
});
}
export function writeResultToStore(_a) {
var dataId = _a.dataId, result = _a.result, document = _a.document, _b = _a.storeFactory, storeFactory = _b === void 0 ? defaultNormalizedCacheFactory : _b, _c = _a.store, store = _c === void 0 ? storeFactory() : _c, variables = _a.variables, dataIdFromObject = _a.dataIdFromObject, fragmentMatcherFunction = _a.fragmentMatcherFunction;
var operationDefinition = getOperationDefinition(document);
var selectionSet = operationDefinition.selectionSet;
var fragmentMap = createFragmentMap(getFragmentDefinitions(document));
variables = assign({}, getDefaultValues(operationDefinition), variables);
try {
return writeSelectionSetToStore({
result: result,
dataId: dataId,
selectionSet: selectionSet,
context: {
store: store,
storeFactory: storeFactory,
processedData: {},
variables: variables,
dataIdFromObject: dataIdFromObject,
fragmentMap: fragmentMap,
fragmentMatcherFunction: fragmentMatcherFunction,
},
});
}
QueryManager.prototype.mutate = function (_a) {
var _this = this;
var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueriesByName = _a.updateQueries, _b = _a.refetchQueries, refetchQueries = _b === void 0 ? [] : _b, updateWithProxyFn = _a.update, _c = _a.errorPolicy, errorPolicy = _c === void 0 ? 'none' : _c, _d = _a.context, context = _d === void 0 ? {} : _d;
if (!mutation) {
throw new Error('mutation option is required. You must specify your GraphQL document in the mutation option.');
}
var mutationId = this.generateQueryId();
var cache = this.dataStore.getCache();
(mutation = cache.transformDocument(mutation)),
(variables = assign({}, getDefaultValues(getMutationDefinition(mutation)), variables));
var mutationString = print(mutation);
var request = {
query: mutation,
variables: variables,
operationName: getOperationName(mutation) || undefined,
context: context,
};
this.setQuery(mutationId, function () { return ({ document: mutation }); });
var generateUpdateQueriesInfo = function () {
var ret = {};
if (updateQueriesByName) {
Object.keys(updateQueriesByName).forEach(function (queryName) {
return (_this.queryIdsByName[queryName] || []).forEach(function (queryId) {
ret[queryId] = {
updater: updateQueriesByName[queryName],
query: _this.queryStore.get(queryId),
export function diffQueryAgainstStore(_a) {
var store = _a.store, query = _a.query, variables = _a.variables, previousResult = _a.previousResult, _b = _a.returnPartialData, returnPartialData = _b === void 0 ? true : _b, _c = _a.rootId, rootId = _c === void 0 ? 'ROOT_QUERY' : _c, fragmentMatcherFunction = _a.fragmentMatcherFunction, config = _a.config;
var queryDefinition = getQueryDefinition(query);
variables = assign({}, getDefaultValues(queryDefinition), variables);
var context = {
store: store,
returnPartialData: returnPartialData,
cacheResolvers: (config && config.cacheResolvers) || {},
hasMissingField: false,
};
var rootIdValue = {
type: 'id',
id: rootId,
previousResult: previousResult,
};
var result = graphqlAnywhere(readStoreResolver, query, rootIdValue, context, variables, {
fragmentMatcher: fragmentMatcherFunction,
resultMapper: resultMapper,
});
return {
QueryManager.prototype.watchQuery = function (options, shouldSubscribe) {
if (shouldSubscribe === void 0) { shouldSubscribe = true; }
if (options.fetchPolicy === 'standby') {
throw new Error('client.watchQuery cannot be called with fetchPolicy set to "standby"');
}
var queryDefinition = getQueryDefinition(options.query);
if (queryDefinition.variableDefinitions &&
queryDefinition.variableDefinitions.length) {
var defaultValues = getDefaultValues(queryDefinition);
options.variables = assign({}, defaultValues, options.variables);
}
if (typeof options.notifyOnNetworkStatusChange === 'undefined') {
options.notifyOnNetworkStatusChange = false;
}
var transformedOptions = __assign({}, options);
return new ObservableQuery({
scheduler: this.scheduler,
options: transformedOptions,
shouldSubscribe: shouldSubscribe,
});
};
QueryManager.prototype.query = function (options) {