Skip to content

Commit af4bdaa

Browse files
committed
more cleanup
1 parent 56ea57c commit af4bdaa

File tree

7 files changed

+39
-33
lines changed

7 files changed

+39
-33
lines changed

src/type/__tests__/definition-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ describe('Type System: Objects', () => {
259259
description: undefined,
260260
type: ScalarType,
261261
defaultValue: undefined,
262+
deprecationReason: undefined,
263+
isDeprecated: false,
262264
extensions: undefined,
263265
astNode: undefined,
264266
},
@@ -750,6 +752,7 @@ describe('Type System: Input Objects', () => {
750752
description: undefined,
751753
type: ScalarType,
752754
defaultValue: undefined,
755+
isDeprecated: false,
753756
extensions: undefined,
754757
astNode: undefined,
755758
},
@@ -770,6 +773,7 @@ describe('Type System: Input Objects', () => {
770773
type: ScalarType,
771774
defaultValue: undefined,
772775
extensions: undefined,
776+
isDeprecated: false,
773777
astNode: undefined,
774778
},
775779
});

src/type/definition.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,8 @@ export interface GraphQLArgumentConfig {
493493
description?: Maybe<string>;
494494
type: GraphQLInputType;
495495
defaultValue?: any;
496+
isDeprecated?: boolean;
497+
deprecationReason?: Maybe<string>;
496498
extensions?: Maybe<Readonly<Record<string, any>>>;
497499
astNode?: Maybe<InputValueDefinitionNode>;
498500
}

src/type/definition.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ function defineFieldMap<TSource, TContext>(
825825
type: argConfig.type,
826826
defaultValue: argConfig.defaultValue,
827827
extensions: argConfig.extensions && toObjMap(argConfig.extensions),
828-
isDeprecated: Boolean(argConfig.deprecationReason),
828+
isDeprecated: argConfig.deprecationReason != null,
829829
deprecationReason: argConfig.deprecationReason,
830830
astNode: argConfig.astNode,
831831
}));
@@ -1535,7 +1535,7 @@ function defineInputFieldMap(
15351535
);
15361536

15371537
return {
1538-
isDeprecated: Boolean(fieldConfig.deprecationReason),
1538+
isDeprecated: fieldConfig.deprecationReason != null,
15391539
name: fieldName,
15401540
description: fieldConfig.description,
15411541
type: fieldConfig.type,

src/utilities/__tests__/buildASTSchema-test.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,29 @@ describe('Schema Builder', () => {
777777
isDeprecated: true,
778778
deprecationReason: 'Because I said so',
779779
});
780+
781+
const inputFields = assertInputObjectType(
782+
schema.getType('MyInput'),
783+
).getFields();
784+
785+
const newInput = inputFields.newInput;
786+
expect(newInput.isDeprecated).to.equal(false);
787+
788+
const oldInput = inputFields.oldInput;
789+
expect(oldInput.isDeprecated).to.equal(true);
790+
expect(oldInput.deprecationReason).to.equal('No longer supported');
791+
792+
const otherInput = inputFields.otherInput;
793+
expect(otherInput.isDeprecated).to.equal(true);
794+
expect(otherInput.deprecationReason).to.equal('Use newInput');
795+
796+
const field3OldArg = rootFields.field3.args[0];
797+
expect(field3OldArg.isDeprecated).to.equal(true);
798+
expect(field3OldArg.deprecationReason).to.equal('No longer supported');
799+
800+
const field4OldArg = rootFields.field4.args[0];
801+
expect(field4OldArg.isDeprecated).to.equal(true);
802+
expect(field4OldArg.deprecationReason).to.equal('why not?');
780803
});
781804

782805
it('Correctly extend scalar type', () => {
@@ -799,32 +822,6 @@ describe('Schema Builder', () => {
799822
`);
800823

801824
expect(printAllASTNodes(someScalar)).to.equal(scalarSDL);
802-
const rootFields = assertObjectType(schema.getType('Query')).getFields();
803-
804-
expect(rootFields.field2.isDeprecated).to.equal(true);
805-
expect(rootFields.field2.deprecationReason).to.equal('Because I said so');
806-
807-
const field3OldArg = rootFields.field3.args[0];
808-
expect(field3OldArg.isDeprecated).to.equal(true);
809-
expect(field3OldArg.deprecationReason).to.equal('No longer supported');
810-
811-
const field4OldArg = rootFields.field4.args[0];
812-
expect(field4OldArg.isDeprecated).to.equal(true);
813-
expect(field4OldArg.deprecationReason).to.equal('why not?');
814-
815-
const myInput = schema.getType('MyInput');
816-
const inputFields = myInput.getFields();
817-
818-
const newInput = inputFields.newInput;
819-
expect(newInput.isDeprecated).to.equal(false);
820-
821-
const oldInput = inputFields.oldInput;
822-
expect(oldInput.isDeprecated).to.equal(true);
823-
expect(oldInput.deprecationReason).to.equal('No longer supported');
824-
825-
const otherInput = inputFields.otherInput;
826-
expect(otherInput.isDeprecated).to.equal(true);
827-
expect(otherInput.deprecationReason).to.equal('Use newInput');
828825
});
829826

830827
it('Correctly extend object type', () => {

src/utilities/__tests__/schemaPrinter-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ describe('Type System Printer', () => {
678678
interfaces: [__Type!]
679679
possibleTypes: [__Type!]
680680
enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
681-
inputFields: [__InputValue!]
681+
inputFields(includeDeprecated: Boolean = false): [__InputValue!]
682682
ofType: __Type
683683
}
684684
@@ -886,7 +886,7 @@ describe('Type System Printer', () => {
886886
interfaces: [__Type!]
887887
possibleTypes: [__Type!]
888888
enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
889-
inputFields: [__InputValue!]
889+
inputFields(includeDeprecated: Boolean = false): [__InputValue!]
890890
ofType: __Type
891891
}
892892
@@ -921,7 +921,7 @@ describe('Type System Printer', () => {
921921
type __Field {
922922
name: String!
923923
description: String
924-
args: [__InputValue!]!
924+
args(includeDeprecated: Boolean = false): [__InputValue!]!
925925
type: __Type!
926926
isDeprecated: Boolean!
927927
deprecationReason: String

src/utilities/extendSchema.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,10 @@ const stdTypeMap = keyMap(
695695
* deprecation reason.
696696
*/
697697
function getDeprecationReason(
698-
node: EnumValueDefinitionNode | FieldDefinitionNode,
698+
node:
699+
| EnumValueDefinitionNode
700+
| FieldDefinitionNode
701+
| InputValueDefinitionNode,
699702
): ?string {
700703
const deprecated = getDirectiveValues(GraphQLDeprecatedDirective, node);
701704
return (deprecated?.reason: any);

src/utilities/printSchema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ function printDirective(directive, options) {
310310
}
311311

312312
function printDeprecated(fieldOrEnumVal) {
313-
if (!fieldOrEnumVal.isDeprecated) {
313+
if (fieldOrEnumVal.deprecationReason == null) {
314314
return '';
315315
}
316316
const reason = fieldOrEnumVal.deprecationReason;

0 commit comments

Comments
 (0)