Skip to content

Commit a22962e

Browse files
committed
Add test and support for deprecated args
1 parent dfb204e commit a22962e

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

src/type/definition.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ function defineFieldMap<TSource, TContext>(
743743
description: arg.description === undefined ? null : arg.description,
744744
type: arg.type,
745745
defaultValue: arg.defaultValue,
746+
isDeprecated: Boolean(arg.deprecationReason),
747+
deprecationReason: arg.deprecationReason,
746748
astNode: arg.astNode,
747749
};
748750
});

src/utilities/__tests__/buildASTSchema-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ describe('Schema Builder', () => {
631631
field1: String @deprecated
632632
field2: Int @deprecated(reason: "Because I said so")
633633
enum: MyEnum
634+
field3(oldArg: String @deprecated, arg: String): String
635+
field4(oldArg: String @deprecated(reason: "why not?"), arg: String): String
634636
}
635637
`;
636638
const output = cycleOutput(body);
@@ -658,6 +660,14 @@ describe('Schema Builder', () => {
658660

659661
expect(rootFields.field2.isDeprecated).to.equal(true);
660662
expect(rootFields.field2.deprecationReason).to.equal('Because I said so');
663+
664+
const field3OldArg = rootFields.field3.args[0];
665+
expect(field3OldArg.isDeprecated).to.equal(true);
666+
expect(field3OldArg.deprecationReason).to.equal('No longer supported');
667+
668+
const field4OldArg = rootFields.field4.args[0];
669+
expect(field4OldArg.isDeprecated).to.equal(true);
670+
expect(field4OldArg.deprecationReason).to.equal('why not?');
661671
});
662672

663673
it('Correctly assign AST nodes', () => {

src/utilities/buildASTSchema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ export class ASTDefinitionBuilder {
309309
type,
310310
description: getDescription(value, this._options),
311311
defaultValue: valueFromAST(value.defaultValue, type),
312+
deprecationReason: getDeprecationReason(value),
312313
astNode: value,
313314
};
314315
}

src/utilities/schemaPrinter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ function printInputValue(arg) {
300300
if (!isInvalid(arg.defaultValue)) {
301301
argDecl += ` = ${print(astFromValue(arg.defaultValue, arg.type))}`;
302302
}
303-
return argDecl;
303+
return argDecl + printDeprecated(arg);
304304
}
305305
306306
function printDirective(directive, options) {

0 commit comments

Comments
 (0)