From 1d5850f9363d71a33b3c6e76c233c970ba538fed Mon Sep 17 00:00:00 2001 From: ksmithson Date: Wed, 24 Oct 2018 11:23:32 -0700 Subject: [PATCH 1/7] Add deprecated directive to arguments and input values --- src/type/__tests__/introspection-test.js | 57 ++++++++++++++++++- src/type/definition.js | 13 +++++ src/type/directives.js | 7 ++- src/type/introspection.js | 39 ++++++++++++- src/utilities/__tests__/schemaPrinter-test.js | 10 +++- 5 files changed, 116 insertions(+), 10 deletions(-) diff --git a/src/type/__tests__/introspection-test.js b/src/type/__tests__/introspection-test.js index 5c60e8a071..a60d0ad30e 100644 --- a/src/type/__tests__/introspection-test.js +++ b/src/type/__tests__/introspection-test.js @@ -325,7 +325,17 @@ describe('Introspection', () => { }, { name: 'inputFields', - args: [], + args: [ + { + name: 'includeDeprecated', + type: { + kind: 'SCALAR', + name: 'Boolean', + ofType: null, + }, + defaultValue: 'false', + }, + ], type: { kind: 'LIST', name: null, @@ -441,7 +451,17 @@ describe('Introspection', () => { }, { name: 'args', - args: [], + args: [ + { + name: 'includeDeprecated', + type: { + kind: 'SCALAR', + name: 'Boolean', + ofType: null, + }, + defaultValue: 'false', + }, + ], type: { kind: 'NON_NULL', name: null, @@ -565,6 +585,32 @@ describe('Introspection', () => { isDeprecated: false, deprecationReason: null, }, + { + name: 'isDeprecated', + args: [], + type: { + kind: 'NON_NULL', + name: null, + ofType: { + kind: 'SCALAR', + name: 'Boolean', + ofType: null, + }, + }, + isDeprecated: false, + deprecationReason: null, + }, + { + name: 'deprecationReason', + args: [], + type: { + kind: 'SCALAR', + name: 'String', + ofType: null, + }, + isDeprecated: false, + deprecationReason: null, + }, ], inputFields: null, interfaces: [], @@ -880,7 +926,12 @@ describe('Introspection', () => { { name: 'deprecated', isRepeatable: false, - locations: ['FIELD_DEFINITION', 'ENUM_VALUE'], + locations: [ + 'FIELD_DEFINITION', + 'ENUM_VALUE', + 'ARGUMENT_DEFINITION', + 'INPUT_FIELD_DEFINITION', + ], args: [ { defaultValue: '"No longer supported"', diff --git a/src/type/definition.js b/src/type/definition.js index 2d5a15117d..0634fa7125 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -949,6 +949,7 @@ export type GraphQLArgumentConfig = {| type: GraphQLInputType, defaultValue?: mixed, extensions?: ?ReadOnlyObjMapLike, + deprecationReason?: ?string, astNode?: ?InputValueDefinitionNode, |}; @@ -978,6 +979,8 @@ export type GraphQLArgument = {| description: ?string, type: GraphQLInputType, defaultValue: mixed, + isDeprecated?:boolean, + deprecationReason?: ? string, extensions: ?ReadOnlyObjMap, astNode: ?InputValueDefinitionNode, |}; @@ -1517,13 +1520,20 @@ function defineInputFieldMap( isPlainObj(fieldMap), `${config.name} fields must be an object with field names as keys or a function which returns such an object.`, ); + return mapValue(fieldMap, (fieldConfig, fieldName) => { devAssert( !('resolve' in fieldConfig), `${config.name}.${fieldName} field has a resolve property, but Input Types cannot define resolvers.`, ); + devAssert( + !fieldConfig.hasOwnProperty('isDeprecated'), + `${config.name}.${fieldName} should provide "deprecationReason" `+ + 'instead of "isDeprecated".', + ); return { + isDeprecated: Boolean(fieldConfig.deprecationReason), name: fieldName, description: fieldConfig.description, type: fieldConfig.type, @@ -1547,6 +1557,7 @@ export type GraphQLInputFieldConfig = {| description?: ?string, type: GraphQLInputType, defaultValue?: mixed, + deprecationReason?: ? string, extensions?: ?ReadOnlyObjMapLike, astNode?: ?InputValueDefinitionNode, |}; @@ -1558,6 +1569,8 @@ export type GraphQLInputField = {| description: ?string, type: GraphQLInputType, defaultValue: mixed, + isDeprecated?:boolean, + deprecationReason?: ?string, extensions: ?ReadOnlyObjMap, astNode: ?InputValueDefinitionNode, |}; diff --git a/src/type/directives.js b/src/type/directives.js index d3ed6fdae9..54053fdf6f 100644 --- a/src/type/directives.js +++ b/src/type/directives.js @@ -181,7 +181,12 @@ export const DEFAULT_DEPRECATION_REASON = 'No longer supported'; export const GraphQLDeprecatedDirective = new GraphQLDirective({ name: 'deprecated', description: 'Marks an element of a GraphQL schema as no longer supported.', - locations: [DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.ENUM_VALUE], + locations: [ + DirectiveLocation.FIELD_DEFINITION, + DirectiveLocation.ENUM_VALUE, + DirectiveLocation.ARGUMENT_DEFINITION, + DirectiveLocation.INPUT_FIELD_DEFINITION, + ], args: { reason: { type: GraphQLString, diff --git a/src/type/introspection.js b/src/type/introspection.js index 043685475f..f4198aa057 100644 --- a/src/type/introspection.js +++ b/src/type/introspection.js @@ -288,9 +288,19 @@ export const __Type = new GraphQLObjectType({ }, inputFields: { type: GraphQLList(GraphQLNonNull(__InputValue)), - resolve(type) { + args: { + includeDeprecated: { + type: GraphQLBoolean, + defaultValue: false, + }, + }, + resolve(type, {includeDeprecated}) { if (isInputObjectType(type)) { - return objectValues(type.getFields()); + let values=objectValues(type.getFields()); + if (!includeDeprecated) { + values=values.filter(value => !value.deprecationReason); + } + return values; } }, }, @@ -317,7 +327,22 @@ export const __Field = new GraphQLObjectType({ }, args: { type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__InputValue))), - resolve: field => field.args, + args: { + includeDeprecated: { + type: GraphQLBoolean, + defaultValue: false, + }, + }, + // resolve: field => field.args || [], + resolve(field, {includeDeprecated}) { + let args=field.args||[]; + + if (!includeDeprecated) { + args=args.filter(arg => !arg.deprecationReason); + } + + return args; + }, }, type: { type: GraphQLNonNull(__Type), @@ -362,6 +387,14 @@ export const __InputValue = new GraphQLObjectType({ return valueAST ? print(valueAST) : null; }, }, + isDeprecated: { + type: GraphQLNonNull(GraphQLBoolean), + resolve: obj => obj.isDeprecated, + }, + deprecationReason: { + type: GraphQLString, + resolve: obj => obj.deprecationReason, + }, }: GraphQLFieldConfigMap), }); diff --git a/src/utilities/__tests__/schemaPrinter-test.js b/src/utilities/__tests__/schemaPrinter-test.js index ebfe7f7ff9..d5d1094bc2 100644 --- a/src/utilities/__tests__/schemaPrinter-test.js +++ b/src/utilities/__tests__/schemaPrinter-test.js @@ -637,7 +637,7 @@ describe('Type System Printer', () => { Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/). """ reason: String = "No longer supported" - ) on FIELD_DEFINITION | ENUM_VALUE + ) on FIELD_DEFINITION | ENUM_VALUE | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION """ A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations. @@ -721,7 +721,7 @@ describe('Type System Printer', () => { type __Field { name: String! description: String - args: [__InputValue!]! + args(includeDeprecated: Boolean = false): [__InputValue!]! type: __Type! isDeprecated: Boolean! deprecationReason: String @@ -739,6 +739,8 @@ describe('Type System Printer', () => { A GraphQL-formatted string representing the default value for this input value. """ defaultValue: String + isDeprecated: Boolean! + deprecationReason: String } """ @@ -851,7 +853,7 @@ describe('Type System Printer', () => { directive @deprecated( # Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/). reason: String = "No longer supported" - ) on FIELD_DEFINITION | ENUM_VALUE + ) on FIELD_DEFINITION | ENUM_VALUE | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION # A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations. type __Schema { @@ -933,6 +935,8 @@ describe('Type System Printer', () => { # A GraphQL-formatted string representing the default value for this input value. defaultValue: String + isDeprecated: Boolean! + deprecationReason: String } # One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string. From 83c732534948e3443644323dd9658223948077ef Mon Sep 17 00:00:00 2001 From: ksmithson Date: Wed, 24 Oct 2018 14:52:24 -0700 Subject: [PATCH 2/7] Add test and support for deprecated args --- src/type/definition.js | 2 ++ src/utilities/__tests__/buildASTSchema-test.js | 14 ++++++++++++++ src/utilities/extendSchema.js | 1 + src/utilities/printSchema.js | 2 +- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/type/definition.js b/src/type/definition.js index 0634fa7125..8265dbf4fd 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -825,6 +825,8 @@ function defineFieldMap( type: argConfig.type, defaultValue: argConfig.defaultValue, extensions: argConfig.extensions && toObjMap(argConfig.extensions), + isDeprecated: Boolean(argConfig.deprecationReason), + deprecationReason: argConfig.deprecationReason, astNode: argConfig.astNode, })); diff --git a/src/utilities/__tests__/buildASTSchema-test.js b/src/utilities/__tests__/buildASTSchema-test.js index 2238294e14..5023e5e9f9 100644 --- a/src/utilities/__tests__/buildASTSchema-test.js +++ b/src/utilities/__tests__/buildASTSchema-test.js @@ -736,6 +736,8 @@ describe('Schema Builder', () => { field1: String @deprecated field2: Int @deprecated(reason: "Because I said so") enum: MyEnum + field3(oldArg: String @deprecated, arg: String): String + field4(oldArg: String @deprecated(reason: "why not?"), arg: String): String } `; expect(cycleSDL(sdl)).to.equal(sdl); @@ -790,6 +792,18 @@ describe('Schema Builder', () => { `); expect(printAllASTNodes(someScalar)).to.equal(scalarSDL); + const rootFields=assertObjectType(schema.getType('Query')).getFields(); + + expect(rootFields.field2.isDeprecated).to.equal(true); + expect(rootFields.field2.deprecationReason).to.equal('Because I said so'); + + const field3OldArg = rootFields.field3.args[0]; + expect(field3OldArg.isDeprecated).to.equal(true); + expect(field3OldArg.deprecationReason).to.equal('No longer supported'); + + const field4OldArg = rootFields.field4.args[0]; + expect(field4OldArg.isDeprecated).to.equal(true); + expect(field4OldArg.deprecationReason).to.equal('why not?'); }); it('Correctly extend object type', () => { diff --git a/src/utilities/extendSchema.js b/src/utilities/extendSchema.js index 0246eca461..ab881aaede 100644 --- a/src/utilities/extendSchema.js +++ b/src/utilities/extendSchema.js @@ -527,6 +527,7 @@ export function extendSchemaImpl( type, description: getDescription(field, options), defaultValue: valueFromAST(field.defaultValue, type), + deprecationReason: getDeprecationReason(field), astNode: field, }; } diff --git a/src/utilities/printSchema.js b/src/utilities/printSchema.js index 674d5b26a5..8593b7d4fc 100644 --- a/src/utilities/printSchema.js +++ b/src/utilities/printSchema.js @@ -294,7 +294,7 @@ function printInputValue(arg) { if (defaultAST) { argDecl += ` = ${print(defaultAST)}`; } - return argDecl; + return argDecl + printDeprecated(arg); } function printDirective(directive, options) { From 52d67fa07d5c500f3ecf9aef8f287e77ed32d819 Mon Sep 17 00:00:00 2001 From: ksmithson Date: Thu, 25 Oct 2018 07:00:12 -0700 Subject: [PATCH 3/7] Add test for input arguments being deprecated --- .../__tests__/buildASTSchema-test.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/utilities/__tests__/buildASTSchema-test.js b/src/utilities/__tests__/buildASTSchema-test.js index 5023e5e9f9..88d245db0a 100644 --- a/src/utilities/__tests__/buildASTSchema-test.js +++ b/src/utilities/__tests__/buildASTSchema-test.js @@ -732,12 +732,19 @@ describe('Schema Builder', () => { OTHER_VALUE @deprecated(reason: "Terrible reasons") } + input MyInput { + oldInput: String @deprecated + otherInput: String @deprecated(reason: "Use newInput") + newInput: String + } + type Query { field1: String @deprecated field2: Int @deprecated(reason: "Because I said so") enum: MyEnum field3(oldArg: String @deprecated, arg: String): String field4(oldArg: String @deprecated(reason: "why not?"), arg: String): String + field5(arg: MyInput): String } `; expect(cycleSDL(sdl)).to.equal(sdl); @@ -804,6 +811,20 @@ describe('Schema Builder', () => { const field4OldArg = rootFields.field4.args[0]; expect(field4OldArg.isDeprecated).to.equal(true); expect(field4OldArg.deprecationReason).to.equal('why not?'); + + const myInput = schema.getType('MyInput'); + const inputFields = myInput.getFields(); + + const newInput = inputFields.newInput; + expect(newInput.isDeprecated).to.equal(false); + + const oldInput = inputFields.oldInput; + expect(oldInput.isDeprecated).to.equal(true); + expect(oldInput.deprecationReason).to.equal('No longer supported'); + + const otherInput = inputFields.otherInput; + expect(otherInput.isDeprecated).to.equal(true); + expect(otherInput.deprecationReason).to.equal('Use newInput'); }); it('Correctly extend object type', () => { From 56ea57cb6bd7da0ec145364b2065ccc873af583a Mon Sep 17 00:00:00 2001 From: jonathan schatz Date: Tue, 11 Feb 2020 10:33:14 -0800 Subject: [PATCH 4/7] eslint/prettier fixes --- src/type/definition.js | 14 +++++++------- src/type/introspection.js | 12 ++++++------ src/utilities/__tests__/buildASTSchema-test.js | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/type/definition.js b/src/type/definition.js index 8265dbf4fd..1ee02c1342 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -981,8 +981,8 @@ export type GraphQLArgument = {| description: ?string, type: GraphQLInputType, defaultValue: mixed, - isDeprecated?:boolean, - deprecationReason?: ? string, + isDeprecated?: boolean, + deprecationReason?: ?string, extensions: ?ReadOnlyObjMap, astNode: ?InputValueDefinitionNode, |}; @@ -1529,9 +1529,9 @@ function defineInputFieldMap( `${config.name}.${fieldName} field has a resolve property, but Input Types cannot define resolvers.`, ); devAssert( - !fieldConfig.hasOwnProperty('isDeprecated'), - `${config.name}.${fieldName} should provide "deprecationReason" `+ - 'instead of "isDeprecated".', + !('isDeprecated' in fieldConfig), + `${config.name}.${fieldName} should provide "deprecationReason" ` + + 'instead of "isDeprecated".', ); return { @@ -1559,7 +1559,7 @@ export type GraphQLInputFieldConfig = {| description?: ?string, type: GraphQLInputType, defaultValue?: mixed, - deprecationReason?: ? string, + deprecationReason?: ?string, extensions?: ?ReadOnlyObjMapLike, astNode?: ?InputValueDefinitionNode, |}; @@ -1571,7 +1571,7 @@ export type GraphQLInputField = {| description: ?string, type: GraphQLInputType, defaultValue: mixed, - isDeprecated?:boolean, + isDeprecated?: boolean, deprecationReason?: ?string, extensions: ?ReadOnlyObjMap, astNode: ?InputValueDefinitionNode, diff --git a/src/type/introspection.js b/src/type/introspection.js index f4198aa057..c50067f1f0 100644 --- a/src/type/introspection.js +++ b/src/type/introspection.js @@ -294,11 +294,11 @@ export const __Type = new GraphQLObjectType({ defaultValue: false, }, }, - resolve(type, {includeDeprecated}) { + resolve(type, { includeDeprecated }) { if (isInputObjectType(type)) { - let values=objectValues(type.getFields()); + let values = objectValues(type.getFields()); if (!includeDeprecated) { - values=values.filter(value => !value.deprecationReason); + values = values.filter(value => !value.deprecationReason); } return values; } @@ -334,11 +334,11 @@ export const __Field = new GraphQLObjectType({ }, }, // resolve: field => field.args || [], - resolve(field, {includeDeprecated}) { - let args=field.args||[]; + resolve(field, { includeDeprecated }) { + let args = field.args || []; if (!includeDeprecated) { - args=args.filter(arg => !arg.deprecationReason); + args = args.filter(arg => !arg.deprecationReason); } return args; diff --git a/src/utilities/__tests__/buildASTSchema-test.js b/src/utilities/__tests__/buildASTSchema-test.js index 88d245db0a..fffe8cd2ab 100644 --- a/src/utilities/__tests__/buildASTSchema-test.js +++ b/src/utilities/__tests__/buildASTSchema-test.js @@ -799,7 +799,7 @@ describe('Schema Builder', () => { `); expect(printAllASTNodes(someScalar)).to.equal(scalarSDL); - const rootFields=assertObjectType(schema.getType('Query')).getFields(); + const rootFields = assertObjectType(schema.getType('Query')).getFields(); expect(rootFields.field2.isDeprecated).to.equal(true); expect(rootFields.field2.deprecationReason).to.equal('Because I said so'); From af4bdaac5077ff40a370efd7105432466c7a0eb7 Mon Sep 17 00:00:00 2001 From: jonathan schatz Date: Tue, 11 Feb 2020 11:15:22 -0800 Subject: [PATCH 5/7] more cleanup --- src/type/__tests__/definition-test.js | 4 ++ src/type/definition.d.ts | 2 + src/type/definition.js | 4 +- .../__tests__/buildASTSchema-test.js | 49 +++++++++---------- src/utilities/__tests__/schemaPrinter-test.js | 6 +-- src/utilities/extendSchema.js | 5 +- src/utilities/printSchema.js | 2 +- 7 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/type/__tests__/definition-test.js b/src/type/__tests__/definition-test.js index 8003d86883..90825f91fc 100644 --- a/src/type/__tests__/definition-test.js +++ b/src/type/__tests__/definition-test.js @@ -259,6 +259,8 @@ describe('Type System: Objects', () => { description: undefined, type: ScalarType, defaultValue: undefined, + deprecationReason: undefined, + isDeprecated: false, extensions: undefined, astNode: undefined, }, @@ -750,6 +752,7 @@ describe('Type System: Input Objects', () => { description: undefined, type: ScalarType, defaultValue: undefined, + isDeprecated: false, extensions: undefined, astNode: undefined, }, @@ -770,6 +773,7 @@ describe('Type System: Input Objects', () => { type: ScalarType, defaultValue: undefined, extensions: undefined, + isDeprecated: false, astNode: undefined, }, }); diff --git a/src/type/definition.d.ts b/src/type/definition.d.ts index df62c66743..cd28b027a9 100644 --- a/src/type/definition.d.ts +++ b/src/type/definition.d.ts @@ -493,6 +493,8 @@ export interface GraphQLArgumentConfig { description?: Maybe; type: GraphQLInputType; defaultValue?: any; + isDeprecated?: boolean; + deprecationReason?: Maybe; extensions?: Maybe>>; astNode?: Maybe; } diff --git a/src/type/definition.js b/src/type/definition.js index 1ee02c1342..4c92c75d8d 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -825,7 +825,7 @@ function defineFieldMap( type: argConfig.type, defaultValue: argConfig.defaultValue, extensions: argConfig.extensions && toObjMap(argConfig.extensions), - isDeprecated: Boolean(argConfig.deprecationReason), + isDeprecated: argConfig.deprecationReason != null, deprecationReason: argConfig.deprecationReason, astNode: argConfig.astNode, })); @@ -1535,7 +1535,7 @@ function defineInputFieldMap( ); return { - isDeprecated: Boolean(fieldConfig.deprecationReason), + isDeprecated: fieldConfig.deprecationReason != null, name: fieldName, description: fieldConfig.description, type: fieldConfig.type, diff --git a/src/utilities/__tests__/buildASTSchema-test.js b/src/utilities/__tests__/buildASTSchema-test.js index fffe8cd2ab..5e9a48d9cd 100644 --- a/src/utilities/__tests__/buildASTSchema-test.js +++ b/src/utilities/__tests__/buildASTSchema-test.js @@ -777,6 +777,29 @@ describe('Schema Builder', () => { isDeprecated: true, deprecationReason: 'Because I said so', }); + + const inputFields = assertInputObjectType( + schema.getType('MyInput'), + ).getFields(); + + const newInput = inputFields.newInput; + expect(newInput.isDeprecated).to.equal(false); + + const oldInput = inputFields.oldInput; + expect(oldInput.isDeprecated).to.equal(true); + expect(oldInput.deprecationReason).to.equal('No longer supported'); + + const otherInput = inputFields.otherInput; + expect(otherInput.isDeprecated).to.equal(true); + expect(otherInput.deprecationReason).to.equal('Use newInput'); + + const field3OldArg = rootFields.field3.args[0]; + expect(field3OldArg.isDeprecated).to.equal(true); + expect(field3OldArg.deprecationReason).to.equal('No longer supported'); + + const field4OldArg = rootFields.field4.args[0]; + expect(field4OldArg.isDeprecated).to.equal(true); + expect(field4OldArg.deprecationReason).to.equal('why not?'); }); it('Correctly extend scalar type', () => { @@ -799,32 +822,6 @@ describe('Schema Builder', () => { `); expect(printAllASTNodes(someScalar)).to.equal(scalarSDL); - const rootFields = assertObjectType(schema.getType('Query')).getFields(); - - expect(rootFields.field2.isDeprecated).to.equal(true); - expect(rootFields.field2.deprecationReason).to.equal('Because I said so'); - - const field3OldArg = rootFields.field3.args[0]; - expect(field3OldArg.isDeprecated).to.equal(true); - expect(field3OldArg.deprecationReason).to.equal('No longer supported'); - - const field4OldArg = rootFields.field4.args[0]; - expect(field4OldArg.isDeprecated).to.equal(true); - expect(field4OldArg.deprecationReason).to.equal('why not?'); - - const myInput = schema.getType('MyInput'); - const inputFields = myInput.getFields(); - - const newInput = inputFields.newInput; - expect(newInput.isDeprecated).to.equal(false); - - const oldInput = inputFields.oldInput; - expect(oldInput.isDeprecated).to.equal(true); - expect(oldInput.deprecationReason).to.equal('No longer supported'); - - const otherInput = inputFields.otherInput; - expect(otherInput.isDeprecated).to.equal(true); - expect(otherInput.deprecationReason).to.equal('Use newInput'); }); it('Correctly extend object type', () => { diff --git a/src/utilities/__tests__/schemaPrinter-test.js b/src/utilities/__tests__/schemaPrinter-test.js index d5d1094bc2..cbdb318150 100644 --- a/src/utilities/__tests__/schemaPrinter-test.js +++ b/src/utilities/__tests__/schemaPrinter-test.js @@ -678,7 +678,7 @@ describe('Type System Printer', () => { interfaces: [__Type!] possibleTypes: [__Type!] enumValues(includeDeprecated: Boolean = false): [__EnumValue!] - inputFields: [__InputValue!] + inputFields(includeDeprecated: Boolean = false): [__InputValue!] ofType: __Type } @@ -886,7 +886,7 @@ describe('Type System Printer', () => { interfaces: [__Type!] possibleTypes: [__Type!] enumValues(includeDeprecated: Boolean = false): [__EnumValue!] - inputFields: [__InputValue!] + inputFields(includeDeprecated: Boolean = false): [__InputValue!] ofType: __Type } @@ -921,7 +921,7 @@ describe('Type System Printer', () => { type __Field { name: String! description: String - args: [__InputValue!]! + args(includeDeprecated: Boolean = false): [__InputValue!]! type: __Type! isDeprecated: Boolean! deprecationReason: String diff --git a/src/utilities/extendSchema.js b/src/utilities/extendSchema.js index ab881aaede..9f24b6eec4 100644 --- a/src/utilities/extendSchema.js +++ b/src/utilities/extendSchema.js @@ -695,7 +695,10 @@ const stdTypeMap = keyMap( * deprecation reason. */ function getDeprecationReason( - node: EnumValueDefinitionNode | FieldDefinitionNode, + node: + | EnumValueDefinitionNode + | FieldDefinitionNode + | InputValueDefinitionNode, ): ?string { const deprecated = getDirectiveValues(GraphQLDeprecatedDirective, node); return (deprecated?.reason: any); diff --git a/src/utilities/printSchema.js b/src/utilities/printSchema.js index 8593b7d4fc..4afceae663 100644 --- a/src/utilities/printSchema.js +++ b/src/utilities/printSchema.js @@ -310,7 +310,7 @@ function printDirective(directive, options) { } function printDeprecated(fieldOrEnumVal) { - if (!fieldOrEnumVal.isDeprecated) { + if (fieldOrEnumVal.deprecationReason == null) { return ''; } const reason = fieldOrEnumVal.deprecationReason; From 83e82d182b458754afc932788a53f94b4d4175ef Mon Sep 17 00:00:00 2001 From: jonathan schatz Date: Tue, 11 Feb 2020 12:03:13 -0800 Subject: [PATCH 6/7] more wip --- src/type/__tests__/definition-test.js | 2 ++ src/type/definition.js | 6 +++- .../__tests__/buildASTSchema-test.js | 28 +++++++++++++------ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/type/__tests__/definition-test.js b/src/type/__tests__/definition-test.js index 90825f91fc..5eecd93893 100644 --- a/src/type/__tests__/definition-test.js +++ b/src/type/__tests__/definition-test.js @@ -752,6 +752,7 @@ describe('Type System: Input Objects', () => { description: undefined, type: ScalarType, defaultValue: undefined, + deprecationReason: undefined, isDeprecated: false, extensions: undefined, astNode: undefined, @@ -774,6 +775,7 @@ describe('Type System: Input Objects', () => { defaultValue: undefined, extensions: undefined, isDeprecated: false, + deprecationReason: undefined, astNode: undefined, }, }); diff --git a/src/type/definition.js b/src/type/definition.js index 4c92c75d8d..1cb05558f4 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -875,6 +875,8 @@ export function argsToArgsConfig( description: arg.description, type: arg.type, defaultValue: arg.defaultValue, + deprecationReason: arg.deprecationReason, + isDeprecated: arg.deprecationReason != null, extensions: arg.extensions, astNode: arg.astNode, }), @@ -952,6 +954,7 @@ export type GraphQLArgumentConfig = {| defaultValue?: mixed, extensions?: ?ReadOnlyObjMapLike, deprecationReason?: ?string, + isDeprecated?: boolean, astNode?: ?InputValueDefinitionNode, |}; @@ -1535,11 +1538,12 @@ function defineInputFieldMap( ); return { - isDeprecated: fieldConfig.deprecationReason != null, name: fieldName, description: fieldConfig.description, type: fieldConfig.type, defaultValue: fieldConfig.defaultValue, + deprecationReason: fieldConfig.deprecationReason, + isDeprecated: fieldConfig.deprecationReason != null, extensions: fieldConfig.extensions && toObjMap(fieldConfig.extensions), astNode: fieldConfig.astNode, }; diff --git a/src/utilities/__tests__/buildASTSchema-test.js b/src/utilities/__tests__/buildASTSchema-test.js index 5e9a48d9cd..39f127bbcc 100644 --- a/src/utilities/__tests__/buildASTSchema-test.js +++ b/src/utilities/__tests__/buildASTSchema-test.js @@ -783,23 +783,33 @@ describe('Schema Builder', () => { ).getFields(); const newInput = inputFields.newInput; - expect(newInput.isDeprecated).to.equal(false); + expect(newInput).to.include({ + isDeprecated: false, + }); const oldInput = inputFields.oldInput; - expect(oldInput.isDeprecated).to.equal(true); - expect(oldInput.deprecationReason).to.equal('No longer supported'); + expect(oldInput).to.include({ + isDeprecated: true, + deprecationReason: 'No longer supported', + }); const otherInput = inputFields.otherInput; - expect(otherInput.isDeprecated).to.equal(true); - expect(otherInput.deprecationReason).to.equal('Use newInput'); + expect(otherInput).to.include({ + isDeprecated: true, + deprecationReason: 'Use newInput', + }); const field3OldArg = rootFields.field3.args[0]; - expect(field3OldArg.isDeprecated).to.equal(true); - expect(field3OldArg.deprecationReason).to.equal('No longer supported'); + expect(field3OldArg).to.include({ + isDeprecated: true, + deprecationReason: 'No longer supported', + }); const field4OldArg = rootFields.field4.args[0]; - expect(field4OldArg.isDeprecated).to.equal(true); - expect(field4OldArg.deprecationReason).to.equal('why not?'); + expect(field4OldArg).to.include({ + isDeprecated: true, + deprecationReason: 'Why not?', + }); }); it('Correctly extend scalar type', () => { From 05717ee1f2696d951c138b212f7b42b112eea521 Mon Sep 17 00:00:00 2001 From: jonathan schatz Date: Wed, 26 Feb 2020 12:29:23 -0800 Subject: [PATCH 7/7] fix last spec --- src/utilities/__tests__/buildASTSchema-test.js | 2 +- src/utilities/extendSchema.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utilities/__tests__/buildASTSchema-test.js b/src/utilities/__tests__/buildASTSchema-test.js index 39f127bbcc..e0578b0f34 100644 --- a/src/utilities/__tests__/buildASTSchema-test.js +++ b/src/utilities/__tests__/buildASTSchema-test.js @@ -743,7 +743,7 @@ describe('Schema Builder', () => { field2: Int @deprecated(reason: "Because I said so") enum: MyEnum field3(oldArg: String @deprecated, arg: String): String - field4(oldArg: String @deprecated(reason: "why not?"), arg: String): String + field4(oldArg: String @deprecated(reason: "Why not?"), arg: String): String field5(arg: MyInput): String } `; diff --git a/src/utilities/extendSchema.js b/src/utilities/extendSchema.js index 9f24b6eec4..b262df677a 100644 --- a/src/utilities/extendSchema.js +++ b/src/utilities/extendSchema.js @@ -501,6 +501,7 @@ export function extendSchemaImpl( type, description: getDescription(arg, options), defaultValue: valueFromAST(arg.defaultValue, type), + deprecationReason: getDeprecationReason(arg), astNode: arg, }; }