Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorect behavior of plugin apollo-server-plugin-response-cache in case of validation error on client request #2745

Closed
kolegm opened this issue May 30, 2019 · 0 comments · Fixed by #2792

Comments

@kolegm
Copy link

kolegm commented May 30, 2019

Hey guys

I have a bug related to the plugin apollo-server-plugin-response-cache.

Expected:
When the client sends a not well-formed request, server must answers with GraphQL error and validation details. Example of correct answer
{ name: 'ValidationError', message: 'Cannot query field "accommodations_foo" on type "Query". Did you mean "accommodations"?', code: 'GRAPHQL_VALIDATION_FAILED' } [ 'Cannot query field "accommodations_foo" on type "Query". Did you mean "accommodations"?',

Actually:
The client received the bag. Trace:
{ name: 'TypeError', message: 'Cannot read property \'operation\' of undefined', code: 'INTERNAL_SERVER_ERROR' } [ 'TypeError: Cannot read property \'operation\' of undefined', at isGraphQLQuery (/home/***/node_modules/apollo-server-plugin-response-cache/src/ 2:36)', at Object.<anonymous> (/home/***/node_modules/apollo-server-plugin-response-cache/ s:224:16)', at Generator.next (<anonymous>)', at /home/***/node_modules/apollo-server-plugin-response-cache/dist/ApolloServerPlu at new Promise (<anonymous>)', at __awaiter (/home/***/node_modules/apollo-server-plugin-response-cache/dist/Apolo, at Object.willSendResponse (/home/***/node_modules/apollo-server-plugin-response-cache/dist/ApolloServerPluginResponseCache.js:92:28)',

Would be great to fix the logic here:

return requestContext.operation!.operation === 'query';

Example of fix (just add checking of existing the operation level:
function isGraphQLQuery(requestContext) { return requestContext.operation && requestContext.operation.operation === 'query'; }

By the way, I'm developing my service on JavaScript, not TypeScript. Maybe it will help you navigate the nature of the error

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant