dotansimha / dotansimha/graphql-code-generator
Non-nullable arguments with default types are optional
- 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:
```gql
type Query {
userById(id: ID! = "dummy-id", name: String!): User!
}
type User {
id: ID!
username: String!
email: String!
}
```
We get the following type for the argument type:
```ts
export type QueryUserByIdArgs = {
id?: Scalars['ID'];
name: Scalars['String'];
};
```
Which allows the `id` argument to be optional even though its non nullable. From a consumers perspective, this can be nulled, but for implementing the resolver, it should not be nullable.
On the actual resolver type itself, its made to be non nullable:
```ts
export type QueryResolvers = {
userById?: Resolver>;
};
```
but this type is not available anywhere for import.
### Your Example Website or App
https://codesandbox.io/p/sandbox/heuristic-marco-95pkb9
### Steps to Reproduce the Bug or Issue
1. Go to codesandbox and look at the generated types file
### Expected behavior
I would expect for their to be an argument type available when implementing the resolver that correctly has `id` as non nullable. So having a type like this available for import at the very least:
```ts
export type QueryUserByIdResolverArgs = {
id: Scalars['ID'];
name: Scalars['String'];
};
```
or even:
```ts
export type QueryUserByIdResolverArgs = RequireFields
```
### 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"] },
},
};
```
### Additional context
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.