Skip to content

Commit 1ac0bf8

Browse files
authored
Fixup: add Experimental note to variable-directive tests (#1458)
1 parent cb0097c commit 1ac0bf8

File tree

4 files changed

+50
-41
lines changed

4 files changed

+50
-41
lines changed

src/language/__tests__/parser-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe('Parser', () => {
106106
);
107107
});
108108

109-
it('parses variable definition directives', () => {
109+
it('Experimental: parses variable definition directives', () => {
110110
expect(() =>
111111
parse('query Foo($x: Boolean = false @bar) { field }', {
112112
experimentalVariableDefinitionDirectives: true,

src/language/__tests__/printer-test.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ describe('Printer: Query document', () => {
5656

5757
const queryAstWithArtifacts = parse(
5858
'query ($foo: TestType) @testDirective { id, name }',
59-
{ experimentalVariableDefinitionDirectives: true },
6059
);
6160
expect(print(queryAstWithArtifacts)).to.equal(dedent`
6261
query ($foo: TestType) @testDirective {
@@ -65,6 +64,18 @@ describe('Printer: Query document', () => {
6564
}
6665
`);
6766

67+
const mutationAstWithArtifacts = parse(
68+
'mutation ($foo: TestType) @testDirective { id, name }',
69+
);
70+
expect(print(mutationAstWithArtifacts)).to.equal(dedent`
71+
mutation ($foo: TestType) @testDirective {
72+
id
73+
name
74+
}
75+
`);
76+
});
77+
78+
it('Experimental: prints query with variable directives', () => {
6879
const queryAstWithVariableDirective = parse(
6980
'query ($foo: TestType = {a: 123} @testDirective(if: true) @test) { id }',
7081
{ experimentalVariableDefinitionDirectives: true },
@@ -74,14 +85,19 @@ describe('Printer: Query document', () => {
7485
id
7586
}
7687
`);
88+
});
7789

78-
const mutationAstWithArtifacts = parse(
79-
'mutation ($foo: TestType) @testDirective { id, name }',
90+
it('Experimental: prints fragment with variable directives', () => {
91+
const queryAstWithVariableDirective = parse(
92+
'fragment Foo($foo: TestType @test) on TestType @testDirective { id }',
93+
{
94+
experimentalFragmentVariables: true,
95+
experimentalVariableDefinitionDirectives: true,
96+
},
8097
);
81-
expect(print(mutationAstWithArtifacts)).to.equal(dedent`
82-
mutation ($foo: TestType) @testDirective {
98+
expect(print(queryAstWithVariableDirective)).to.equal(dedent`
99+
fragment Foo($foo: TestType @test) on TestType @testDirective {
83100
id
84-
name
85101
}
86102
`);
87103
});

src/validation/__tests__/KnownDirectives-test.js

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import { expect } from 'chai';
98
import { describe, it } from 'mocha';
10-
import { parse } from '../../language';
119
import { buildSchema } from '../../utilities';
12-
import { validate } from '../validate';
1310
import {
1411
expectPassesRule,
1512
expectFailsRule,
1613
expectSDLErrorsFromRule,
17-
testSchema,
1814
} from './harness';
1915

2016
import {
@@ -145,19 +141,16 @@ describe('Validate: Known directives', () => {
145141
);
146142
});
147143

148-
it('with well placed variable definition directive', () => {
149-
// Need to parse with experimental flag
150-
const queryString = `
144+
it('Experimental: with well placed variable definition directive', () => {
145+
expectPassesRule(
146+
KnownDirectives,
147+
`
151148
query Foo($var: Boolean @onVariableDefinition) {
152149
name
153150
}
154-
`;
155-
const errors = validate(
156-
testSchema,
157-
parse(queryString, { experimentalVariableDefinitionDirectives: true }),
158-
[KnownDirectives],
151+
`,
152+
{ experimentalVariableDefinitionDirectives: true },
159153
);
160-
expect(errors).to.deep.equal([], 'Should validate');
161154
});
162155

163156
it('with misplaced directives', () => {
@@ -182,23 +175,17 @@ describe('Validate: Known directives', () => {
182175
);
183176
});
184177

185-
it('with misplaced variable definition directive', () => {
186-
// Need to parse with experimental flag
187-
const queryString = `
178+
it('Experimental: with misplaced variable definition directive', () => {
179+
expectFailsRule(
180+
KnownDirectives,
181+
`
188182
query Foo($var: Boolean @onField) {
189183
name
190184
}
191-
`;
192-
const errors = validate(
193-
testSchema,
194-
parse(queryString, { experimentalVariableDefinitionDirectives: true }),
195-
[KnownDirectives],
185+
`,
186+
[misplacedDirective('onField', 'VARIABLE_DEFINITION', 2, 31)],
187+
{ experimentalVariableDefinitionDirectives: true },
196188
);
197-
const expectedErrors = [
198-
misplacedDirective('onField', 'VARIABLE_DEFINITION', 2, 31),
199-
];
200-
expect(errors).to.have.length.of.at.least(1, 'Should not validate');
201-
expect(errors).to.deep.equal(expectedErrors);
202189
});
203190

204191
describe('within SDL', () => {

src/validation/__tests__/harness.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,24 +381,30 @@ export const testSchema = new GraphQLSchema({
381381
],
382382
});
383383

384-
function expectValid(schema, rule, queryString) {
385-
const errors = validate(schema, parse(queryString), [rule]);
384+
function expectValid(schema, rule, queryString, options = {}) {
385+
const errors = validate(schema, parse(queryString, options), [rule]);
386386
expect(errors).to.deep.equal([], 'Should validate');
387387
}
388388

389-
function expectInvalid(schema, rule, queryString, expectedErrors) {
390-
const errors = validate(schema, parse(queryString), [rule]);
389+
function expectInvalid(
390+
schema,
391+
rule,
392+
queryString,
393+
expectedErrors,
394+
options = {},
395+
) {
396+
const errors = validate(schema, parse(queryString, options), [rule]);
391397
expect(errors).to.have.length.of.at.least(1, 'Should not validate');
392398
expect(errors).to.deep.equal(expectedErrors);
393399
return errors;
394400
}
395401

396-
export function expectPassesRule(rule, queryString) {
397-
return expectValid(testSchema, rule, queryString);
402+
export function expectPassesRule(rule, queryString, options = {}) {
403+
return expectValid(testSchema, rule, queryString, options);
398404
}
399405

400-
export function expectFailsRule(rule, queryString, errors) {
401-
return expectInvalid(testSchema, rule, queryString, errors);
406+
export function expectFailsRule(rule, queryString, errors, options = {}) {
407+
return expectInvalid(testSchema, rule, queryString, errors, options);
402408
}
403409

404410
export function expectPassesRuleWithSchema(schema, rule, queryString) {

0 commit comments

Comments
 (0)