Skip to content

Update to match SDL changes #1102

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
Dec 4, 2017
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
15 changes: 5 additions & 10 deletions src/execution/__tests__/executor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,11 +965,11 @@ describe('Execute: Handles basic execution tasks', () => {
]);
});

it('fails to execute a query containing a type definition', async () => {
it('executes ignoring invalid non-executable definitions', async () => {
const query = parse(`
{ foo }

type Query { foo: String }
type Query { bar: String }
`);

const schema = new GraphQLSchema({
Expand All @@ -983,14 +983,9 @@ describe('Execute: Handles basic execution tasks', () => {

const result = await execute(schema, query);
expect(result).to.deep.equal({
errors: [
{
message: 'GraphQL cannot execute a request containing a ' +
'ObjectTypeDefinition.',
locations: [ { line: 4, column: 7 } ],
path: undefined,
}
]
data: {
foo: null,
},
});
});

Expand Down
4 changes: 0 additions & 4 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,6 @@ export function buildExecutionContext(
case Kind.FRAGMENT_DEFINITION:
fragments[definition.name.value] = definition;
break;
default: throw new GraphQLError(
`GraphQL cannot execute a request containing a ${definition.kind}.`,
[ definition ]
);
}
});
if (!operation) {
Expand Down
10 changes: 4 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ export {
// "Enum" of Type Kinds
TypeKind,

// "Enum" of Directive Locations
DirectiveLocation,

// Scalars
GraphQLInt,
GraphQLFloat,
Expand Down Expand Up @@ -113,8 +110,6 @@ export {
} from './type';

export type {
DirectiveLocationEnum,

GraphQLType,
GraphQLInputType,
GraphQLOutputType,
Expand Down Expand Up @@ -173,6 +168,7 @@ export {
getVisitFn,
Kind,
TokenKind,
DirectiveLocation,
BREAK,
} from './language';

Expand Down Expand Up @@ -226,8 +222,10 @@ export type {
EnumTypeDefinitionNode,
EnumValueDefinitionNode,
InputObjectTypeDefinitionNode,
TypeExtensionDefinitionNode,
TypeExtensionNode,
ObjectTypeExtensionNode,
DirectiveDefinitionNode,
DirectiveLocationEnum,
} from './language';


Expand Down
4 changes: 1 addition & 3 deletions src/language/__tests__/schema-kitchen-sink.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ extend type Foo {
seven(argument: [String]): Type
}

extend type Foo @onType {}

type NoFields {}
extend type Foo @onType

directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

Expand Down
97 changes: 72 additions & 25 deletions src/language/__tests__/schema-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,17 @@ extend type Hello {
kind: 'Document',
definitions: [
{
kind: 'TypeExtensionDefinition',
definition: {
kind: 'ObjectTypeDefinition',
name: nameNode('Hello', { start: 13, end: 18 }),
interfaces: [],
directives: [],
fields: [
fieldNode(
nameNode('world', { start: 23, end: 28 }),
typeNode('String', { start: 30, end: 36 }),
{ start: 23, end: 36 }
)
],
loc: { start: 8, end: 38 },
},
kind: 'ObjectTypeExtension',
name: nameNode('Hello', { start: 13, end: 18 }),
interfaces: [],
directives: [],
fields: [
fieldNode(
nameNode('world', { start: 23, end: 28 }),
typeNode('String', { start: 30, end: 36 }),
{ start: 23, end: 36 }
)
],
loc: { start: 1, end: 38 },
}
],
Expand All @@ -177,13 +173,45 @@ extend type Hello {
expect(printJson(doc)).to.equal(printJson(expected));
});

it('Extension without fields', () => {
const body = 'extend type Hello implements Greeting';
const doc = parse(body);
const expected = {
kind: 'Document',
definitions: [
{
kind: 'ObjectTypeExtension',
name: nameNode('Hello', { start: 12, end: 17 }),
interfaces: [ typeNode('Greeting', { start: 29, end: 37 }) ],
directives: [],
fields: [],
loc: { start: 0, end: 37 },
}
],
loc: { start: 0, end: 37 }
};
expect(printJson(doc)).to.equal(printJson(expected));
});

it('Extension without anything throws', () => {
expect(() => parse(`
extend type Hello
`)).to.throw('Syntax Error GraphQL request (3:5) Unexpected <EOF>');
});

it('Extension do not include descriptions', () => {
expect(() => parse(`
"Description"
extend type Hello {
world: String
}
`)).to.throw('Syntax Error GraphQL request (2:7)');
`)).to.throw('Syntax Error GraphQL request (3:7)');

expect(() => parse(`
extend "Description" type Hello {
world: String
}
`)).to.throw('Syntax Error GraphQL request (2:14)');
});

it('Simple non-null type', () => {
Expand Down Expand Up @@ -219,9 +247,8 @@ type Hello {
expect(printJson(doc)).to.equal(printJson(expected));
});


it('Simple type inheriting interface', () => {
const body = 'type Hello implements World { }';
const body = 'type Hello implements World { field: String }';
const doc = parse(body);
const expected = {
kind: 'Document',
Expand All @@ -231,17 +258,23 @@ type Hello {
name: nameNode('Hello', { start: 5, end: 10 }),
interfaces: [ typeNode('World', { start: 22, end: 27 }) ],
directives: [],
fields: [],
loc: { start: 0, end: 31 },
fields: [
fieldNode(
nameNode('field', { start: 30, end: 35 }),
typeNode('String', { start: 37, end: 43 }),
{ start: 30, end: 43 }
)
],
loc: { start: 0, end: 45 },
}
],
loc: { start: 0, end: 31 },
loc: { start: 0, end: 45 },
};
expect(printJson(doc)).to.equal(printJson(expected));
});

it('Simple type inheriting multiple interfaces', () => {
const body = 'type Hello implements Wo, rld { }';
const body = 'type Hello implements Wo, rld { field: String }';
const doc = parse(body);
const expected = {
kind: 'Document',
Expand All @@ -254,11 +287,17 @@ type Hello {
typeNode('rld', { start: 26, end: 29 })
],
directives: [],
fields: [],
loc: { start: 0, end: 33 },
fields: [
fieldNode(
nameNode('field', { start: 32, end: 37 }),
typeNode('String', { start: 39, end: 45 }),
{ start: 32, end: 45 }
)
],
loc: { start: 0, end: 47 },
}
],
loc: { start: 0, end: 33 },
loc: { start: 0, end: 47 },
};
expect(printJson(doc)).to.equal(printJson(expected));
});
Expand Down Expand Up @@ -632,4 +671,12 @@ input Hello {
expect(() => parse(body)).to.throw('Error');
});

it('Directive with incorrect locations', () => {
expect(() => parse(`
directive @foo on FIELD | INCORRECT_LOCATION
`)).to.throw(
'Syntax Error GraphQL request (2:33) Unexpected Name "INCORRECT_LOCATION"'
);
});

});
4 changes: 1 addition & 3 deletions src/language/__tests__/schema-printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ extend type Foo {
seven(argument: [String]): Type
}

extend type Foo @onType {}

type NoFields {}
extend type Foo @onType

directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

Expand Down
26 changes: 21 additions & 5 deletions src/language/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export type ASTNode =
| EnumTypeDefinitionNode
| EnumValueDefinitionNode
| InputObjectTypeDefinitionNode
| TypeExtensionDefinitionNode
| ObjectTypeExtensionNode
| DirectiveDefinitionNode;

// Name
Expand Down Expand Up @@ -363,12 +363,13 @@ export type NonNullTypeNode = {
type: NamedTypeNode | ListTypeNode;
};


// Type System Definition

export type TypeSystemDefinitionNode =
| SchemaDefinitionNode
| TypeDefinitionNode
| TypeExtensionDefinitionNode
| TypeExtensionNode
| DirectiveDefinitionNode;

export type SchemaDefinitionNode = {
Expand All @@ -385,6 +386,9 @@ export type OperationTypeDefinitionNode = {
type: NamedTypeNode;
};


// Type Definition

export type TypeDefinitionNode =
| ScalarTypeDefinitionNode
| ObjectTypeDefinitionNode
Expand Down Expand Up @@ -475,12 +479,24 @@ export type InputObjectTypeDefinitionNode = {
fields: Array<InputValueDefinitionNode>;
};

export type TypeExtensionDefinitionNode = {
kind: 'TypeExtensionDefinition';

// Type Extensions

export type TypeExtensionNode =
| ObjectTypeExtensionNode;

export type ObjectTypeExtensionNode = {
kind: 'ObjectTypeExtension';
loc?: Location;
definition: ObjectTypeDefinitionNode;
name: NameNode;
interfaces?: ?Array<NamedTypeNode>;
directives?: ?Array<DirectiveNode>;
fields?: ?Array<FieldDefinitionNode>;
};


// Directive Definitions

export type DirectiveDefinitionNode = {
kind: 'DirectiveDefinition';
loc?: Location;
Expand Down
39 changes: 39 additions & 0 deletions src/language/directiveLocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

/**
* The set of allowed directive location values.
*/
export const DirectiveLocation = {
// Request Definitions
QUERY: 'QUERY',
MUTATION: 'MUTATION',
SUBSCRIPTION: 'SUBSCRIPTION',
FIELD: 'FIELD',
FRAGMENT_DEFINITION: 'FRAGMENT_DEFINITION',
FRAGMENT_SPREAD: 'FRAGMENT_SPREAD',
INLINE_FRAGMENT: 'INLINE_FRAGMENT',
// Type System Definitions
SCHEMA: 'SCHEMA',
SCALAR: 'SCALAR',
OBJECT: 'OBJECT',
FIELD_DEFINITION: 'FIELD_DEFINITION',
ARGUMENT_DEFINITION: 'ARGUMENT_DEFINITION',
INTERFACE: 'INTERFACE',
UNION: 'UNION',
ENUM: 'ENUM',
ENUM_VALUE: 'ENUM_VALUE',
INPUT_OBJECT: 'INPUT_OBJECT',
INPUT_FIELD_DEFINITION: 'INPUT_FIELD_DEFINITION',
};

/**
* The enum type representing the directive location values.
*/
export type DirectiveLocationEnum = $Keys<typeof DirectiveLocation>;
6 changes: 5 additions & 1 deletion src/language/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export type {
EnumTypeDefinitionNode,
EnumValueDefinitionNode,
InputObjectTypeDefinitionNode,
TypeExtensionDefinitionNode,
TypeExtensionNode,
ObjectTypeExtensionNode,
DirectiveDefinitionNode,
} from './ast';

export { DirectiveLocation } from './directiveLocation';
export type { DirectiveLocationEnum } from './directiveLocation';
2 changes: 1 addition & 1 deletion src/language/kinds.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const INPUT_OBJECT_TYPE_DEFINITION = 'InputObjectTypeDefinition';

// Type Extensions

export const TYPE_EXTENSION_DEFINITION = 'TypeExtensionDefinition';
export const OBJECT_TYPE_EXTENSION = 'ObjectTypeExtension';

// Directive Definitions

Expand Down
Loading