Skip to content

Fix union & conditional directive (@skip and @include) not generating field types correctly - #10918

Merged
eddeee888 merged 4 commits into
masterfrom
fix-union-fragment
Aug 12, 2026
Merged

Fix union & conditional directive (@skip and @include) not generating field types correctly#10918
eddeee888 merged 4 commits into
masterfrom
fix-union-fragment

Conversation

@eddeee888

@eddeee888 eddeee888 commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Description

When updating Codegen packages in Console, we saw that there are issues with generated types:

Given a document like this:

mutation schemaPublish($input: SchemaPublishInput!, $usesGitHubApp: Boolean!) {
    schemaPublish(input: $input) {
      __typename
      ... on SchemaPublishSuccess @skip(if: $usesGitHubApp) {
        initial
        valid
        successMessage: message
        linkToWebsite
        changes {
          edges {
            __typename
          }
          ...RenderChanges_schemaChanges
        }
      }
      ... on SchemaPublishError @skip(if: $usesGitHubApp) {
        valid
        linkToWebsite
        changes {
          edges {
            __typename
          }
          ...RenderChanges_schemaChanges
        }
        errors {
          ...RenderErrors_SchemaErrorConnectionFragment
        }
      }
      ... on SchemaPublishMissingServiceError @skip(if: $usesGitHubApp) {
        missingServiceError: message
      }
      ... on SchemaPublishMissingUrlError @skip(if: $usesGitHubApp) {
        missingUrlError: message
      }
      ... on GitHubSchemaPublishSuccess @include(if: $usesGitHubApp) {
        message
      }
      ... on GitHubSchemaPublishError @include(if: $usesGitHubApp) {
        message
      }
      ... on SchemaPublishRetry {
        reason
      }
    }
  }

In @graphql-codegen/client-preset@5.1.1:

Screenshot 2026-08-11 at 10 39 49 pm

This is incorrect because fields in inline fragments should be optional

In @graphql-codegen/client-preset@6.1.2:

Screenshot 2026-08-11 at 11 23 07 pm

This is definitely incorrect because fields in inline fragments should be optional, and they are all gone here

This PR fixes it by correctly applying optionality to fields of a fragment marked with conditional directives when used in a union:

Screenshot 2026-08-11 at 11 33 48 pm

Note: this might be an issue for interfaces as well, but let's solve this one first.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit test
  • Release alpha and test in codebase

@changeset-bot

changeset-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 54a4bfd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@graphql-codegen/visitor-plugin-common Patch
@graphql-codegen/typescript-operations Patch
@graphql-codegen/client-preset Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

💻 Website Preview

The latest changes are available as preview in: https://pr-10918.graphql-code-generator.pages.dev

@eddeee888
eddeee888 marked this pull request as ready for review August 11, 2026 13:36
@eddeee888
eddeee888 marked this pull request as draft August 11, 2026 14:13
Repository owner deleted a comment from github-actions Bot Aug 12, 2026
@eddeee888
eddeee888 marked this pull request as ready for review August 12, 2026 12:20
@eddeee888
eddeee888 merged commit 6a3b734 into master Aug 12, 2026
32 of 36 checks passed
@eddeee888
eddeee888 deleted the fix-union-fragment branch August 12, 2026 12:21
negezor pushed a commit to senkuro-dev/graphql-code-generator that referenced this pull request Aug 14, 2026
…ting field types correctly (dotansimha#10918)

* Fix union and conditional directive types

* Add changeset

* Add test to ensure no double/tripple fragmentRefs/fragmentName

* Fix double added fragment names
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

Successfully merging this pull request may close these issues.

1 participant