-
Notifications
You must be signed in to change notification settings - Fork 2k
VariableDefinition Directives: hide behind experimental flag #1454
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,16 @@ | |
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
import { parse } from '../../language'; | ||
import { buildSchema } from '../../utilities'; | ||
import { validate } from '../validate'; | ||
import { | ||
expectPassesRule, | ||
expectFailsRule, | ||
expectSDLErrorsFromRule, | ||
testSchema, | ||
} from './harness'; | ||
|
||
import { | ||
|
@@ -127,7 +131,7 @@ describe('Validate: Known directives', () => { | |
expectPassesRule( | ||
KnownDirectives, | ||
` | ||
query Foo($var: Boolean @onVariableDefinition) @onQuery { | ||
query Foo($var: Boolean) @onQuery { | ||
name @include(if: $var) | ||
...Frag @include(if: true) | ||
skippedField @skip(if: true) | ||
|
@@ -141,11 +145,26 @@ describe('Validate: Known directives', () => { | |
); | ||
}); | ||
|
||
it('with well placed variable definition directive', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merged before I saw your comments: will fix up now. |
||
// Need to parse with experimental flag | ||
const queryString = ` | ||
query Foo($var: Boolean @onVariableDefinition) { | ||
name | ||
} | ||
`; | ||
const errors = validate( | ||
testSchema, | ||
parse(queryString, { experimentalVariableDefinitionDirectives: true }), | ||
[KnownDirectives], | ||
); | ||
expect(errors).to.deep.equal([], 'Should validate'); | ||
}); | ||
|
||
it('with misplaced directives', () => { | ||
expectFailsRule( | ||
KnownDirectives, | ||
` | ||
query Foo($var: Boolean @onField) @include(if: true) { | ||
query Foo($var: Boolean) @include(if: true) { | ||
name @onQuery @include(if: $var) | ||
...Frag @onQuery | ||
} | ||
|
@@ -155,15 +174,33 @@ describe('Validate: Known directives', () => { | |
} | ||
`, | ||
[ | ||
misplacedDirective('onField', 'VARIABLE_DEFINITION', 2, 31), | ||
misplacedDirective('include', 'QUERY', 2, 41), | ||
misplacedDirective('include', 'QUERY', 2, 32), | ||
misplacedDirective('onQuery', 'FIELD', 3, 14), | ||
misplacedDirective('onQuery', 'FRAGMENT_SPREAD', 4, 17), | ||
misplacedDirective('onQuery', 'MUTATION', 7, 20), | ||
], | ||
); | ||
}); | ||
|
||
it('with misplaced variable definition directive', () => { | ||
// Need to parse with experimental flag | ||
const queryString = ` | ||
query Foo($var: Boolean @onField) { | ||
name | ||
} | ||
`; | ||
const errors = validate( | ||
testSchema, | ||
parse(queryString, { experimentalVariableDefinitionDirectives: true }), | ||
[KnownDirectives], | ||
); | ||
const expectedErrors = [ | ||
misplacedDirective('onField', 'VARIABLE_DEFINITION', 2, 31), | ||
]; | ||
expect(errors).to.have.length.of.at.least(1, 'Should not validate'); | ||
expect(errors).to.deep.equal(expectedErrors); | ||
}); | ||
|
||
describe('within SDL', () => { | ||
it('with directive defined inside SDL', () => { | ||
expectSDLErrors(` | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@mjmahone You can reuse this change from your previous PR:
https://github.com/graphql/graphql-js/pull/1422/files#diff-43fa06a89eafc57a60a0108a96f1c502R424