Skip to content

Commit eb0fed0

Browse files
type/introspection: add missing __Directive.args(includeDeprecated:) (#3275)
Backport #3273
1 parent 1532910 commit eb0fed0

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

src/type/__tests__/introspection-test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,17 @@ describe('Introspection', () => {
761761
},
762762
{
763763
name: 'args',
764-
args: [],
764+
args: [
765+
{
766+
name: 'includeDeprecated',
767+
type: {
768+
kind: 'SCALAR',
769+
name: 'Boolean',
770+
ofType: null,
771+
},
772+
defaultValue: 'false',
773+
},
774+
],
765775
type: {
766776
kind: 'NON_NULL',
767777
name: null,

src/type/introspection.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,17 @@ export const __Directive = new GraphQLObjectType({
106106
type: new GraphQLNonNull(
107107
new GraphQLList(new GraphQLNonNull(__InputValue)),
108108
),
109-
resolve: (directive) => directive.args,
109+
args: {
110+
includeDeprecated: {
111+
type: GraphQLBoolean,
112+
defaultValue: false,
113+
},
114+
},
115+
resolve(field, { includeDeprecated }) {
116+
return includeDeprecated
117+
? field.args
118+
: field.args.filter((arg) => arg.deprecationReason == null);
119+
},
110120
},
111121
}: GraphQLFieldConfigMap<GraphQLDirective, mixed>),
112122
});

src/utilities/__tests__/getIntrospectionQuery-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import { expect } from 'chai';
22
import { describe, it } from 'mocha';
33

4+
import { parse } from '../../language/parser';
5+
6+
import { validate } from '../../validation/validate';
7+
48
import type { IntrospectionOptions } from '../getIntrospectionQuery';
9+
import { buildSchema } from '../buildASTSchema';
510
import { getIntrospectionQuery } from '../getIntrospectionQuery';
611

12+
const dummySchema = buildSchema(`
13+
type Query {
14+
dummy: String
15+
}
16+
`);
17+
718
function expectIntrospectionQuery(options?: IntrospectionOptions) {
819
const query = getIntrospectionQuery(options);
920

21+
const validationErrors = validate(dummySchema, parse(query));
22+
expect(validationErrors).to.deep.equal([]);
23+
1024
return {
1125
toMatch(name: string, times: number = 1): void {
1226
const pattern = toRegExp(name);

src/utilities/__tests__/printSchema-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ describe('Type System Printer', () => {
766766
description: String
767767
isRepeatable: Boolean!
768768
locations: [__DirectiveLocation!]!
769-
args: [__InputValue!]!
769+
args(includeDeprecated: Boolean = false): [__InputValue!]!
770770
}
771771
772772
"""
@@ -965,7 +965,7 @@ describe('Type System Printer', () => {
965965
description: String
966966
isRepeatable: Boolean!
967967
locations: [__DirectiveLocation!]!
968-
args: [__InputValue!]!
968+
args(includeDeprecated: Boolean = false): [__InputValue!]!
969969
}
970970
971971
# A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.

0 commit comments

Comments
 (0)