dotansimha / dotansimha/graphql-code-generator

Subscription "NameOfSubscription" must select only one top level field when using addTypenameSelectionDocumentTransform and generating code for subscription

Open
#9,888 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Which packages are impacted by your issue?

@graphql-codegen/client-preset

### Describe the bug

The `__typename` should not be added to the root node of a subscription when using `addTypenameSelectionDocumentTransform` with `documentTransforms` since a single root node is expected and the code generator fails because of that

### Your Example Website or App

https://github.com/Sojaner/graphql-code-generator-issue-sandbox-template

### Steps to Reproduce the Bug or Issue

1. Clone the [issue-sandbox-template repo](https://github.com/Sojaner/graphql-code-generator-issue-sandbox-template)
2. Install packages using yarn
3. `yarn generate` **(Test without the `addTypenameSelectionDocumentTransform` - Works fine)**
4. `yarn generate --add-typenames` **(Test with the `addTypenameSelectionDocumentTransform` - This will fail)**
5. `yarn generate --add-fixed-typenames` **(Test with the _patched_ `addTypenameSelectionDocumentTransform` - Works fine)**

### Expected behavior

Generating types from all types of documents should work when using the `addTypenameSelectionDocumentTransform` document transformer, but currently, the subscription types will cause an error and fail the code generation.

### Platform

- OS: Windows
- NodeJS: 20.11.1
- `graphql` version: N/A
- `@graphql-codegen/client-preset` version: 4.2.4

### Codegen Config File

```typescript
import { CodegenConfig } from "@graphql-codegen/cli";
import { addTypenameSelectionDocumentTransform } from "@graphql-codegen/client-preset";

const config: CodegenConfig = {
schema: "schema.graphql",
documents: "document.graphql",
generates: {
"types.ts": { plugins: ["typescript", "typescript-operations"], documentTransforms: [ addTypenameSelectionDocumentTransform] },
},
};

export default config;
```

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.