From ca3713d41333b0b4acd1b575e0661f536a9fc5c4 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Fri, 24 Sep 2021 18:51:26 +0300 Subject: [PATCH] type/introspection: add missing `__Directive.args(includeDeprecated:)` Fixes #2895 Fixes #3046 --- src/type/__tests__/introspection-test.ts | 12 +++++++++++- src/type/introspection.ts | 12 +++++++++++- .../__tests__/getIntrospectionQuery-test.ts | 14 ++++++++++++++ src/utilities/__tests__/printSchema-test.ts | 2 +- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/type/__tests__/introspection-test.ts b/src/type/__tests__/introspection-test.ts index 0851769d4e..efca4c00ac 100644 --- a/src/type/__tests__/introspection-test.ts +++ b/src/type/__tests__/introspection-test.ts @@ -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, diff --git a/src/type/introspection.ts b/src/type/introspection.ts index 5859aa27ed..d7c555f46a 100644 --- a/src/type/introspection.ts +++ b/src/type/introspection.ts @@ -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), }); diff --git a/src/utilities/__tests__/getIntrospectionQuery-test.ts b/src/utilities/__tests__/getIntrospectionQuery-test.ts index f57dec0236..324d77b0b0 100644 --- a/src/utilities/__tests__/getIntrospectionQuery-test.ts +++ b/src/utilities/__tests__/getIntrospectionQuery-test.ts @@ -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); diff --git a/src/utilities/__tests__/printSchema-test.ts b/src/utilities/__tests__/printSchema-test.ts index 89aefc03d8..c9c16f0d5c 100644 --- a/src/utilities/__tests__/printSchema-test.ts +++ b/src/utilities/__tests__/printSchema-test.ts @@ -767,7 +767,7 @@ describe('Type System Printer', () => { description: String isRepeatable: Boolean! locations: [__DirectiveLocation!]! - args: [__InputValue!]! + args(includeDeprecated: Boolean = false): [__InputValue!]! } """