Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function collectCacheControlHints(
schema: GraphQLSchema,
source: string,
options?: CacheControlExtensionOptions,
): Promise {
enableGraphQLExtensions(schema);
// Because this test helper looks at the formatted extensions, we always want
// to include them.
const cacheControlExtension = new CacheControlExtension({
...options,
stripFormattedExtensions: false,
});
const response = await graphql({
schema,
source,
contextValue: {
_extensionStack: new GraphQLExtensionStack([cacheControlExtension]),
},
});
constructor(public readonly schema: GraphQLSchema) {
// FIXME: This is needed to enable support for `resolveObject`, but we
// should move that to `apollo-graphql`
enableGraphQLExtensions(schema);
}
function initializeExtensionStack(): GraphQLExtensionStack {
enableGraphQLExtensions(config.schema);
// If custom extension factories were provided, create per-request extension
// objects.
const extensions = config.extensions ? config.extensions.map(f => f()) : [];
if (config.tracing) {
extensions.push(new TracingExtension());
}
if (config.cacheControl) {
cacheControlExtension = new CacheControlExtension(config.cacheControl);
extensions.push(cacheControlExtension);
}
return new GraphQLExtensionStack(extensions);
}
extensions.push(new CacheControlExtension());
} else if (options.cacheControl) {
extensions.push(new CacheControlExtension(options.cacheControl));
}
const extensionStack = new GraphQLExtensionStack(extensions);
// We unconditionally create an extensionStack, even if there are no
// extensions (so that we don't have to litter the rest of this function with
// `if (extensionStack)`, but we don't instrument the schema unless there
// actually are extensions. We do unconditionally put the stack on the
// context, because if some other call had extensions and the schema is
// already instrumented, that's the only way to get a custom fieldResolver to
// work.
if (extensions.length > 0) {
enableGraphQLExtensions(options.schema);
}
context._extensionStack = extensionStack;
const requestDidEnd = extensionStack.requestDidStart({
// Since the Request interfacess are not the same between node-fetch and
// typescript's lib dom, we should limit the fields that need to be passed
// into requestDidStart to only the ones we need, currently just the
// headers, method, and url
request: options.request as any,
queryString: options.queryString,
parsedQuery: options.parsedQuery,
operationName: options.operationName,
variables: options.variables,
persistedQueryHit: options.persistedQueryHit,
persistedQueryRegister: options.persistedQueryRegister,
context,
extensions.push(new CacheControlExtension());
} else if (options.cacheControl) {
extensions.push(new CacheControlExtension(options.cacheControl));
}
const extensionStack = new GraphQLExtensionStack(extensions);
// We unconditionally create an extensionStack, even if there are no
// extensions (so that we don't have to litter the rest of this function with
// `if (extensionStack)`, but we don't instrument the schema unless there
// actually are extensions. We do unconditionally put the stack on the
// context, because if some other call had extensions and the schema is
// already instrumented, that's the only way to get a custom fieldResolver to
// work.
if (extensions.length > 0) {
enableGraphQLExtensions(options.schema);
}
context._extensionStack = extensionStack;
const requestDidEnd = extensionStack.requestDidStart({
// Since the Request interfacess are not the same between node-fetch and
// typescript's lib dom, we should limit the fields that need to be passed
// into requestDidStart to only the ones we need, currently just the
// headers, method, and url
request: options.request as any,
queryString: options.queryString,
parsedQuery: options.parsedQuery,
operationName: options.operationName,
variables: options.variables,
persistedQueryHit: options.persistedQueryHit,
persistedQueryRegister: options.persistedQueryRegister,
context,
const context = options.context || {};
let extensions = [];
if (options.tracing) {
extensions.push(TracingExtension);
}
if (options.cacheControl === true) {
extensions.push(CacheControlExtension);
} else if (options.cacheControl) {
extensions.push(new CacheControlExtension(options.cacheControl));
}
const extensionStack =
extensions.length > 0 && new GraphQLExtensionStack(extensions);
if (extensionStack) {
context._extensionStack = extensionStack;
enableGraphQLExtensions(options.schema);
extensionStack.requestDidStart();
}
const qry =
typeof options.query === 'string' ? options.query : print(options.query);
logFunction({
action: LogAction.request,
step: LogStep.status,
key: 'query',
data: qry,
});
logFunction({
action: LogAction.request,
step: LogStep.status,
key: 'variables',
logFunction({ action: LogAction.request, step: LogStep.start });
var context = options.context || {};
var extensions = [];
if (options.tracing) {
extensions.push(apollo_tracing_1.TracingExtension);
}
if (options.cacheControl === true) {
extensions.push(apollo_cache_control_1.CacheControlExtension);
}
else if (options.cacheControl) {
extensions.push(new apollo_cache_control_1.CacheControlExtension(options.cacheControl));
}
var extensionStack = extensions.length > 0 && new graphql_extensions_1.GraphQLExtensionStack(extensions);
if (extensionStack) {
context._extensionStack = extensionStack;
graphql_extensions_1.enableGraphQLExtensions(options.schema);
extensionStack.requestDidStart();
}
var qry = typeof options.query === 'string' ? options.query : graphql_1.print(options.query);
logFunction({
action: LogAction.request,
step: LogStep.status,
key: 'query',
data: qry,
});
logFunction({
action: LogAction.request,
step: LogStep.status,
key: 'variables',
data: options.variables,
});
logFunction({