Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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 (queryHash !== computedQueryHash) {
throw new InvalidGraphQLRequestError(
'provided sha does not match query',
);
}
// We won't write to the persisted query cache until later.
// Defering the writing gives plugins the ability to "win" from use of
// the cache, but also have their say in whether or not the cache is
// written to (by interrupting the request with an error).
metrics.persistedQueryRegister = true;
}