Skip to content

Commit 08374e7

Browse files
committed
Various fixes
1 parent 171aec5 commit 08374e7

File tree

10 files changed

+66
-40
lines changed

10 files changed

+66
-40
lines changed

src/type/__tests__/definition-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ describe('Type System: Objects', () => {
281281
description: undefined,
282282
type: ScalarType,
283283
defaultValue: undefined,
284-
deprecationReason: undefined,
285284
isDeprecated: false,
285+
deprecationReason: undefined,
286286
extensions: undefined,
287287
astNode: undefined,
288288
},
@@ -774,8 +774,8 @@ describe('Type System: Input Objects', () => {
774774
description: undefined,
775775
type: ScalarType,
776776
defaultValue: undefined,
777-
deprecationReason: undefined,
778777
isDeprecated: false,
778+
deprecationReason: undefined,
779779
extensions: undefined,
780780
astNode: undefined,
781781
},

src/type/__tests__/directive-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ describe('Type System: Directive', () => {
3939
description: undefined,
4040
type: GraphQLString,
4141
defaultValue: undefined,
42+
isDeprecated: false,
43+
deprecationReason: undefined,
4244
extensions: undefined,
4345
astNode: undefined,
4446
},
@@ -47,6 +49,8 @@ describe('Type System: Directive', () => {
4749
description: undefined,
4850
type: GraphQLInt,
4951
defaultValue: undefined,
52+
isDeprecated: false,
53+
deprecationReason: undefined,
5054
extensions: undefined,
5155
astNode: undefined,
5256
},

src/type/__tests__/introspection-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,8 @@ describe('Introspection', () => {
951951
isRepeatable: false,
952952
locations: [
953953
'FIELD_DEFINITION',
954-
'ENUM_VALUE',
955954
'ARGUMENT_DEFINITION',
955+
'ENUM_VALUE',
956956
'INPUT_FIELD_DEFINITION',
957957
],
958958
args: [

src/type/__tests__/predicate-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ describe('Type predicates', () => {
549549
name: 'someArg',
550550
description: undefined,
551551
defaultValue: undefined,
552+
isDeprecated: false,
553+
deprecationReason: null,
552554
extensions: undefined,
553555
astNode: undefined,
554556
...config,
@@ -593,6 +595,8 @@ describe('Type predicates', () => {
593595
name: 'someInputField',
594596
description: undefined,
595597
defaultValue: undefined,
598+
isDeprecated: false,
599+
deprecationReason: null,
596600
extensions: undefined,
597601
astNode: undefined,
598602
...config,

src/type/definition.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,6 @@ export interface GraphQLArgumentConfig {
546546
description?: Maybe<string>;
547547
type: GraphQLInputType;
548548
defaultValue?: any;
549-
isDeprecated?: boolean;
550549
deprecationReason?: Maybe<string>;
551550
extensions?: Maybe<Readonly<GraphQLArgumentExtensions>>;
552551
astNode?: Maybe<InputValueDefinitionNode>;
@@ -578,6 +577,8 @@ export interface GraphQLArgument {
578577
description: Maybe<string>;
579578
type: GraphQLInputType;
580579
defaultValue: any;
580+
isDeprecated: boolean;
581+
deprecationReason: Maybe<string>;
581582
extensions: Maybe<Readonly<GraphQLArgumentExtensions>>;
582583
astNode: Maybe<InputValueDefinitionNode>;
583584
}
@@ -917,6 +918,7 @@ export interface GraphQLInputFieldConfig {
917918
description?: Maybe<string>;
918919
type: GraphQLInputType;
919920
defaultValue?: any;
921+
deprecationReason?: Maybe<string>;
920922
extensions?: Maybe<Readonly<GraphQLInputFieldExtensions>>;
921923
astNode?: Maybe<InputValueDefinitionNode>;
922924
}
@@ -930,6 +932,8 @@ export interface GraphQLInputField {
930932
description?: Maybe<string>;
931933
type: GraphQLInputType;
932934
defaultValue?: any;
935+
isDeprecated: boolean;
936+
deprecationReason: Maybe<string>;
933937
extensions: Maybe<Readonly<GraphQLInputFieldExtensions>>;
934938
astNode?: Maybe<InputValueDefinitionNode>;
935939
}

src/type/definition.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -848,16 +848,23 @@ function defineFieldMap<TSource, TContext>(
848848
`${config.name}.${fieldName} args must be an object with argument names as keys.`,
849849
);
850850

851-
const args = objectEntries(argsConfig).map(([argName, argConfig]) => ({
852-
name: argName,
853-
description: argConfig.description,
854-
type: argConfig.type,
855-
defaultValue: argConfig.defaultValue,
856-
extensions: argConfig.extensions && toObjMap(argConfig.extensions),
857-
isDeprecated: argConfig.deprecationReason != null,
858-
deprecationReason: argConfig.deprecationReason,
859-
astNode: argConfig.astNode,
860-
}));
851+
const args = objectEntries(argsConfig).map(([argName, argConfig]) => {
852+
devAssert(
853+
!('isDeprecated' in argConfig),
854+
`${config.name}.${fieldName}.${argName} should provide "deprecationReason" instead of "isDeprecated".`,
855+
);
856+
857+
return {
858+
name: argName,
859+
description: argConfig.description,
860+
type: argConfig.type,
861+
defaultValue: argConfig.defaultValue,
862+
isDeprecated: argConfig.deprecationReason != null,
863+
deprecationReason: argConfig.deprecationReason,
864+
extensions: argConfig.extensions && toObjMap(argConfig.extensions),
865+
astNode: argConfig.astNode,
866+
};
867+
});
861868

862869
return {
863870
name: fieldName,
@@ -905,7 +912,6 @@ export function argsToArgsConfig(
905912
type: arg.type,
906913
defaultValue: arg.defaultValue,
907914
deprecationReason: arg.deprecationReason,
908-
isDeprecated: arg.deprecationReason != null,
909915
extensions: arg.extensions,
910916
astNode: arg.astNode,
911917
}),
@@ -983,7 +989,6 @@ export type GraphQLArgumentConfig = {|
983989
defaultValue?: mixed,
984990
extensions?: ?ReadOnlyObjMapLike<mixed>,
985991
deprecationReason?: ?string,
986-
isDeprecated?: boolean,
987992
astNode?: ?InputValueDefinitionNode,
988993
|};
989994

@@ -1013,8 +1018,8 @@ export type GraphQLArgument = {|
10131018
description: ?string,
10141019
type: GraphQLInputType,
10151020
defaultValue: mixed,
1016-
isDeprecated?: boolean,
1017-
deprecationReason?: ?string,
1021+
isDeprecated: boolean,
1022+
deprecationReason: ?string,
10181023
extensions: ?ReadOnlyObjMap<mixed>,
10191024
astNode: ?InputValueDefinitionNode,
10201025
|};
@@ -1582,17 +1587,16 @@ function defineInputFieldMap(
15821587
);
15831588
devAssert(
15841589
!('isDeprecated' in fieldConfig),
1585-
`${config.name}.${fieldName} should provide "deprecationReason" ` +
1586-
'instead of "isDeprecated".',
1590+
`${config.name}.${fieldName} should provide "deprecationReason" instead of "isDeprecated".`,
15871591
);
15881592

15891593
return {
15901594
name: fieldName,
15911595
description: fieldConfig.description,
15921596
type: fieldConfig.type,
15931597
defaultValue: fieldConfig.defaultValue,
1594-
deprecationReason: fieldConfig.deprecationReason,
15951598
isDeprecated: fieldConfig.deprecationReason != null,
1599+
deprecationReason: fieldConfig.deprecationReason,
15961600
extensions: fieldConfig.extensions && toObjMap(fieldConfig.extensions),
15971601
astNode: fieldConfig.astNode,
15981602
};
@@ -1624,8 +1628,8 @@ export type GraphQLInputField = {|
16241628
description: ?string,
16251629
type: GraphQLInputType,
16261630
defaultValue: mixed,
1627-
isDeprecated?: boolean,
1628-
deprecationReason?: ?string,
1631+
isDeprecated: boolean,
1632+
deprecationReason: ?string,
16291633
extensions: ?ReadOnlyObjMap<mixed>,
16301634
astNode: ?InputValueDefinitionNode,
16311635
|};

src/type/directives.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,23 @@ export class GraphQLDirective {
7575
`@${config.name} args must be an object with argument names as keys.`,
7676
);
7777

78-
this.args = objectEntries(args).map(([argName, argConfig]) => ({
79-
name: argName,
80-
description: argConfig.description,
81-
type: argConfig.type,
82-
defaultValue: argConfig.defaultValue,
83-
extensions: argConfig.extensions && toObjMap(argConfig.extensions),
84-
astNode: argConfig.astNode,
85-
}));
78+
this.args = objectEntries(args).map(([argName, argConfig]) => {
79+
devAssert(
80+
!('isDeprecated' in argConfig),
81+
`@${config.name}.${argName} should provide "deprecationReason" instead of "isDeprecated".`,
82+
);
83+
84+
return {
85+
name: argName,
86+
description: argConfig.description,
87+
type: argConfig.type,
88+
defaultValue: argConfig.defaultValue,
89+
isDeprecated: argConfig.deprecationReason != null,
90+
deprecationReason: argConfig.deprecationReason,
91+
extensions: argConfig.extensions && toObjMap(argConfig.extensions),
92+
astNode: argConfig.astNode,
93+
};
94+
});
8695
}
8796

8897
toConfig(): {|
@@ -182,8 +191,8 @@ export const GraphQLDeprecatedDirective = new GraphQLDirective({
182191
description: 'Marks an element of a GraphQL schema as no longer supported.',
183192
locations: [
184193
DirectiveLocation.FIELD_DEFINITION,
185-
DirectiveLocation.ENUM_VALUE,
186194
DirectiveLocation.ARGUMENT_DEFINITION,
195+
DirectiveLocation.ENUM_VALUE,
187196
DirectiveLocation.INPUT_FIELD_DEFINITION,
188197
],
189198
args: {

src/type/introspection.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ export const TypeMetaFieldDef: GraphQLField<mixed, mixed> = {
512512
description: undefined,
513513
type: GraphQLNonNull(GraphQLString),
514514
defaultValue: undefined,
515+
isDeprecated: false,
516+
deprecationReason: undefined,
515517
extensions: undefined,
516518
astNode: undefined,
517519
},

src/utilities/__tests__/printSchema-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ describe('Type System Printer', () => {
629629
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/).
630630
"""
631631
reason: String = "No longer supported"
632-
) on FIELD_DEFINITION | ENUM_VALUE | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
632+
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | ENUM_VALUE | INPUT_FIELD_DEFINITION
633633
634634
"""Exposes a URL that specifies the behaviour of this scalar."""
635635
directive @specifiedBy(
@@ -852,7 +852,7 @@ describe('Type System Printer', () => {
852852
directive @deprecated(
853853
# 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/).
854854
reason: String = "No longer supported"
855-
) on FIELD_DEFINITION | ENUM_VALUE | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
855+
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | ENUM_VALUE | INPUT_FIELD_DEFINITION
856856
857857
# Exposes a URL that specifies the behaviour of this scalar.
858858
directive @specifiedBy(

src/utilities/printSchema.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function printEnum(type: GraphQLEnumType, options): string {
232232
printDescription(options, value, ' ', !i) +
233233
' ' +
234234
value.name +
235-
printDeprecated(value),
235+
printDeprecated(value.deprecationReason),
236236
);
237237

238238
return (
@@ -259,7 +259,7 @@ function printFields(options, type) {
259259
printArgs(options, f.args, ' ') +
260260
': ' +
261261
String(f.type) +
262-
printDeprecated(f),
262+
printDeprecated(f.deprecationReason),
263263
);
264264
return printBlock(fields);
265265
}
@@ -301,7 +301,7 @@ function printInputValue(arg) {
301301
if (defaultAST) {
302302
argDecl += ` = ${print(defaultAST)}`;
303303
}
304-
return argDecl + printDeprecated(arg);
304+
return argDecl + printDeprecated(arg.deprecationReason);
305305
}
306306
307307
function printDirective(directive, options) {
@@ -316,11 +316,10 @@ function printDirective(directive, options) {
316316
);
317317
}
318318
319-
function printDeprecated(fieldOrEnumVal) {
320-
if (fieldOrEnumVal.deprecationReason == null) {
319+
function printDeprecated(reason) {
320+
if (reason == null) {
321321
return '';
322322
}
323-
const reason = fieldOrEnumVal.deprecationReason;
324323
const reasonAST = astFromValue(reason, GraphQLString);
325324
if (reasonAST && reason !== DEFAULT_DEPRECATION_REASON) {
326325
return ' @deprecated(reason: ' + print(reasonAST) + ')';

0 commit comments

Comments
 (0)