Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Sojaner opened this issue Feb 29, 2024 · 0 comments

Comments

@Sojaner
Copy link
Contributor

Sojaner commented Feb 29, 2024

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
  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

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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant