Skip to content

Commit

Permalink
type/introspection: add missing __Directive.args(includeDeprecated:)
Browse files Browse the repository at this point in the history
Backport #3273
  • Loading branch information
IvanGoncharov committed Sep 24, 2021
1 parent 1532910 commit 82b8121
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/type/__tests__/introspection-test.js
Expand Up @@ -761,7 +761,17 @@ describe('Introspection', () => {
},
{
name: 'args',
args: [],
args: [
{
name: 'includeDeprecated',
type: {
kind: 'SCALAR',
name: 'Boolean',
ofType: null,
},
defaultValue: 'false',
},
],
type: {
kind: 'NON_NULL',
name: null,
Expand Down
12 changes: 11 additions & 1 deletion src/type/introspection.js
Expand Up @@ -106,7 +106,17 @@ export const __Directive = new GraphQLObjectType({
type: new GraphQLNonNull(
new GraphQLList(new GraphQLNonNull(__InputValue)),
),
resolve: (directive) => directive.args,
args: {
includeDeprecated: {
type: GraphQLBoolean,
defaultValue: false,
},
},
resolve(field, { includeDeprecated }) {
return includeDeprecated
? field.args
: field.args.filter((arg) => arg.deprecationReason == null);
},
},
}: GraphQLFieldConfigMap<GraphQLDirective, mixed>),
});
Expand Down
14 changes: 14 additions & 0 deletions src/utilities/__tests__/getIntrospectionQuery-test.js
@@ -1,12 +1,26 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import { parse } from '../../language/parser';

import { validate } from '../../validation/validate';

import type { IntrospectionOptions } from '../getIntrospectionQuery';
import { buildSchema } from '../buildASTSchema';
import { getIntrospectionQuery } from '../getIntrospectionQuery';

const dummySchema = buildSchema(`
type Query {
dummy: String
}
`);

function expectIntrospectionQuery(options?: IntrospectionOptions) {
const query = getIntrospectionQuery(options);

const validationErrors = validate(dummySchema, parse(query));
expect(validationErrors).to.deep.equal([]);

return {
toMatch(name: string, times: number = 1): void {
const pattern = toRegExp(name);
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/__tests__/printSchema-test.js
Expand Up @@ -766,7 +766,7 @@ describe('Type System Printer', () => {
description: String
isRepeatable: Boolean!
locations: [__DirectiveLocation!]!
args: [__InputValue!]!
args(includeDeprecated: Boolean = false): [__InputValue!]!
}
"""
Expand Down

0 comments on commit 82b8121

Please sign in to comment.