Skip to content

Commit 83c7325

Browse files
smitt04modosc
authored andcommitted
Add test and support for deprecated args
1 parent 1d5850f commit 83c7325

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/type/definition.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,8 @@ function defineFieldMap<TSource, TContext>(
825825
type: argConfig.type,
826826
defaultValue: argConfig.defaultValue,
827827
extensions: argConfig.extensions && toObjMap(argConfig.extensions),
828+
isDeprecated: Boolean(argConfig.deprecationReason),
829+
deprecationReason: argConfig.deprecationReason,
828830
astNode: argConfig.astNode,
829831
}));
830832

src/utilities/__tests__/buildASTSchema-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,8 @@ describe('Schema Builder', () => {
736736
field1: String @deprecated
737737
field2: Int @deprecated(reason: "Because I said so")
738738
enum: MyEnum
739+
field3(oldArg: String @deprecated, arg: String): String
740+
field4(oldArg: String @deprecated(reason: "why not?"), arg: String): String
739741
}
740742
`;
741743
expect(cycleSDL(sdl)).to.equal(sdl);
@@ -790,6 +792,18 @@ describe('Schema Builder', () => {
790792
`);
791793

792794
expect(printAllASTNodes(someScalar)).to.equal(scalarSDL);
795+
const rootFields=assertObjectType(schema.getType('Query')).getFields();
796+
797+
expect(rootFields.field2.isDeprecated).to.equal(true);
798+
expect(rootFields.field2.deprecationReason).to.equal('Because I said so');
799+
800+
const field3OldArg = rootFields.field3.args[0];
801+
expect(field3OldArg.isDeprecated).to.equal(true);
802+
expect(field3OldArg.deprecationReason).to.equal('No longer supported');
803+
804+
const field4OldArg = rootFields.field4.args[0];
805+
expect(field4OldArg.isDeprecated).to.equal(true);
806+
expect(field4OldArg.deprecationReason).to.equal('why not?');
793807
});
794808

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

src/utilities/extendSchema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ export function extendSchemaImpl(
527527
type,
528528
description: getDescription(field, options),
529529
defaultValue: valueFromAST(field.defaultValue, type),
530+
deprecationReason: getDeprecationReason(field),
530531
astNode: field,
531532
};
532533
}

src/utilities/printSchema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ function printInputValue(arg) {
294294
if (defaultAST) {
295295
argDecl += ` = ${print(defaultAST)}`;
296296
}
297-
return argDecl;
297+
return argDecl + printDeprecated(arg);
298298
}
299299

300300
function printDirective(directive, options) {

0 commit comments

Comments
 (0)