We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1b6824b commit 0aa78f6Copy full SHA for 0aa78f6
src/language/ast.js
@@ -268,6 +268,7 @@ export type TypeSystemDefinition = SchemaDefinition
268
export type SchemaDefinition = {
269
kind: 'SchemaDefinition';
270
loc?: ?Location;
271
+ directives: Array<Directive>;
272
operationTypes: Array<OperationTypeDefinition>;
273
}
274
src/language/parser.js
@@ -701,13 +701,14 @@ function parseTypeSystemDefinition(parser: Parser): TypeSystemDefinition {
701
702
703
/**
704
- * SchemaDefinition : schema { OperationTypeDefinition+ }
+ * SchemaDefinition : schema Directives? { OperationTypeDefinition+ }
705
*
706
* OperationTypeDefinition : OperationType : NamedType
707
*/
708
function parseSchemaDefinition(parser: Parser): SchemaDefinition {
709
const start = parser.token.start;
710
expectKeyword(parser, 'schema');
711
+ const directives = parseDirectives(parser);
712
const operationTypes = many(
713
parser,
714
TokenKind.BRACE_L,
@@ -716,6 +717,7 @@ function parseSchemaDefinition(parser: Parser): SchemaDefinition {
716
717
);
718
return {
719
kind: SCHEMA_DEFINITION,
720
+ directives,
721
operationTypes,
722
loc: loc(parser, start),
723
};
src/language/printer.js
@@ -94,8 +94,12 @@ const printDocASTReducer = {
94
95
// Type System Definitions
96
97
- SchemaDefinition: ({ operationTypes }) =>
98
- 'schema ' + block(operationTypes),
+ SchemaDefinition: ({ directives, operationTypes }) =>
+ join([
99
+ 'schema',
100
+ join(directives, ' '),
101
+ block(operationTypes),
102
+ ], ' '),
103
104
OperationTypeDefinition: ({ operation, type }) =>
105
operation + ': ' + type,
src/language/visitor.js
@@ -38,7 +38,7 @@ export const QueryDocumentKeys = {
38
ListType: [ 'type' ],
39
NonNullType: [ 'type' ],
40
41
- SchemaDefinition: [ 'operationTypes' ],
+ SchemaDefinition: [ 'directives', 'operationTypes' ],
42
OperationTypeDefinition: [ 'type' ],
43
44
ScalarTypeDefinition: [ 'name', 'directives' ],
src/type/directives.js
@@ -28,6 +28,7 @@ export const DirectiveLocation = {
28
FRAGMENT_SPREAD: 'FRAGMENT_SPREAD',
29
INLINE_FRAGMENT: 'INLINE_FRAGMENT',
30
// Schema Definitions
31
+ SCHEMA: 'SCHEMA',
32
SCALAR: 'SCALAR',
33
OBJECT: 'OBJECT',
34
FIELD_DEFINITION: 'FIELD_DEFINITION',
src/type/introspection.js
@@ -149,6 +149,10 @@ export const __DirectiveLocation = new GraphQLEnumType({
149
value: DirectiveLocation.INLINE_FRAGMENT,
150
description: 'Location adjacent to an inline fragment.'
151
},
152
+ SCHEMA: {
153
+ value: DirectiveLocation.SCHEMA,
154
+ description: 'Location adjacent to a schema definition.'
155
+ },
156
SCALAR: {
157
value: DirectiveLocation.SCALAR,
158
description: 'Location adjacent to a scalar definition.'
src/utilities/__tests__/schemaPrinter-test.js
@@ -620,6 +620,7 @@ enum __DirectiveLocation {
620
FRAGMENT_DEFINITION
621
FRAGMENT_SPREAD
622
INLINE_FRAGMENT
623
+ SCHEMA
624
SCALAR
625
OBJECT
626
FIELD_DEFINITION
src/validation/__tests__/KnownDirectives-test.js
@@ -149,6 +149,10 @@ describe('Validate: Known directives', () => {
input MyInput @onInputObject {
myField: Int @onInputFieldDefinition
+
+ schema @onSchema {
+ query: MyQuery
+ }
`);
});
@@ -173,6 +177,10 @@ describe('Validate: Known directives', () => {
173
177
input MyInput @onEnum {
174
178
myField: Int @onArgumentDefinition
175
179
180
181
+ schema @onObject {
182
183
176
184
`, [
185
misplacedDirective('onInterface', 'OBJECT', 2, 43),
186
misplacedDirective('onInputFieldDefinition', 'ARGUMENT_DEFINITION', 3, 30),
@@ -186,6 +194,7 @@ describe('Validate: Known directives', () => {
194
misplacedDirective('onUnion', 'ENUM_VALUE', 15, 20),
187
195
misplacedDirective('onEnum', 'INPUT_OBJECT', 18, 23),
188
196
misplacedDirective('onArgumentDefinition', 'INPUT_FIELD_DEFINITION', 19, 24),
197
+ misplacedDirective('onObject', 'SCHEMA', 22, 16),
189
198
]);
190
199
191
200
src/validation/__tests__/harness.js
@@ -336,6 +336,10 @@ export const testSchema = new GraphQLSchema({
336
name: 'onInlineFragment',
337
locations: [ 'INLINE_FRAGMENT' ],
338
}),
339
+ new GraphQLDirective({
340
+ name: 'onSchema',
341
+ locations: [ 'SCHEMA' ],
342
+ }),
343
new GraphQLDirective({
344
name: 'onScalar',
345
locations: [ 'SCALAR' ],
src/validation/rules/KnownDirectives.js
@@ -17,15 +17,16 @@ import {
17
FRAGMENT_SPREAD,
18
INLINE_FRAGMENT,
19
OPERATION_DEFINITION,
20
- ENUM_TYPE_DEFINITION,
21
- ENUM_VALUE_DEFINITION,
+ SCHEMA_DEFINITION,
+ SCALAR_TYPE_DEFINITION,
22
+ OBJECT_TYPE_DEFINITION,
23
FIELD_DEFINITION,
- INPUT_OBJECT_TYPE_DEFINITION,
24
INPUT_VALUE_DEFINITION,
25
INTERFACE_TYPE_DEFINITION,
26
- OBJECT_TYPE_DEFINITION,
27
- SCALAR_TYPE_DEFINITION,
UNION_TYPE_DEFINITION,
+ ENUM_TYPE_DEFINITION,
+ ENUM_VALUE_DEFINITION,
+ INPUT_OBJECT_TYPE_DEFINITION,
} from '../../language/kinds';
import { DirectiveLocation } from '../../type/directives';
@@ -91,6 +92,7 @@ function getDirectiveLocationForASTPath(ancestors) {
91
92
case FRAGMENT_SPREAD: return DirectiveLocation.FRAGMENT_SPREAD;
93
case INLINE_FRAGMENT: return DirectiveLocation.INLINE_FRAGMENT;
case FRAGMENT_DEFINITION: return DirectiveLocation.FRAGMENT_DEFINITION;
+ case SCHEMA_DEFINITION: return DirectiveLocation.SCHEMA;
case SCALAR_TYPE_DEFINITION: return DirectiveLocation.SCALAR;
case OBJECT_TYPE_DEFINITION: return DirectiveLocation.OBJECT;
case FIELD_DEFINITION: return DirectiveLocation.FIELD_DEFINITION;
0 commit comments