dotansimha / dotansimha/graphql-code-generator
'Types' is declared but its value is never read
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
**Describe the bug**
When generate separated files for fragments, added
import * as Types from './types';
in any case, ever Types does not using.
Generated code:
```ts
# Never use cause fragment does not have Maybe<> fields
import * as Types from './types';
import { gql } from '@apollo/client';
export type TopicsConnectionTopicFragment = { __typename?: 'Resource', id: string, updatedAt: any, name: string, uri: string };
export const TopicsConnectionTopicFragmentDoc = gql`
fragment topicsConnectionTopic on Resource {
id
updatedAt
name
uri
}
`;
```
**To Reproduce**
Steps to reproduce the behavior:
```js
function createQueriesMap(filesMap: any) {
let documentsString = ''
for (const contents of filesMap.values()) {
documentsString += contents + '\n'
}
const definitions = parse(documentsString).definitions
const queriesAndFragments = definitions.filter(
({ kind }) =>
kind === 'OperationDefinition' || kind === 'FragmentDefinition'
) as Array
const queriesMap = new Map()
queriesAndFragments.forEach((definition) => {
if (definition.name && definition.loc) {
const name = definition.name.value
const oldText = queriesMap.get(name)
if (!oldText) {
queriesMap.set(
name,
documentsString.substring(definition.loc.start, definition.loc.end)
)
} else {
const newText = documentsString.substring(
definition.loc.start,
definition.loc.end
)
if (
oldText.replace(/\r/g, '').trim() !==
newText.replace(/\r/g, '').trim()
) {
throw new Error(`duplicate definitions ${name}`)
}
}
}
})
return queriesMap
}
```
1. My GraphQL schema:
```graphql
# Put your schema here
fragment topicsConnectionTopic on Resource {
id
updatedAt
name
uri
}
```
3. My `codegen conf` config file:
```js
const codegenConfig = {
plugins: [
{
add: {
content: prependText.join(''),
},
},
'typescript-operations',
'typescript-react-apollo',
],
preset: 'near-operation-file',
presetConfig: {
extension: '.ts',
baseTypesPath: './types.ts',
},
config: {
withHOC: false,
withHooks: true,
withComponent: false,
preResolveTypes: true,
exportFragmentSpreadSubTypes: true,
},
}
```
**Expected behavior**
**Environment:**
- OS:
- `@graphql-codegen/...`:
- NodeJS:
**Additional context**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.