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

Generate valid types when the same field is selected by both conditional and unconditional fragments #4915

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vhfmag
Copy link

@vhfmag vhfmag commented Feb 20, 2025

This fixes #4914 — check the original issue for details about the bug this tries to solve. Here's how the types generated differ before and after this change:

TypescriptFlow
Before
export type AppQuery$rawResponse = {
  readonly account: {
    readonly id: string;
    readonly name: string;
  } | null | undefined;
  readonly account: {
    readonly email: string;
  } | null | undefined;
};
export type AppQuery$rawResponse = {|
  +me: ?{|
    +firstName: ?string,
    +id: string,
  |},
  +me?: ?{|
    +lastName: ?string,
  |},
|};
After
export type AppQuery$rawResponse = {
  readonly account: {
    readonly id: string;
    readonly name: string;
    readonly email?: string;
  } | null | undefined;
};
export type AppQuery$rawResponse = {|
  +me: ?{|
    +firstName: ?string,
    +id: string,
    +lastName?: ?string,
  |},
|};

More specifically, if both conditional and unconditional selections are present for a given linked field, it emits a single non-optional prop, but handles fields from the conditional selection as if they were conditional themselves (AKA ...Fragment @include(if: $condition) + fragment Fragment on Type { field } behaves the same as ...Fragment + fragment Fragment on Type { field @include(if: $condition) }.

@facebook-github-bot
Copy link
Contributor

Hi @vhfmag!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants