Describe the bug
The schema I'm trying to generate types for contains some types that implement other types but don't contain any fields of their own. See the schema below for a minimal reproducible example.
The example below generates the following code:
type Maybe<T> = T | null;
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: string,
String: string,
Boolean: boolean,
Int: number,
Float: number,
};
export type GenericInterface = {};
export type SpecificInterface = GenericInterface & ;
The generated line type SpecificInterface = GenericInterface & ; is not valid TS.
To Reproduce
Steps to reproduce the behavior:
Run graphql-codegen --config codegen.yml with the config below. The code I've pasted is a minimal reproducible example and should work as of 1.0.6.
{
"__schema": {
"queryType": null,
"mutationType": null,
"subscriptionType": null,
"types": [
{
"kind": "INTERFACE",
"name": "GenericInterface",
"fields": [],
"inputFields": null,
"interfaces": null,
"enumValues": null
},
{
"kind": "OBJECT",
"name": "SpecificInterface",
"fields": [],
"inputFields": null,
"interfaces": [
{ "kind": "INTERFACE", "name": "GenericInterface", "ofType": null }
],
"enumValues": null,
"possibleTypes": null
}
]
}
}
Operations irrelevant.
codegen.yml config file:overwrite: true
schema: "./schema.json"
documents: "**/*.graphql"
generates:
src/types.tsx:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
Expected behavior
Expected generated code:
type Maybe<T> = T | null;
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: string,
String: string,
Boolean: boolean,
Int: number,
Float: number,
};
export type GenericInterface = {};
export type SpecificInterface = GenericInterface & {};
I.e. the final line should be an intersection between the other types and {}, which represents no fields.
Environment:
"@graphql-codegen/cli": "^1.0.6",
"@graphql-codegen/typescript": "1.0.6",
"@graphql-codegen/typescript-operations": "1.0.6",
"@graphql-codegen/typescript-react-apollo": "1.0.6",
@brainlessdeveloper, thank you for reporting it.
I managed to reproduce this issue and fix it: https://github.com/dotansimha/graphql-code-generator/pull/1596
Can you please test the alpha version? 1.0.7-alpha-ba1a94bb.4
How can I access the tag?
@brainlessdeveloper from npm, use that version instead of 1.0.6 in your package.json (just make sure to update all packages from @graphql-codegen/...)
Ah right, sorry :see_no_evil:
The generated types look great now. Thanks!
@brainlessdeveloper Great, so I'll update it once we'll release a stable version with this fix.
@dotansimha Random question, but what do you use for tagging and versioning this repository? It seems pretty tidy.
@brainlessdeveloper We are using lerna for managing releases and tags, along with with CI configuration for auto-release of alpha versions on each commit.
Changelog is done using GitHub Releases (on tags that have been created by lerna).
We tried https://github.com/conventional-changelog/conventional-changelog in the past but it created a lot of clutter on the changelogs, so we prefer to do it manually.
Thanks a lot!
Fixed in 1.0.7 :)