Describe the bug
FragmentDoc are imported without being used if used with near-operation-file preset and noGraphQLTag enabled. This happens when the fragment of a different file is being imported to be used in an operation.
Certain apps such as create-react-app enforces noUnusedLocals by default which causes TS compilation to fail.
To Reproduce
Go to this template and run yarn gg. GetProject.operation.generated.tsx is generated with 2 unused FragmentDoc: GetProject_IdFragmentDoc and GetProject_StatusFragmentDoc. These 2 fragments are separate files and are being used in the main GetProject query
https://codesandbox.io/s/gcg-14-experiments-c8l15
type Project {
id: ID!
status: Status!
}
enum Status {
INITIAL
PENDING
COMPLETED
}
type Query {
project: Project!
}
schema {
query: Query
}
// GetProject_Id.graphql
fragment GetProject_Id on Project {
id
}
// GetProject_Status.graphql
fragment GetProject_Status on Project {
status
}
// GetProject.graphql
fragment GetProject_All on Project {
id
status
}
query GetProject {
project {
...GetProject_Id
...GetProject_Status
...GetProject_All
}
}
codegen.yml config file:overwrite: true
schema: 'schema.graphql'
documents: './src/**/*.graphql'
generates:
src/__generated__/types.ts:
plugins:
- typescript
src/:
preset: near-operation-file
presetConfig:
baseTypesPath: __generated__/types.ts
extension: .generated.tsx
plugins:
- typescript-operations
- typescript-react-apollo
config:
noGraphQLTag: true
Expected behavior
It should not include FragmentDoc if it's not used
Additional context
This is probably a side effect of https://github.com/dotansimha/graphql-code-generator/pull/2106?
Thanks @eddeee888 , and sorry for the delay. Fixed in: https://github.com/dotansimha/graphql-code-generator/pull/2260 , you can try it with the alpha 1.4.1-alpha-6ee432d2.57.
@dotansimha Woo hoo! It's working as expected! Cheers mate!
Fixed in 1.5.0 馃帀