Skip to content

Commit c86e332

Browse files
committed
Add ParseOption.experimentalDirectivesOnDirectiveDefinition
1 parent 519cd49 commit c86e332

6 files changed

Lines changed: 27 additions & 16 deletions

File tree

src/__testUtils__/kitchenSinkSDL.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,4 @@ extend schema @onSchema
161161
extend schema @onSchema {
162162
subscription: SubscriptionType
163163
}
164-
165-
directive @myDirective @onDirective on OBJECT | FIELD_DEFINITION
166-
167-
extend directive @myDirective @onDirective2
168164
`;

src/language/__tests__/schema-printer-test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,6 @@ describe('Printer: SDL document', () => {
178178
extend schema @onSchema {
179179
subscription: SubscriptionType
180180
}
181-
182-
directive @myDirective @onDirective on OBJECT | FIELD_DEFINITION
183-
184-
extend directive @myDirective @onDirective2
185181
`);
186182
});
187183
});

src/language/parser.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ export interface ParseOptions {
113113
*/
114114
allowLegacyFragmentVariables?: boolean;
115115

116+
/**
117+
* EXPERIMENTAL:
118+
*
119+
* If enabled, the parser will parse directives on directive definitions.
120+
* This syntax is not part of the GraphQL specification and may change.
121+
*
122+
* ```graphql
123+
* directive @foo @bar on FIELD
124+
* ```
125+
*/
126+
experimentalDirectivesOnDirectiveDefinitions?: boolean;
127+
116128
/**
117129
* You may override the Lexer class used to lex the source; this is used by
118130
* schema coordinates to introduce a lexer with a restricted syntax.
@@ -1207,7 +1219,12 @@ export class Parser {
12071219
case 'input':
12081220
return this.parseInputObjectTypeExtension();
12091221
case 'directive':
1210-
return this.parseDirectiveDefinitionExtension();
1222+
if (
1223+
this._options.experimentalDirectivesOnDirectiveDefinitions === true
1224+
) {
1225+
return this.parseDirectiveDefinitionExtension();
1226+
}
1227+
break;
12111228
}
12121229
}
12131230

@@ -1420,7 +1437,10 @@ export class Parser {
14201437
this.expectToken(TokenKind.AT);
14211438
const name = this.parseName();
14221439
const args = this.parseArgumentDefs();
1423-
const directives = this.parseConstDirectives();
1440+
const directives =
1441+
this._options.experimentalDirectivesOnDirectiveDefinitions === true
1442+
? this.parseConstDirectives()
1443+
: [];
14241444
const repeatable = this.expectOptionalKeyword('repeatable');
14251445
this.expectKeyword('on');
14261446
const locations = this.parseDirectiveLocations();

src/type/__tests__/introspection-test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { describe, it } from 'mocha';
33

44
import { expectJSON } from '../../__testUtils__/expectJSON';
55

6-
import { buildSchema } from '../../utilities/buildASTSchema';
6+
import { buildASTSchema, buildSchema } from '../../utilities/buildASTSchema';
77
import { getIntrospectionQuery } from '../../utilities/getIntrospectionQuery';
88

99
import { graphqlSync } from '../../graphql';
1010

1111
import type { GraphQLResolveInfo } from '../definition';
12+
import { parse } from '../..';
1213

1314
describe('Introspection', () => {
1415
it('executes an introspection query', () => {
@@ -1798,13 +1799,13 @@ describe('Introspection', () => {
17981799
});
17991800

18001801
it('identifies deprecated directives', () => {
1801-
const schema = buildSchema(`
1802+
const schema = buildASTSchema(parse(`
18021803
type Query {
18031804
someField: String
18041805
}
18051806
directive @isNotDeprecated on FIELD_DEFINITION
18061807
directive @isDeprecated @deprecated(reason: "No longer supported") on FIELD_DEFINITION
1807-
`);
1808+
`, { experimentalDirectivesOnDirectiveDefinitions: true }));
18081809

18091810
const source = `
18101811
{

src/utilities/__tests__/extendSchema-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ describe('extendSchema', () => {
13231323
const schema = buildSchema('directive @isDeprecated on FIELD_DEFINITION');
13241324
const extendAST = parse(`
13251325
extend directive @isDeprecated @deprecated(reason: "use another directive")
1326-
`);
1326+
`, { experimentalDirectivesOnDirectiveDefinitions: true });
13271327
const extendedSchema = extendSchema(schema, extendAST);
13281328

13291329
const someDirective = assertDirective(

src/validation/__tests__/KnownDirectivesRule-test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,6 @@ describe('Validate: Known directives', () => {
352352
extend schema @onSchema
353353
354354
directive @myDirective on OBJECT
355-
356-
extend directive @myDirective @onDirective
357355
`,
358356
schemaWithSDLDirectives,
359357
);

0 commit comments

Comments
 (0)