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

Required onError parameter in graphql ValidationContext #27

Closed
wants to merge 1 commit into from
Closed

Required onError parameter in graphql ValidationContext #27

wants to merge 1 commit into from

Conversation

junajan
Copy link

@junajan junajan commented Apr 30, 2020

In the recent release of graphql-js plugin there has been a breaking change in ValidationContext class which now requires a fourth "onError" parameter in its constructor.

See: https://github.com/graphql/graphql-js/pull/2130/files

Right now, if the client sends a query without a required parameter, the graphql server throws an error which is incorrectly handled in the graphql-query-complexity plugin so it throws a new error:

TypeError: this._onError is not a function
    at ValidationContext.reportError (.../node_modules/graphql/validation/ValidationContext.js:46:10)
    at .../node_modules/graphql-query-complexity/dist/QueryComplexity.js:121:49
    at Array.reduce (<anonymous>)
    at QueryComplexity.nodeComplexity (.../node_modules/graphql-query-complexity/dist/QueryComplexity.js:85:62)
    at QueryComplexity.onOperationDefinitionEnter (.../node_modules/graphql-query-complexity/dist/QueryComplexity.js:56:41)
    at Object.enter (.../node_modules/graphql/utilities/TypeInfo.js:370:25)
    at Object.visit (.../node_modules/graphql/language/visitor.js:243:26)
    at getComplexity (.../node_modules/graphql-query-complexity/dist/QueryComplexity.js:24:15)

To fix this, we can add an empty error handler (this plugin only calculates complexity, not handling invalid GQL queries so an empty function should be fine)

In the [recent release](https://github.com/graphql/graphql-js/releases/tag/v15.0.0) of graphql-js plugin there has been a breaking change in `ValidationContext` class which now requires a fourth "onError" parameter in its constructor.

See: https://github.com/graphql/graphql-js/pull/2130/files

Right now, if the client sends a query without a required parameter, the graphql server throws an error which is incorrectly handled in the `graphql-query-complexity` plugin so it throws a new error:
```
TypeError: this._onError is not a function
    at ValidationContext.reportError (.../node_modules/graphql/validation/ValidationContext.js:46:10)
    at .../node_modules/graphql-query-complexity/dist/QueryComplexity.js:121:49
    at Array.reduce (<anonymous>)
    at QueryComplexity.nodeComplexity (.../node_modules/graphql-query-complexity/dist/QueryComplexity.js:85:62)
    at QueryComplexity.onOperationDefinitionEnter (.../node_modules/graphql-query-complexity/dist/QueryComplexity.js:56:41)
    at Object.enter (.../node_modules/graphql/utilities/TypeInfo.js:370:25)
    at Object.visit (.../node_modules/graphql/language/visitor.js:243:26)
    at getComplexity (.../node_modules/graphql-query-complexity/dist/QueryComplexity.js:24:15)
 ```

To fix this, we can add an empty error handler (this plugin only calculates complexity, not handling invalid GQL queries so an empty function should be fine)
@ivome ivome mentioned this pull request May 22, 2020
@ivome
Copy link
Collaborator

ivome commented May 25, 2020

Thanks for the PR! I just merged #30 which also contains this fix among others and adds support for GraphQL v15.

@ivome ivome closed this May 25, 2020
@junajan
Copy link
Author

junajan commented May 26, 2020

Thanks @ivome

@junajan junajan deleted the patch-1 branch May 26, 2020 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants