typescript: Code generation fails when a type in the GraphQL schema is a reserved Typescript type alongside usage of a plugin that utilizes that type #10161
We had an instance where a GraphQL schema had a type name on it called Record. The Typescript type generator generates the following for this:
export type Record = {
__typename?: 'Record';
wins?: Maybe<Scalars['Int']['output']>;
};
This causes issues elsewhere in the generated code, as it overrides the built-in Typescript Record type used in the generated Typescript file, which causes Typescript issues.
Specifically, Record seems to be an issue with the following configuration options:
constructor(private value: string, public __meta__?: Record<string, any>) {
with the error:
Type 'Record' is not generic.(2315)
Expected behavior
As as user, I would expect the GraphQL type generator to not generate types that override Typescript built-ins, and instead rename or suffix types that collide with builtin types.
Screenshots or Videos
No response
Platform
NodeJS: v18.20.3
graphql version: 16.2.0
@graphql-codegen/* version(s): 5.0.2
Codegen Config File
import { CodegenConfig } from '@graphql-codegen/cli';
Which packages are impacted by your issue?
No response
Describe the bug
We had an instance where a GraphQL schema had a type name on it called
Record
. The Typescript type generator generates the following for this:This causes issues elsewhere in the generated code, as it overrides the built-in Typescript
Record
type used in the generated Typescript file, which causes Typescript issues.Specifically,
Record
seems to be an issue with the following configuration options:The generated types include:
Your Example Website or App
https://stackblitz.com/edit/github-yjyxnx?file=schema.graphql
Steps to Reproduce the Bug or Issue
yarn generate
.src/generated/graphql.ts
.with the error:
Expected behavior
As as user, I would expect the GraphQL type generator to not generate types that override Typescript built-ins, and instead rename or suffix types that collide with builtin types.
Screenshots or Videos
No response
Platform
graphql
version: 16.2.0@graphql-codegen/*
version(s): 5.0.2Codegen Config File
import { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = { schema: 'schema.graphql', documents: ['src/*/.ts'], ignoreNoDocuments: true, generates: { './src/generated/graphql/': { preset: 'client', config: { documentMode: 'string', }, }, './schema.graphql': { plugins: ['schema-ast'], config: { includeDirectives: true, }, }, }, }; export default config;
Additional context
No response