Skip to content

Duplicate fragment names (in multiple files) causes command to fail #5196

@joesaunderson

Description

@joesaunderson

Describe the bug
I have two separate queries, with separate fragments (named the same).

These queries are in different directories within my project, so I would expect both of them to create separate EntityFragment types in the generated files.

Instead, I receive this error:

yarn run v1.22.4
$ graphql-codegen --config codegen.yml
Multiple fragments with the name(s) "entity" were found.
Multiple fragments with the name(s) "entity" were found.
Not all fragments have an unique name: entity
Not all fragments have an unique name: entity
Something went wrong
error Command failed with exit code 1.

To Reproduce
Steps to reproduce the behavior:

  1. My GraphQL schema:

File 1:

fragment entity on Entity {
    id
    somefield
}

File 2:

fragment entity on Entity {
    id
    someotherfield
}
  1. My codegen.yml config file:
overwrite: true
errorsOnly: true
schema:
    - schema.graphql:
          loader: "./app/scripts/webpack/graphql-schema.js"
documents: "src/**/*.graphql"
generates:
    src/js/shared/@types/graphql.d.ts:
        plugins:
            - "typescript"
        config:
            skipTypename: true
            useTypeImports: true
            declarationKind: "interface"
    src/:
        preset: near-operation-file
        presetConfig:
            extension: .generated.ts
            baseTypesPath: js/shared/@types/graphql.ts
        plugins:
            - "typescript-operations"
            - "typed-document-node"
        config:
            skipTypename: true
            declarationKind: "interface"

Expected behavior

Environment:

  • OS: Ubuntu
        "@graphql-codegen/cli": "1.19.1",
        "@graphql-codegen/near-operation-file-preset": "^1.17.12",
        "@graphql-codegen/typed-document-node": "^1.17.10",
        "@graphql-codegen/typescript": "1.17.11",
        "@graphql-codegen/typescript-operations": "1.17.9",
  • NodeJS: 14.7.0

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions