dotansimha / dotansimha/graphql-code-generator

Mutation type comment propagated to parameter types

Open
#8,025 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Describe the bug

If a comment provided for the `Mutation` type, the CLI copies that comment to the argument type for each mutation.

For example, [EntityGraphQL](https://entitygraphql.github.io/) generates a GraphQL mutation type like this:

``` graphql
"""The mutation type schema represents all of the mutation functions in the schema"""
type Mutation {
myMutation(myParameter: String!): [MyResponseType!]!
}
```

The CLI-generated TypeScript from this type for for @apollo/client looks like:

``` typescript
/** The mutation type schema represents all of the mutation functions in the schema */
export type Mutation = {
__typename?: 'Mutation';
myMutation: Array;
};

/** The mutation type schema represents all of the mutation functions in the schema */
export type MyMutationArgs = {
myParameter: Scalars['String'];
};
```

Note how the comment on `MyMutationArgs` is incorrect. The comment indicates that `MyMutationArgs` is the set of all mutations, when really, it's the set of parameters for a given mutation.

Since the type name of generate types such as MyMutationArgs is self-describing, no comment is required at all.

### Your Example Website or App

https://entitygraphql.github.io/

### Steps to Reproduce the Bug or Issue

1. Create a .graphql file with a mutation.
2. Run `graphql-codegen`.

### Expected behavior

No comment on mutation arg types.

### Screenshots or Videos

_No response_

### Platform

- OS: Windows
- NodeJS: v16.15.1
- @graphql-codegen/cli: 2.6.2

### Codegen Config File

``` yaml
overwrite: true
schema: "src/generated/schema.graphql"
documents: "src/queries/*.graphql"
generates:
src/generated/gqlTypes.ts:
plugins:
- typescript
- typescript-operations
- typescript-react-apollo
```

### 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.