When a fragment is created that only includes other fragments, like the following
export const DetailedFileAttachmentFields = gql`
fragment MyFragment on MyType {
...SomeOtherFragment
aNestedField {
...SomeOtherFragment
}
}
${SomeOtherFragment}`
The generated file includes import * as Types from '...'; when it shouldn't, as the generated fragment does not use Types. This causes an issue with Typescript and noUnusedLocals
Packages I'm using are as follows:
"@graphql-codegen/add": "^1.8.3",
"@graphql-codegen/cli": "^1.8.3",
"@graphql-codegen/fragment-matcher": "1.8.3",
"@graphql-codegen/import-types-preset": "^1.8.3",
"@graphql-codegen/introspection": "1.8.3",
"@graphql-codegen/near-operation-file-preset": "1.8.4-alpha-11f86a7d.48+11f86a7d",
"@graphql-codegen/typescript": "1.8.3",
"@graphql-codegen/typescript-operations": "^1.8.3",
"@graphql-codegen/typescript-react-apollo": "1.8.3",
I'm using an alpha version for the fix it includes for the issue here https://github.com/dotansimha/graphql-code-generator/issues/2912
codegen.yml looks like
overwrite: true
schema: './node_modules/my/path/*.graphql'
documents: './graphql/**/*.gql.ts'
generates:
graphql/:
preset: near-operation-file
presetConfig:
extension: .generated.tsx
baseTypesPath: '~my/package'
folder: generated
plugins:
- add: '/* THIS FILE WAS GENERATED BY GRAPHQL CODE GENERATOR. DO NOT EDIT. */'
- 'typescript-operations'
- 'typescript-react-apollo'
config:
documentMode: 'external'
importDocumentNodeExternallyFrom: 'near-operation-file'
withHooks: true
withHOC: true
reactApolloVersion: 3
hooks:
afterOneFileWrite:
- prettier --write
we're facing the same issue with fragments 馃槥
Most helpful comment
we're facing the same issue with fragments 馃槥