dotansimha / dotansimha/graphql-code-generator-community

`near-operation-file` preset: "Multiple fragments with the name(s) ... were found" error with fragments in different directories

Open
#405 2 comments 1 reaction 0 assignees View on GitHub
waiting-for-answer
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

### Which packages are impacted by your issue?

@graphql-codegen/near-operation-file-preset

### Describe the bug

![image](https://github.com/dotansimha/graphql-code-generator-community/assets/61546355/7aab43be-d57e-41d2-a6c2-79d1009a88e8)
This is the result of running npx graphql-codegen --verbose

The directory structure is as follows with each fragment appearing once in different files and different directories.
![image](https://github.com/dotansimha/graphql-code-generator-community/assets/61546355/8e7b94b5-3a55-4a48-9296-3682b29d6e32)

If I comment out two of these, it breaks my code but all of the types are correctly generated for other modules in `[moduleName].generated.ts` and in the same directory as that module.

It's necessary that these fragments all share the same name because the parent is responsible for rendering the child component and it passes a fragment to tell it what fields it needs fetched from the API, and the child spread the fragment into its own query.

From what I understand the `skipDocumentsValidation.skipDuplicateValidation` is the related config setting: https://the-guild.dev/graphql/codegen/docs/config-reference/codegen-config

And it's supposed to be active by default:
https://github.com/dotansimha/graphql-code-generator-community/blob/9fb6b6eb31b076cdd752a19e95f494eed399319b/packages/presets/near-operation-file/src/index.ts#L343

### Your Example Website or App

example.com

### Steps to Reproduce the Bug or Issue

1. Make fragments with the same name in nested directories under the `components` directory, using `gql` template tag.
2. Run the codegen with the provided settings.

### Expected behavior

I expected that the codegen would write the generated types to file without error. Since I'm using the `near-operation-file` preset it shouldn't matter if there's a naming conflict in different directories because each different fragment type definition will be written to its own `ts` file in a different location.

### Screenshots or Videos

_No response_

### Platform

- OS: Windows 10
- NodeJS: 16.16.0
- `graphql` version: 16.6.0
- `@graphql-codegen/cli`: 5.0.0
- `@graphql-codegen/core`: 4.0.0
- `@graphql-codegen/typescript`: 4.0.1
- `@graphql-codegen/typescript-operations`: 4.0.1
- `@graphql-codegen/near-operation-file-preset`: 2.5.0

### Codegen Config File

```ts
// codegen.ts
import { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
schema: 'http://localhost/graphql',
ignoreNoDocuments: true, // for better experience with the watcher
generates: {
'types/operationTypes.ts': {
plugins: ['typescript'],
},
'./': {
documents: ['components/**/!(*.generated).{ts,tsx}'],
preset: 'near-operation-file',
presetConfig: {
extension: '.generated.ts',
baseTypesPath: 'types/operationTypes.ts',
},
plugins: ['typescript-operations']
}
}
}

export default config;
```

### Additional context

Related issues:
https://github.com/dotansimha/graphql-code-generator-community/pull/383
https://github.com/dotansimha/graphql-code-generator/issues/5196
https://github.com/dotansimha/graphql-code-generator/issues/2890

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.