dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.8k stars 1.32k forks source link

Duplicate type definitions in the output file #9093

Closed tlehwalder closed 1 year ago

tlehwalder commented 1 year ago

Which packages are impacted by your issue?

@graphql-codegen/cli, @graphql-codegen/typescript-operations

Describe the bug

When running graphql-codegen with the provided configuration, the generated output file contains duplicate type definitions for every type.

I run graphql-codegen --config codegen.ts

the config-file (codegen.ts):

import type { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
  overwrite: true,
  schema: 'http://localhost:4000',
  documents: ['**/src/**/*.tsx'],
  generates: {
    './generated-graphl-types/': {
      preset: "client-preset",
      plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
    },
  },
}

export default config

I found similar issues, where the preset was named as the root cause, but i tried different presets and either I get an error or face the same issue.

Your Example Website or App

none

Steps to Reproduce the Bug or Issue

  1. Run graphql-codegen --config codegen.tswith the given config
  2. Inspect generated file at ./generated-graphl-types/graphql.ts

Expected behavior

Types shouldn't be duplicated in the output file

Screenshots or Videos

No response

Platform

Codegen Config File

import type { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = { overwrite: true, schema: 'http://localhost:4000', documents: ['/src//.tsx'], // '/src//.ts' generates: { './generated-graphl-types/': { preset: "client-preset", plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'], }, }, }

export default config

Additional context

No response

tlehwalder commented 1 year ago

It looks like the ** at the beginning of documents was the issue

ghost commented 1 year ago

import type { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
  overwrite: true,
  schema: "https://beta.pokeapi.co/graphql/v1beta",
  documents: "./src/**/*.ts",
  generates: {
    "src/gql/": {
      preset: "client",
      plugins: ["@graphql-codegen/typescript-react-apollo"]
    }
  },
};

export default config;

I am using this config to geenrate the types and it is generating duplicate types

I am using this plugins with next js