dotansimha / dotansimha/graphql-code-generator

`@deprecated` directive on root resolver arguments does not get reflected in generated types

Open
#9,590 2 comments 8 reactions 1 assignee Claimed by @saihaj View on GitHub
core kind/bug stage/1-reproduction
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Which packages are impacted by your issue?

@graphql-codegen/cli, @graphql-codegen/typescript

### Describe the bug

Adding a `@deprecated` directive on the resolver arguments itself, does not show up in the generated types. Based on the [GraphQL spec](https://spec.graphql.org/draft/#sec--deprecated), `@deprecated` is supported on the resolver's argument.

### Your Example Website or App

https://the-guild.dev/graphql/codegen - Using the codegen playground

### Steps to Reproduce the Bug or Issue

This can be replicated in the graphql codegen playground.

- Go to https://the-guild.dev/graphql/codegen
- Select `Schema Types`

**schema.graphql**

```graphql
scalar Date

schema {
query: Query
}

type Query {
user(id: ID!, oldUserId: ID @deprecated(reason: "this field should be deprecated")): User
}

type User {
id: ID!
username: String!
email: String!
}
```

codegen.yml
```yml
generates:
types.ts:
plugins:
- typescript
```

autogenerated `types.ts`
```typescript
export type Maybe = T | null;
export type InputMaybe = Maybe;
export type Exact = { [K in keyof T]: T[K] };
export type MakeOptional = Omit & { [SubKey in K]?: Maybe };
export type MakeMaybe = Omit & { [SubKey in K]: Maybe };
export type MakeEmpty = { [_ in K]?: never };
export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: { input: string; output: string; }
String: { input: string; output: string; }
Boolean: { input: boolean; output: boolean; }
Int: { input: number; output: number; }
Float: { input: number; output: number; }
Date: { input: any; output: any; }
};

export type Query = {
__typename?: 'Query';
user?: Maybe;
};

export type QueryUserArgs = {
id: Scalars['ID']['input'];
oldUserId?: InputMaybe;
};

export type User = {
__typename?: 'User';
id: Scalars['ID']['output'];
username: Scalars['String']['output'];
email: Scalars['String']['output'];
};
```

### Expected behavior

I should expect this type to be generated instead

expected types.ts
```typescript
export type Maybe = T | null;
export type InputMaybe = Maybe;
export type Exact = { [K in keyof T]: T[K] };
export type MakeOptional = Omit & { [SubKey in K]?: Maybe };
export type MakeMaybe = Omit & { [SubKey in K]: Maybe };
export type MakeEmpty = { [_ in K]?: never };
export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: { input: string; output: string; }
String: { input: string; output: string; }
Boolean: { input: boolean; output: boolean; }
Int: { input: number; output: number; }
Float: { input: number; output: number; }
Date: { input: any; output: any; }
};

export type Query = {
__typename?: 'Query';
user?: Maybe;
};

export type QueryUserArgs = {
id: Scalars['ID']['input'];
/** @deprecated this field should be deprecated */
oldUserId?: InputMaybe;
};

export type User = {
__typename?: 'User';
id: Scalars['ID']['output'];
username: Scalars['String']['output'];
email: Scalars['String']['output'];
};
```

### Screenshots or Videos

image

### Platform

- OS: macOS 13.3.1
- `graphql` version: whatever version is on the playground
- `@graphql-codegen/typescript` version(s): whatever version is on the playground
- `@graphql-codegen/cli` version(s): whatever version is on the playground

### Codegen Config File

generates:
types.ts:
plugins:
- typescript

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.