Skip to content

Commit

Permalink
type/introspection: add missing __Directive.args(includeDeprecated:) (
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored Sep 24, 2021
1 parent e95ea9b commit 8261922
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.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,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.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,17 @@ export const __Directive: GraphQLObjectType = 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);
},
},
} as GraphQLFieldConfigMap<GraphQLDirective, unknown>),
});
Expand Down
14 changes: 14 additions & 0 deletions src/utilities/__tests__/getIntrospectionQuery-test.ts
Original file line number Diff line number Diff line change
@@ -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.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ describe('Type System Printer', () => {
description: String
isRepeatable: Boolean!
locations: [__DirectiveLocation!]!
args: [__InputValue!]!
args(includeDeprecated: Boolean = false): [__InputValue!]!
}
"""
Expand Down

0 comments on commit 8261922

Please sign in to comment.