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

Add ability to detect unused variables #660

Merged
merged 13 commits into from
Apr 14, 2021
Merged

Add ability to detect unused variables #660

merged 13 commits into from
Apr 14, 2021

Conversation

mfn
Copy link
Collaborator

@mfn mfn commented Jul 11, 2020

Summary

Inspired by webonyx/graphql-php#615 (comment)

I once had a bug in production which went unnoticed for some time because one of the "variables" passed it had a typo and thus wasn't consumed. The destination field in question also was "nullable", so no obvious error was triggered.

The idea is to provide a config option to enable this behaviour (e.g. only on local development) to throw a hard error.

Example

Query

mutation test($value:ID) {
  someMutation(type:"falbala", optional_id:$value)
}

Variables:

{
  // Ops! typo
  "values": "159"
}

Result:

{
  "errors": [
    {
      "message": "The following variables were provided but not consumed: values",
      "extensions": {
        "category": "graphql"
      }
    }
  ]
}

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Misc. change (internal, infrastructure, maintenance, etc.)

Checklist

  • Existing tests have been adapted and/or new tests have been added
  • Add a CHANGELOG.md entry
  • Update the README.md
  • Code style has been fixed via composer fix-style

@mfn mfn self-assigned this Jul 11, 2020
src/GraphQL.php Outdated Show resolved Hide resolved
@mfn mfn marked this pull request as ready for review April 14, 2021 17:49
Copy link
Collaborator Author

@mfn mfn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally found time to wrap this up \o/

@mfn mfn merged commit 6fcc060 into master Apr 14, 2021
@mfn mfn deleted the mfn-detect-unused branch April 14, 2021 17:55
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

1 participant