Skip to content

Commit

Permalink
Merge pull request #327 from the-hideout/no-cache-errors
Browse files Browse the repository at this point in the history
Don't cache error responses
  • Loading branch information
Razzmatazzz authored Sep 2, 2024
2 parents 8b6a1cb + 90bbdad commit cf91430
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ async function graphqlHandler(request, env, ctx) {
result.warnings.push(...context.warnings);
}

if (specialCache === 'application/json') {
if (result.errors?.some(err => err.message === 'Unexpected error.')) {
ttl = 0;
} else if (result.errors?.some(err => err.message.startsWith('Syntax Error'))) {
ttl = 1800;
} else if (specialCache === 'application/json') {
if (!result.warnings) {
result = Object.assign({warnings: []}, result);
}
Expand Down
6 changes: 5 additions & 1 deletion plugins/plugin-use-cache-machine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ export default function useCacheMachine(env) {
let ttl = request.data?.getRequestTtl(request.requestId) ?? 60 * 5;

const sCache = specialCache(request);
if (sCache === 'application/json') {
if (result.errors?.some(err => err.message === 'Unexpected error.')) {
ttl = 0;
} else if (result.errors?.some(err => err.message.startsWith('Syntax Error'))) {
ttl = 1800;
} else if (sCache === 'application/json') {
if (!result.warnings) {
result = Object.assign({warnings: []}, result);
}
Expand Down
2 changes: 1 addition & 1 deletion utils/graphql-util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const graphqlUtil = {
for (const arg of selection.arguments) {
if (arg.name.value === argumentName) {
if (arg.value.kind === 'Variable') {
argValue = info.variableValues[argumentName];
argValue = info.variableValues[arg.value.name.value];
} else {
argValue = arg.value.value;
}
Expand Down

0 comments on commit cf91430

Please sign in to comment.