dotansimha / dotansimha/graphql-code-generator

Avoid optional ignored when all arguments optional

Open
#9,438 0 comments 1 reaction 0 assignees View on GitHub
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/typescript-resolvers

### Describe the bug

Given the following schema with `avoidOptionals: true`:
```gql
type Query {
userById(id: ID): User!
}

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

We get a correct argument type:
```ts
export type QueryUserByIdArgs = {
id: InputMaybe;
};
```

However, in the actual resolver type itself, optionals are incorrectly introduced by wrapping this type with a Partial
```ts
export type QueryResolvers = {
userById: Resolver>;
};
```

### Your Example Website or App

https://codesandbox.io/p/sandbox/spring-hill-ebr1nw

### Steps to Reproduce the Bug or Issue

1. open the codesandbox and look at the generated types file

### Expected behavior

I would expect that when implementing the resolver, I would not get any optional argument types. For example, in this case the following code would be expected:

```ts
export type QueryResolvers = {
userById: Resolver;
};
```

### Screenshots or Videos

_No response_

### Platform

- "@graphql-codegen/typescript": "3.0.4",
- "@graphql-codegen/typescript-resolvers": "3.2.1",

### Codegen Config File

```ts
const config: CodegenConfig = {
schema: "schema.graphql",
documents: [],
generates: {
"types.ts": { plugins: ["typescript", "typescript-resolvers"] },
},
config: {
avoidOptionals: true,
},
};
```

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