Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} else if (extensions.persistedQuery.version !== 1) {
throw new InvalidGraphQLRequestError(
'Unsupported persisted query version',
);
}
// We'll store a reference to the persisted query cache so we can actually
// do the write at a later point in the request pipeline processing.
persistedQueryCache = config.persistedQueries.cache;
// This is a bit hacky, but if `config` came from direct use of the old
// apollo-server 1.0-style middleware (graphqlExpress etc, not via the
// ApolloServer class), it won't have been converted to
// PrefixingKeyValueCache yet.
if (!(persistedQueryCache instanceof PrefixingKeyValueCache)) {
persistedQueryCache = new PrefixingKeyValueCache(
persistedQueryCache,
APQ_CACHE_PREFIX,
);
}
queryHash = extensions.persistedQuery.sha256Hash;
if (query === undefined) {
query = await persistedQueryCache.get(queryHash);
if (query) {
metrics.persistedQueryHit = true;
} else {
throw new PersistedQueryNotFoundError();
}
} else {
const computedQueryHash = computeQueryHash(query);
};
}
}
if (!requestOptions.cache) {
requestOptions.cache = new InMemoryLRUCache();
}
if (requestOptions.persistedQueries !== false) {
const {
cache: apqCache = requestOptions.cache!,
...apqOtherOptions
} = requestOptions.persistedQueries || Object.create(null);
requestOptions.persistedQueries = {
cache: new PrefixingKeyValueCache(apqCache, APQ_CACHE_PREFIX),
...apqOtherOptions,
};
} else {
// the user does not want to use persisted queries, so we remove the field
delete requestOptions.persistedQueries;
}
this.requestOptions = requestOptions as GraphQLServerOptions;
if (uploads !== false && !forbidUploadsForTesting) {
if (this.supportsUploads()) {
if (!runtimeSupportsUploads) {
printNodeFileUploadsMessage();
throw new Error(
'`graphql-upload` is no longer supported on Node.js < v8.5.0. ' +
'See https://bit.ly/gql-upload-node-6.',
requestDidStart(
outerRequestContext: GraphQLRequestContext,
): GraphQLRequestListener {
const cache = new PrefixingKeyValueCache(
options.cache || outerRequestContext.cache!,
'fqc:',
);
let sessionId: string | null = null;
let baseCacheKey: BaseCacheKey | null = null;
let age: number | null = null;
return {
async responseForOperation(
requestContext,
): Promise {
requestContext.metrics.responseCacheHit = false;
if (!isGraphQLQuery(requestContext)) {
return null;
constructor(
keyValueCache: KeyValueCache = new InMemoryLRUCache(),
httpFetch: typeof fetch = fetch,
) {
this.keyValueCache = new PrefixingKeyValueCache(
keyValueCache,
'httpcache:',
);
this.httpFetch = httpFetch;
}