Skip to content

Commit

Permalink
[Spec] Move variable definition directive off of experimental flag (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjmahone authored Oct 4, 2018
1 parent 94b3844 commit 252e737
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 35 deletions.
6 changes: 2 additions & 4 deletions src/language/__tests__/parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,9 @@ describe('Parser', () => {
);
});

it('Experimental: parses variable definition directives', () => {
it('parses variable definition directives', () => {
expect(() =>
parse('query Foo($x: Boolean = false @bar) { field }', {
experimentalVariableDefinitionDirectives: true,
}),
parse('query Foo($x: Boolean = false @bar) { field }'),
).to.not.throw();
});

Expand Down
4 changes: 1 addition & 3 deletions src/language/__tests__/printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ describe('Printer: Query document', () => {
`);
});

it('Experimental: prints query with variable directives', () => {
it('prints query with variable directives', () => {
const queryAstWithVariableDirective = parse(
'query ($foo: TestType = {a: 123} @testDirective(if: true) @test) { id }',
{ experimentalVariableDefinitionDirectives: true },
);
expect(print(queryAstWithVariableDirective)).to.equal(dedent`
query ($foo: TestType = {a: 123} @testDirective(if: true) @test) {
Expand All @@ -94,7 +93,6 @@ describe('Printer: Query document', () => {
'fragment Foo($foo: TestType @test) on TestType @testDirective { id }',
{
experimentalFragmentVariables: true,
experimentalVariableDefinitionDirectives: true,
},
);
expect(print(queryAstWithVariableDirective)).to.equal(dedent`
Expand Down
25 changes: 1 addition & 24 deletions src/language/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,6 @@ export type ParseOptions = {
* future.
*/
experimentalFragmentVariables?: boolean,

/**
* EXPERIMENTAL:
*
* If enabled, the parser understands directives on variable definitions:
*
* query Foo($var: String = "abc" @variable_definition_directive) {
* ...
* }
*/
experimentalVariableDefinitionDirectives?: boolean,
};

/**
Expand Down Expand Up @@ -341,26 +330,14 @@ function parseVariableDefinitions(
*/
function parseVariableDefinition(lexer: Lexer<*>): VariableDefinitionNode {
const start = lexer.token;
if (lexer.options.experimentalVariableDefinitionDirectives) {
return {
kind: Kind.VARIABLE_DEFINITION,
variable: parseVariable(lexer),
type: (expect(lexer, TokenKind.COLON), parseTypeReference(lexer)),
defaultValue: skip(lexer, TokenKind.EQUALS)
? parseValueLiteral(lexer, true)
: undefined,
directives: parseDirectives(lexer, true),
loc: loc(lexer, start),
};
}

return {
kind: Kind.VARIABLE_DEFINITION,
variable: parseVariable(lexer),
type: (expect(lexer, TokenKind.COLON), parseTypeReference(lexer)),
defaultValue: skip(lexer, TokenKind.EQUALS)
? parseValueLiteral(lexer, true)
: undefined,
directives: parseDirectives(lexer, true),
loc: loc(lexer, start),
};
}
Expand Down
6 changes: 2 additions & 4 deletions src/validation/__tests__/KnownDirectives-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,14 @@ describe('Validate: Known directives', () => {
);
});

it('Experimental: with well placed variable definition directive', () => {
it('with well placed variable definition directive', () => {
expectPassesRule(
KnownDirectives,
`
query Foo($var: Boolean @onVariableDefinition) {
name
}
`,
{ experimentalVariableDefinitionDirectives: true },
);
});

Expand All @@ -177,7 +176,7 @@ describe('Validate: Known directives', () => {
);
});

it('Experimental: with misplaced variable definition directive', () => {
it('with misplaced variable definition directive', () => {
expectFailsRule(
KnownDirectives,
`
Expand All @@ -186,7 +185,6 @@ describe('Validate: Known directives', () => {
}
`,
[misplacedDirective('onField', 'VARIABLE_DEFINITION', 2, 31)],
{ experimentalVariableDefinitionDirectives: true },
);
});

Expand Down

0 comments on commit 252e737

Please sign in to comment.