Skip to content
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
26 changes: 3 additions & 23 deletions src/utilities/__tests__/buildASTSchema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,26 +809,6 @@ describe('Schema Builder', () => {
});

describe('Failures', () => {
it('Allows only a single schema definition', () => {
const body = dedent`
schema {
query: Hello
}

schema {
query: Hello
}

type Hello {
bar: Bar
}
`;
const doc = parse(body);
expect(() => buildASTSchema(doc)).to.throw(
'Must provide only one schema definition.',
);
});

it('Allows only a single query type', () => {
const body = dedent`
schema {
Expand All @@ -837,7 +817,7 @@ describe('Failures', () => {
}

type Hello {
bar: Bar
bar: String
}

type Yellow {
Expand All @@ -859,7 +839,7 @@ describe('Failures', () => {
}

type Hello {
bar: Bar
bar: String
}

type Yellow {
Expand All @@ -881,7 +861,7 @@ describe('Failures', () => {
}

type Hello {
bar: Bar
bar: String
}

type Yellow {
Expand Down
15 changes: 0 additions & 15 deletions src/utilities/__tests__/extendSchema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1288,21 +1288,6 @@ describe('extendSchema', () => {
expect(schema.getMutationType()).to.equal(null);
});

it('does not allow overriding schema within an extension', () => {
const sdl = `
schema {
mutation: Mutation
}

type Mutation {
doSomething: String
}
`;
expect(() => extendTestSchema(sdl)).to.throw(
'Cannot define a new schema within a schema extension.',
);
});

it('adds schema definition missing in the original schema', () => {
let schema = new GraphQLSchema({
directives: [FooDirective],
Expand Down
158 changes: 102 additions & 56 deletions src/validation/__tests__/KnownDirectives-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,46 +191,92 @@ describe('Validate: Known directives', () => {
`).to.deep.equal([]);
});

it('with well placed directives', () => {
it('with directive defined in schema extension', () => {
const schema = buildSchema(`
type Query {
foo: String
}
`);
expectSDLErrors(
`
type MyObj implements MyInterface @onObject {
myField(myArg: Int @onArgumentDefinition): String @onFieldDefinition
}
directive @test on OBJECT

extend type MyObj @onObject
extend type Query @test
`,
schema,
).to.deep.equal([]);
});

scalar MyScalar @onScalar
it('with directive used in schema extension', () => {
const schema = buildSchema(`
directive @test on OBJECT

extend scalar MyScalar @onScalar
type Query {
foo: String
}
`);
expectSDLErrors(
`
extend type Query @test
`,
schema,
).to.deep.equal([]);
});

interface MyInterface @onInterface {
myField(myArg: Int @onArgumentDefinition): String @onFieldDefinition
it('with unknown directive in schema extension', () => {
const schema = buildSchema(`
type Query {
foo: String
}
`);
expectSDLErrors(
`
extend type Query @unknown
`,
schema,
).to.deep.equal([unknownDirective('unknown', 2, 29)]);
});

extend interface MyInterface @onInterface
it('with well placed directives', () => {
expectSDLErrors(
`
type MyObj implements MyInterface @onObject {
myField(myArg: Int @onArgumentDefinition): String @onFieldDefinition
}

union MyUnion @onUnion = MyObj | Other
extend type MyObj @onObject

extend union MyUnion @onUnion
scalar MyScalar @onScalar

enum MyEnum @onEnum {
MY_VALUE @onEnumValue
}
extend scalar MyScalar @onScalar

extend enum MyEnum @onEnum
interface MyInterface @onInterface {
myField(myArg: Int @onArgumentDefinition): String @onFieldDefinition
}

input MyInput @onInputObject {
myField: Int @onInputFieldDefinition
}
extend interface MyInterface @onInterface

extend input MyInput @onInputObject
union MyUnion @onUnion = MyObj | Other

schema @onSchema {
query: MyQuery
}
extend union MyUnion @onUnion

enum MyEnum @onEnum {
MY_VALUE @onEnumValue
}

extend enum MyEnum @onEnum

input MyInput @onInputObject {
myField: Int @onInputFieldDefinition
}

extend input MyInput @onInputObject

schema @onSchema {
query: MyQuery
}

extend schema @onSchema
extend schema @onSchema
`,
schemaWithSDLDirectives,
).to.deep.equal([]);
Expand All @@ -239,63 +285,63 @@ describe('Validate: Known directives', () => {
it('with misplaced directives', () => {
expectSDLErrors(
`
type MyObj implements MyInterface @onInterface {
myField(myArg: Int @onInputFieldDefinition): String @onInputFieldDefinition
}
type MyObj implements MyInterface @onInterface {
myField(myArg: Int @onInputFieldDefinition): String @onInputFieldDefinition
}

scalar MyScalar @onEnum
scalar MyScalar @onEnum

interface MyInterface @onObject {
myField(myArg: Int @onInputFieldDefinition): String @onInputFieldDefinition
}
interface MyInterface @onObject {
myField(myArg: Int @onInputFieldDefinition): String @onInputFieldDefinition
}

union MyUnion @onEnumValue = MyObj | Other
union MyUnion @onEnumValue = MyObj | Other

enum MyEnum @onScalar {
MY_VALUE @onUnion
}
enum MyEnum @onScalar {
MY_VALUE @onUnion
}

input MyInput @onEnum {
myField: Int @onArgumentDefinition
}
input MyInput @onEnum {
myField: Int @onArgumentDefinition
}

schema @onObject {
query: MyQuery
}
schema @onObject {
query: MyQuery
}

extend schema @onObject
extend schema @onObject
`,
schemaWithSDLDirectives,
).to.deep.equal([
misplacedDirective('onInterface', 'OBJECT', 2, 43),
misplacedDirective('onInterface', 'OBJECT', 2, 45),
misplacedDirective(
'onInputFieldDefinition',
'ARGUMENT_DEFINITION',
3,
30,
32,
),
misplacedDirective('onInputFieldDefinition', 'FIELD_DEFINITION', 3, 63),
misplacedDirective('onEnum', 'SCALAR', 6, 25),
misplacedDirective('onObject', 'INTERFACE', 8, 31),
misplacedDirective('onInputFieldDefinition', 'FIELD_DEFINITION', 3, 65),
misplacedDirective('onEnum', 'SCALAR', 6, 27),
misplacedDirective('onObject', 'INTERFACE', 8, 33),
misplacedDirective(
'onInputFieldDefinition',
'ARGUMENT_DEFINITION',
9,
30,
32,
),
misplacedDirective('onInputFieldDefinition', 'FIELD_DEFINITION', 9, 63),
misplacedDirective('onEnumValue', 'UNION', 12, 23),
misplacedDirective('onScalar', 'ENUM', 14, 21),
misplacedDirective('onUnion', 'ENUM_VALUE', 15, 20),
misplacedDirective('onEnum', 'INPUT_OBJECT', 18, 23),
misplacedDirective('onInputFieldDefinition', 'FIELD_DEFINITION', 9, 65),
misplacedDirective('onEnumValue', 'UNION', 12, 25),
misplacedDirective('onScalar', 'ENUM', 14, 23),
misplacedDirective('onUnion', 'ENUM_VALUE', 15, 22),
misplacedDirective('onEnum', 'INPUT_OBJECT', 18, 25),
misplacedDirective(
'onArgumentDefinition',
'INPUT_FIELD_DEFINITION',
19,
24,
26,
),
misplacedDirective('onObject', 'SCHEMA', 22, 16),
misplacedDirective('onObject', 'SCHEMA', 26, 23),
misplacedDirective('onObject', 'SCHEMA', 22, 18),
misplacedDirective('onObject', 'SCHEMA', 26, 25),
]);
});
});
Expand Down
Loading