Skip to content

Commit aa1e6ea

Browse files
samchungysaihaj
andauthored
feat: add support for deprecated input fields (#7767)
* feat: add support for deprecated input fields * chore: add issue number * Create fresh-elephants-provide.md * Update fresh-elephants-provide.md * Apply suggestions from code review Co-authored-by: Saihajpreet Singh <saihajpreet.singh@gmail.com>
1 parent 0f40df9 commit aa1e6ea

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

‎.changeset/fresh-elephants-provide.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@graphql-codegen/typescript": minor
3+
"@graphql-codegen/visitor-plugin-common": minor
4+
---
5+
6+
Add @Deprecated support for input

‎packages/plugins/other/visitor-plugin-common/src/base-types-visitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ export class BaseTypesVisitor<
834834
return null;
835835
}
836836

837-
getNodeComment(node: FieldDefinitionNode | EnumValueDefinitionNode): string {
837+
getNodeComment(node: FieldDefinitionNode | EnumValueDefinitionNode | InputValueDefinitionNode): string {
838838
let commentText: string = node.description as any;
839839
const deprecationDirective = node.directives.find((v: any) => v.name === 'deprecated');
840840
if (deprecationDirective) {

‎packages/plugins/typescript/typescript/src/visitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ export class TsVisitor<
295295
!this.config.avoidOptionals.inputValue &&
296296
(originalFieldNode.type.kind !== Kind.NON_NULL_TYPE ||
297297
(!this.config.avoidOptionals.defaultValue && node.defaultValue !== undefined));
298-
const comment = transformComment(node.description as any as string, 1);
298+
const comment = this.getNodeComment(node);
299299
const declarationKind = this.config.declarationKind.type;
300300

301301
let type: string = node.type as any as string;

‎packages/plugins/typescript/typescript/tests/typescript.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,23 @@ describe('TypeScript', () => {
954954
validateTs(result);
955955
});
956956

957+
it('#7766 - input value @deprecated directive support', async () => {
958+
const schema = buildSchema(`
959+
input MyInput {
960+
A: Int
961+
B: Int @deprecated(reason: "input value \`B\` has been deprecated.")
962+
}`);
963+
964+
const result = await plugin(schema, [], {}, { outputFile: '' });
965+
expect(result.content).toBeSimilarStringTo(`
966+
export type MyInput = {
967+
A?: InputMaybe<Scalars['Int']>;
968+
/** @deprecated input value \`B\` has been deprecated. */
969+
B?: InputMaybe<Scalars['Int']>;
970+
};`);
971+
validateTs(result);
972+
});
973+
957974
it('#1462 - Union of scalars and argument of directive', async () => {
958975
const schema = buildSchema(`
959976
union Any = String | Int | Float | ID

0 commit comments

Comments
 (0)