dotansimha / dotansimha/graphql-code-generator

Combining typed-document-node with import-types

Open
#5,670 1 comment 1 reaction 0 assignees View on GitHub
core kind/enhancement plugins presets
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

Hello,

I've tried combining this plugin with the import-types preset, as follows, but couldn't get it to work.
The generated typed-document-nodes.ts file does get the import, but doesn't use it.

Here's the codegen.yml config file:
```
# graphql-codegen configuration

# Always replace files
overwrite: true

# Schema file to use as input
schema: ./apps/writer-plan/server/graphql/generated/schema.graphql

# All GraphQL queries (could also be extracted from TS files!)
documents: ./apps/writer-plan/client/graphql/queries/*.graphql

# Output to generate
generates:
./apps/writer-plan/client/graphql/generated/graphql.client.types.ts:
plugins:
- typescript
- typescript-operations
config:
immutableTypes: true
./apps/writer-plan/client/graphql/generated/typed-document-nodes.ts:
preset: import-types
presetConfig:
typesPath: ./graphql.client.types
# https://graphql-code-generator.com/docs/plugins/typescript-document-nodes
plugins:
- typed-document-node
hooks:
afterAllFileWrite:
- prettier --write
```

And the generated TS file:

```
import * as Types from './graphql.client.types';

import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
import gql from 'graphql-tag';

export const PingDocument: DocumentNode = gql`
query ping {
ping {
message
timestamp
}
}
`;

```

As you can see, it does import the types, but doesn't use them below.

Am I using this incorrectly?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.