dotansimha / dotansimha/graphql-code-generator

Never type incorrectly generated for interfaces

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

Description

**Issue:** Generating type definitions for a query which returns an interface outputs that interface type as `never`

**Steps to reproduce:**
`schema.graphql`:
```
schema {
query: Query
}

type Query {
user(id: ID!): User
}

interface User {
id: ID!
name: String!
}
```

`operations.graphql`
```
query findUser($userId: ID!) {
user(id: $userId) {
id
name
}
}
```

`codegen.yml`
```
generates:
types-and-hooks.tsx:
plugins:
- typescript
- typescript-operations
- typescript-react-apollo
```

Results in (abbreviated to highlight the issue):
```
...
export type User = {
id: Scalars['ID'];
name: Scalars['String'];
};

export type FindUserQuery = { __typename?: 'Query', user?: never | null };
...
```

You can reproduce this at https://www.graphql-code-generator.com/ by inputting the same values for the various files into the appropriate input fields within that UI.

**Expected result:** The `export type FindUserQuery` should specify the optional `user?: User | null` instead of `user?: never | null`

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.