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

Commits on Apr 30, 2020

  1. Required onError parameter in graphql ValidationContext

    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)
    junajan committed Apr 30, 2020
    Configuration menu
    Copy the full SHA
    163252f View commit details
    Browse the repository at this point in the history