-
Notifications
You must be signed in to change notification settings - Fork 103
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
Always guard against undefined type in fieldAvailableOnType #231
Conversation
Previously, only the first half of the check inside `fieldAvailableOnType` guarded against `type` being `undefined`. To prevent this from accidentally happening again if we ever have to add another check to this logic, I moved the check for `!type` up into it's own guard, with an early return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotations 👇
@@ -5,7 +5,7 @@ | |||
"author": "Sashko Stubailo", | |||
"main": "lib/index.js", | |||
"scripts": { | |||
"test": "tav --ci && mocha test/index.js", | |||
"test": "tav", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests have been failing in CI for a while, because in CI tests rung against all versions of graphql
that satisfy the semver ranges defined in .tav.yml
:
eslint-plugin-graphql/.tav.yml
Line 3 in ed2e619
versions: ^0.12.0 || ^0.13.0 || ^14.0.0 |
Amongst those was v14.3.1
, which shows a slightly different error message for the ProvidedRequiredArguments
validator. You can see the error here: https://travis-ci.org/apollographql/eslint-plugin-graphql/jobs/548949602
If you look at recent PRs, all of them are failing with the same error. What made this confusing to me was that tav
was only being run on CI, and not locally. So locally tests were passing. For that reason, I thought it would be best if tav
also runs locally now –– hence why the --ci
flag is removed here. If that's not okay, I can revert this part of the PR.
Anyways, the fix for the actual error can be seen below in test/validationRules/built-in.js
@@ -162,7 +162,7 @@ const validatorCases = { | |||
errors: [ | |||
{ | |||
message: | |||
'Field "sum" argument "b" of type "Int!" is required but not provided.', | |||
/Field "sum" argument "b" of type "Int!" is required/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make these regexes so they pass in all versions of graphql
that we test (the error messages have slight variations depending on the version).
@@ -11,6 +11,7 @@ const requiredFieldsTestCases = { | |||
"const x = gql`query { greetings { id, hello, foo } }`", | |||
"const x = gql`query { greetings { id ... on Greetings { hello } } }`", | |||
"const x = gql`fragment Name on Greetings { id hello }`", | |||
"const x = gql`fragment Foo on FooBar { id, hello, foo }`", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case would throw an error if not for the fix in src/customGraphQLValidationRules.js
above
Hey @jnwng it's been almost 3 months, any chance you'd have time to take a look at this? It's blocking me from using |
lgtm. please rebase onto master as we’ve resolved the tests running in CI and can get this released
…On Wed, Sep 18 2019 at 8:02 AM, < ***@***.*** > wrote:
Hey @jnwng ( https://github.com/jnwng ) it's been almost 3 months, any
chance you'd have time to take a look at this? It's blocking me from using
eslint-plugin-graphql at work.
Thanks in advance!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (
#231?email_source=notifications&email_token=AAIRCRVKXXU6AODT3CZLG6LQKIKE5A5CNFSM4H2VW5MKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD672HWA#issuecomment-532653016
) , or mute the thread (
https://github.com/notifications/unsubscribe-auth/AAIRCRWFXMGEK4T34FMESIDQKIKE5ANCNFSM4H2VW5MA
).
|
@jnwng thanks so much for the reply! 🙏 I know y'all must be pretty busy, so I appreciate it! I had an issue with the original branch this PR was based on (says "unknown repository" now 🤔), so I recreated the PR here. I'll close this one and tag you over there! |
Previously, only the first half of the check inside
fieldAvailableOnType
guarded againsttype
beingundefined
. This meant that the function would throw an error.To fix this, and o prevent it from accidentally happening again if we ever add another check to this logic, I moved the check for
!type
up into it's own guard, with an early return.This change makes the required-fields rule more resilient (which uses this
fieldAvailableOnType
function internally).Without this change, I see errors when trying to run
eslint-plugin-graphql
against my project:TODO: