diff --git a/src/language/__tests__/parser-test.js b/src/language/__tests__/parser-test.js index 5aedf08ebf..c1e9ceca92 100644 --- a/src/language/__tests__/parser-test.js +++ b/src/language/__tests__/parser-test.js @@ -106,7 +106,7 @@ describe('Parser', () => { ); }); - it('parses variable definition directives', () => { + it('Experimental: parses variable definition directives', () => { expect(() => parse('query Foo($x: Boolean = false @bar) { field }', { experimentalVariableDefinitionDirectives: true, diff --git a/src/language/__tests__/printer-test.js b/src/language/__tests__/printer-test.js index 32b303e6a9..4f33ba8f19 100644 --- a/src/language/__tests__/printer-test.js +++ b/src/language/__tests__/printer-test.js @@ -56,7 +56,6 @@ describe('Printer: Query document', () => { const queryAstWithArtifacts = parse( 'query ($foo: TestType) @testDirective { id, name }', - { experimentalVariableDefinitionDirectives: true }, ); expect(print(queryAstWithArtifacts)).to.equal(dedent` query ($foo: TestType) @testDirective { @@ -65,6 +64,18 @@ describe('Printer: Query document', () => { } `); + const mutationAstWithArtifacts = parse( + 'mutation ($foo: TestType) @testDirective { id, name }', + ); + expect(print(mutationAstWithArtifacts)).to.equal(dedent` + mutation ($foo: TestType) @testDirective { + id + name + } + `); + }); + + it('Experimental: prints query with variable directives', () => { const queryAstWithVariableDirective = parse( 'query ($foo: TestType = {a: 123} @testDirective(if: true) @test) { id }', { experimentalVariableDefinitionDirectives: true }, @@ -74,14 +85,19 @@ describe('Printer: Query document', () => { id } `); + }); - const mutationAstWithArtifacts = parse( - 'mutation ($foo: TestType) @testDirective { id, name }', + it('Experimental: prints fragment with variable directives', () => { + const queryAstWithVariableDirective = parse( + 'fragment Foo($foo: TestType @test) on TestType @testDirective { id }', + { + experimentalFragmentVariables: true, + experimentalVariableDefinitionDirectives: true, + }, ); - expect(print(mutationAstWithArtifacts)).to.equal(dedent` - mutation ($foo: TestType) @testDirective { + expect(print(queryAstWithVariableDirective)).to.equal(dedent` + fragment Foo($foo: TestType @test) on TestType @testDirective { id - name } `); }); diff --git a/src/validation/__tests__/KnownDirectives-test.js b/src/validation/__tests__/KnownDirectives-test.js index e210b3a695..9225db5f81 100644 --- a/src/validation/__tests__/KnownDirectives-test.js +++ b/src/validation/__tests__/KnownDirectives-test.js @@ -5,16 +5,12 @@ * 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 { @@ -145,19 +141,16 @@ describe('Validate: Known directives', () => { ); }); - it('with well placed variable definition directive', () => { - // Need to parse with experimental flag - const queryString = ` + it('Experimental: with well placed variable definition directive', () => { + expectPassesRule( + KnownDirectives, + ` query Foo($var: Boolean @onVariableDefinition) { name } - `; - const errors = validate( - testSchema, - parse(queryString, { experimentalVariableDefinitionDirectives: true }), - [KnownDirectives], + `, + { experimentalVariableDefinitionDirectives: true }, ); - expect(errors).to.deep.equal([], 'Should validate'); }); it('with misplaced directives', () => { @@ -182,23 +175,17 @@ describe('Validate: Known directives', () => { ); }); - it('with misplaced variable definition directive', () => { - // Need to parse with experimental flag - const queryString = ` + it('Experimental: with misplaced variable definition directive', () => { + expectFailsRule( + KnownDirectives, + ` query Foo($var: Boolean @onField) { name } - `; - const errors = validate( - testSchema, - parse(queryString, { experimentalVariableDefinitionDirectives: true }), - [KnownDirectives], + `, + [misplacedDirective('onField', 'VARIABLE_DEFINITION', 2, 31)], + { experimentalVariableDefinitionDirectives: true }, ); - 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', () => { diff --git a/src/validation/__tests__/harness.js b/src/validation/__tests__/harness.js index e8c4e71c1e..a3611d3a76 100644 --- a/src/validation/__tests__/harness.js +++ b/src/validation/__tests__/harness.js @@ -381,24 +381,30 @@ export const testSchema = new GraphQLSchema({ ], }); -function expectValid(schema, rule, queryString) { - const errors = validate(schema, parse(queryString), [rule]); +function expectValid(schema, rule, queryString, options = {}) { + const errors = validate(schema, parse(queryString, options), [rule]); expect(errors).to.deep.equal([], 'Should validate'); } -function expectInvalid(schema, rule, queryString, expectedErrors) { - const errors = validate(schema, parse(queryString), [rule]); +function expectInvalid( + schema, + rule, + queryString, + expectedErrors, + options = {}, +) { + const errors = validate(schema, parse(queryString, options), [rule]); expect(errors).to.have.length.of.at.least(1, 'Should not validate'); expect(errors).to.deep.equal(expectedErrors); return errors; } -export function expectPassesRule(rule, queryString) { - return expectValid(testSchema, rule, queryString); +export function expectPassesRule(rule, queryString, options = {}) { + return expectValid(testSchema, rule, queryString, options); } -export function expectFailsRule(rule, queryString, errors) { - return expectInvalid(testSchema, rule, queryString, errors); +export function expectFailsRule(rule, queryString, errors, options = {}) { + return expectInvalid(testSchema, rule, queryString, errors, options); } export function expectPassesRuleWithSchema(schema, rule, queryString) {