Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function graphql(
resolver: Resolver,
document: DocumentNode,
rootValue?: any,
contextValue?: any,
variableValues?: VariableMap,
execOptions: ExecOptions = {},
) {
const mainDefinition = getMainDefinition(document);
const fragments = getFragmentDefinitions(document);
const fragmentMap = createFragmentMap(fragments);
const resultMapper = execOptions.resultMapper;
// Default matcher always matches all fragments
const fragmentMatcher = execOptions.fragmentMatcher || (() => true);
const execContext: ExecContext = {
fragmentMap,
contextValue,
variableValues,
resultMapper,
resolver,
fragmentMatcher,
};
export const executeStoreQuery = wrap(function (
query: DocumentNode,
rootValue: IdValue,
contextValue: ReadStoreContext,
variableValues: VariableMap,
// Default matcher always matches all fragments
fragmentMatcher: FragmentMatcher = defaultFragmentMatcher,
): ExecResult {
const mainDefinition = getMainDefinition(query);
const fragments = getFragmentDefinitions(query);
const fragmentMap = createFragmentMap(fragments);
const execContext: ExecContext = {
fragmentMap,
contextValue,
variableValues,
fragmentMatcher,
};
return executeSelectionSet(
mainDefinition.selectionSet,
rootValue,
execContext,
);
}, {
makeCacheKey(
function graphql(
resolver,
document,
rootValue,
contextValue,
variables,
execOptions = {}
) {
const mainDefinition = getMainDefinition(document)
const fragments = getFragmentDefinitions(document)
const fragmentMap = createFragmentMap(fragments)
const resultMapper = execOptions.resultMapper
// Default matcher always matches all fragments
const fragmentMatcher = execOptions.fragmentMatcher || (() => true)
const execContext = {
fragmentMap,
contextValue,
variables,
resultMapper,
resolver,
fragmentMatcher
}
export function graphql(
resolver: Resolver,
document: DocumentNode,
rootValue?: any,
contextValue?: any,
variableValues?: VariableMap,
execOptions: ExecOptions = {},
) {
const mainDefinition = getMainDefinition(document);
const fragments = getFragmentDefinitions(document);
const fragmentMap = createFragmentMap(fragments);
const resultMapper = execOptions.resultMapper;
// Default matcher always matches all fragments
const fragmentMatcher = execOptions.fragmentMatcher || (() => true);
const execContext: ExecContext = {
fragmentMap,
contextValue,
variableValues,
resultMapper,
resolver,
fragmentMatcher,
};
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);
}
}
private async resolveDocument(
document: DocumentNode,
rootValue: TData,
context: any = {},
variables: VariableMap = {},
fragmentMatcher: FragmentMatcher = () => true,
onlyRunForcedResolvers: boolean = false,
) {
const mainDefinition = getMainDefinition(document);
const fragments = getFragmentDefinitions(document);
const fragmentMap = createFragmentMap(fragments);
const definitionOperation = (mainDefinition as OperationDefinitionNode)
.operation;
const defaultOperationType = definitionOperation
? capitalizeFirstLetter(definitionOperation)
: 'Query';
const { cache, client } = this;
const execContext: ExecContext = {
fragmentMap,
context: {
...context,
cache,
client,
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,
},
});