Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
}
return executeSelectionSet(
export function graphql(
resolver: Resolver,
document: DocumentNode,
rootValue?: any,
contextValue?: any,
variableValues?: VariableMap,
execOptions: ExecOptions = {},
): Promise {
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,
};
return executeSelectionSet(
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,
};
return executeSelectionSet(
private executeStoreQuery({
query,
rootValue,
contextValue,
variableValues,
// Default matcher always matches all fragments
fragmentMatcher = defaultFragmentMatcher,
}: ExecStoreQueryOptions): ExecResult {
const mainDefinition = getMainDefinition(query);
const fragments = getFragmentDefinitions(query);
const fragmentMap = createFragmentMap(fragments);
const execContext: ExecContext = {
query,
fragmentMap,
contextValue,
variableValues,
fragmentMatcher,
};
return this.executeSelectionSet({
selectionSet: mainDefinition.selectionSet,
rootValue,
execContext,
});
}
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 default function reduceDocument(document, options = {}) {
const mainDefinition = getMainDefinition(document);
const fragments = getFragmentDefinitions(document);
const operationDefinition = getOperationDefinition(document);
const path = operationDefinition
? operationDefinition.operation
: `type.${mainDefinition.typeCondition.name.value}`;
const execContext = {
rawFragmentMap: createFragmentMap(fragments),
fragmentMap: options.fragmentMap || {},
variables: options.variables,
typeGetter: options.typeGetter || (() => null),
};
return {
kind: 'Document',
definitions: [transformDefinition(mainDefinition, execContext, path)],
};
}
}
const {
credentials,
endpoints,
headers,
customFetch,
operationType,
mainDefinition,
fragmentDefinitions,
typeNameNormalizer,
fieldNameNormalizer,
fieldNameDenormalizer: linkLevelNameDenormalizer,
serializers,
} = context;
const fragmentMap = createFragmentMap(fragmentDefinitions);
let {
path,
endpoint,
pathBuilder,
} = directives.jsonapi as JsonApiLink.DirectiveOptions;
const endpointOption = getEndpointOptions(endpoints, endpoint);
const neitherPathsProvided = path == null && pathBuilder == null;
if (neitherPathsProvided) {
throw new Error(
`One of ("path" | "pathBuilder") must be set in the @jsonapi() directive. This request had neither, please add one`,
);
}
if (!pathBuilder) {