Skip to content

CODEGEN-940 Fix conditional directive (@skip and @include) incorrectly drop fields in Result when used on Inline Fragment / Fragment Spread#10899

Open
eddeee888 wants to merge 9 commits into
masterfrom
codegen-940-fix-conditional-directive-on-fragment
Open

CODEGEN-940 Fix conditional directive (@skip and @include) incorrectly drop fields in Result when used on Inline Fragment / Fragment Spread#10899
eddeee888 wants to merge 9 commits into
masterfrom
codegen-940-fix-conditional-directive-on-fragment

Conversation

@eddeee888

@eddeee888 eddeee888 commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Description

TODO:

  • Write description
  • Fix failing test

Related #10881

Type of change

Please delete options that are not relevant.

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

How Has This Been Tested?

  • Unit test

@changeset-bot

changeset-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f6c0103

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

This PR includes changesets to release 2 packages
Name Type
@graphql-codegen/visitor-plugin-common Patch
@graphql-codegen/typescript-operations 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

@eddeee888 eddeee888 changed the title CODEGEN-940 Fix conditional directive (@skip and @include) incorrectly drop fields in main Result when used on Inline Fragment / Fragment Spread CODEGEN-940 Fix conditional directive (@skip and @include) incorrectly drop fields in Result when used on Inline Fragment / Fragment Spread Jul 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

💻 Website Preview

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



export type UserSkipQuery = { user: { id: string } & { name?: string, niName?: string } & { age?: number, createdAt?: string } & ({ age: number, createdAt: string } | { age?: never, createdAt?: never }) | null };
export type UserSkipQuery = { user: { id: string } & { name?: string, niName?: string } & { age?: number, createdAt?: string } & ({ age?: number, createdAt?: string } | { age?: never, createdAt?: never }) | null };

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type change actually doesn't have any effect on the final merged type.

Here are the scenarios at runtime:

  1. When @include(if: false), the fields are not available i.e. { }. This is captured in the { age?: number, createdAt?: string } group where each field is undefined
  2. When @include(if: true):
    a. the fields are not available if they are deferred
    b. the fields are available if they are not deferred. HOWEVER, the fields could be undefined because it's used in conjunction with @skip.

@eddeee888
eddeee888 force-pushed the codegen-940-fix-conditional-directive-on-fragment branch from 347ba2f to 8ed8e78 Compare July 19, 2026 12:56
name: String!
nickName: String!
age: Int!
age: Int

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this nullable so we can see the difference between non-nullable and nullable fields when used with these directives

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-codegen/visitor-plugin-common 7.2.2-alpha-20260720140050-f6c010380b76ecfa068fb6136bba705a20c04536 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-operations 6.1.2-alpha-20260720140050-f6c010380b76ecfa068fb6136bba705a20c04536 npm ↗︎ unpkg ↗︎

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