From 22559595faf97b2fa852f568272f571829c4f60a Mon Sep 17 00:00:00 2001 From: spawnia Date: Sun, 7 Nov 2021 21:10:51 +0100 Subject: [PATCH] POC for https://github.com/graphql/graphql-js/pull/3362#issuecomment-962585017 --- src/type/directives.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/type/directives.ts b/src/type/directives.ts index b84a1302d3..0266377bda 100644 --- a/src/type/directives.ts +++ b/src/type/directives.ts @@ -9,8 +9,8 @@ import type { DirectiveDefinitionNode } from '../language/ast'; import { DirectiveLocation } from '../language/directiveLocation'; import type { - GraphQLArgument, - GraphQLFieldConfigArgumentMap, + GraphQLArgument, GraphQLEnumValue, GraphQLField, + GraphQLFieldConfigArgumentMap, GraphQLInputField, GraphQLType, } from './definition'; import { assertName } from './assertName'; import { GraphQLString, GraphQLBoolean } from './scalars'; @@ -109,6 +109,8 @@ export class GraphQLDirective { } } +type DirectiveExposeArgs = (definition: GraphQLType|GraphQLField|GraphQLEnumValue|GraphQLInputField|GraphQLArgument) => Record + export interface GraphQLDirectiveConfig { name: string; description?: Maybe; @@ -117,6 +119,7 @@ export interface GraphQLDirectiveConfig { isRepeatable?: Maybe; extensions?: Maybe>; astNode?: Maybe; + exposeArgs?: Maybe } interface GraphQLDirectiveNormalizedConfig extends GraphQLDirectiveConfig { @@ -191,6 +194,15 @@ export const GraphQLDeprecatedDirective: GraphQLDirective = defaultValue: DEFAULT_DEPRECATION_REASON, }, }, + exposeArgs: (definition: GraphQLField|GraphQLInputField|GraphQLEnumValue) => { + if (definition.deprecationReason != null) { + return [ + definition.deprecationReason === DEFAULT_DEPRECATION_REASON + ? {} + : { reason: definition.deprecationReason }, + ]; + } + } }); /**