Skip to content

Fixup: add Experimental note to variable-directive tests #1458

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 1 commit into from
Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/language/__tests__/parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 22 additions & 6 deletions src/language/__tests__/printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 },
Expand All @@ -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
}
`);
});
Expand Down
39 changes: 13 additions & 26 deletions src/validation/__tests__/KnownDirectives-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down
22 changes: 14 additions & 8 deletions src/validation/__tests__/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down