dotansimha / dotansimha/graphql-code-generator-community
`near-operation-file` preset: "Multiple fragments with the name(s) ... were found" error with fragments in different directories
- 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

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.

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.