Describe the bug
typescript-graphql-files-modules only considers the file name, not the full path, and generates declare module '*/{filename}'. If there are multiple files with the same name, e.g. query.graphql, multiple declare module '*/query.graphql' are generated, which creates conflicts on the return types.
To Reproduce
The following file structure:
- src
- A
- index.tsx
- query.graphql
- B
- index.tsx
- query.graphql
Generates
declare module '*/query.graphql' {
import { DocumentNode } from 'graphql';
const defaultDocument: DocumentNode;
const AQuery: DocumentNode;
export { AQuery };
export default defaultDocument;
}
declare module '*/query.graphql' {
import { DocumentNode } from 'graphql';
const defaultDocument: DocumentNode;
const BQuery: DocumentNode;
export { BQuery };
export default defaultDocument;
}
yaml config:
overwrite: true
schema: schema.graphql
documents: 'src/**/*.graphql'
generates:
src/types/gql-gen/tsd.d.ts:
plugins:
- 'typescript-graphql-files-modules'
Expected behavior
To generate full file paths:
declare module 'src/A/query.graphql' {
import { DocumentNode } from 'graphql';
const defaultDocument: DocumentNode;
const AQuery: DocumentNode;
export { AQuery };
export default defaultDocument;
}
declare module 'src/B/query.graphql' {
import { DocumentNode } from 'graphql';
const defaultDocument: DocumentNode;
const BQuery: DocumentNode;
export { BQuery };
export default defaultDocument;
}
and prevent conflicts.
Hi @elado !
Thank you for reporting this issue. @dobesv already reported it: https://github.com/dotansimha/graphql-code-generator/issues/1165 and we already fixed it in the latest refactor (https://github.com/dotansimha/graphql-code-generator/pull/1353). We hope to release it very soon.
@dotansimha I have had this problem too! Did the plugin support this feature?
@VienNguyen113 Which version do you use?
@dotansimha I'm using 1.1.3. Is there any config to allow the plugin to generate the absolute path (via the config) instead of */{filename}.graphql. Currently, I have to write a script to do that. Updated to 1.8.3 and don't see it works too
@VienNguyen113 can you please open a new issue with the output you are getting with 1.8.3? thank you :)
@dotansimha https://codesandbox.io/s/codegen-sanbox-92u2i I've created a sample here.
current result: src/generated/index.d.ts:
declare module '*/test.graphql' {
import { DocumentNode } from 'graphql';
const defaultDocument: DocumentNode;
export const getUser: DocumentNode;
export default defaultDocument;
}
-expected result is:
```javascript
declare module '/client/test.graphql' {
import { DocumentNode } from 'graphql';
const defaultDocument: DocumentNode;
export const getUser: DocumentNode;
export default defaultDocument;
}
```
@dotansimha I'm also having the same issue, should this be re-opened? The codesandbox repo above looks to be replicating the issue mentioned.
Seeing the same here as well.
@ebenoist @webberwang @VienNguyen113 I think we already fixed it. Can you please try the latest? If it's still relevant, can you please open a new issue?
I'll check it out with the latest. Thank you!
Most helpful comment
Hi @elado !
Thank you for reporting this issue. @dobesv already reported it: https://github.com/dotansimha/graphql-code-generator/issues/1165 and we already fixed it in the latest refactor (https://github.com/dotansimha/graphql-code-generator/pull/1353). We hope to release it very soon.