dotansimha / dotansimha/graphql-code-generator
Interfaces not handled properly in typescript and typescript-mongodb plugins
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
**Describe the bug**
2 issues:
1. A child interface that implements a parent interface does not actually do so with code generated under the "typescript" plugin even though the feature is now supported under the GraphQL spec and graphql-js as of v15.0.0.
2. The "typescript-mongodb" plugin does not properly reference a DbInterface for a field that specifies an interface as its type instead of an object.
**To Reproduce**
Steps to reproduce the behavior:
Link to code sandbox that demonstrates the behavior (check the files in the generated dir):
https://codesandbox.io/s/graphql-code-generator-interface-bug-044g6y
1. My GraphQL schema:
```graphql
interface Node @abstractEntity(discriminatorField: "type") {
id: ID! @id
}
interface ChildInterface implements Node
@abstractEntity(discriminatorField: "childType") {
example1: String! @column
}
type ExampleObject implements ChildInterface @entity {
example2: Node! @link
example3: ChildInterface! @link
}
```
2. My GraphQL operations:
```graphql
# Not relevant
```
3. My `codegen.yml` config file:
```yml
schema: schema.graphql
generates:
generated/typescript-types.ts:
plugins:
- typescript
generated/mongodb-types.ts:
plugins:
- typescript
- typescript-mongodb
```
**Expected behavior**
Expected TypeScript output:
```typescript
export type Scalars = {
ID: string;
String: string;
Boolean: boolean;
Int: number;
Float: number;
}
export type Node = {
id: Scalars["ID"];
}
export type ChildInterface = Node & {
example1: Scalars["String"];
}
```
Expected MongoDB output:
```typescript
import { ObjectId } from "mongodb";
export type NodeDbInterface = {
_id: ObjectId;
type: string;
};
export type ChildInterfaceDbInterface = NodeDbInterface & {
example1: string;
childType: string;
};
export type ExampleObjectDbObject = ChildInterfaceDbInterface & {
example2: NodeDbInterface["_id"];
example3: ChildInterfaceDbInterface["_id"];
};
```
**Environment:**
- OS: macOS Monterey v12.2.1
- `@graphql-codegen/typescript`: 2.4.5
- `@graphql-codegen/typescript-mongodb`: 4.4.1
- NodeJS: 17.2.0
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.