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

fix: Fix __typename fields on abstract selections not being exact #11

Merged
merged 8 commits into from
Jan 16, 2024

Conversation

kitten
Copy link
Member

@kitten kitten commented Jan 16, 2024

Summary

When a __typename field is used on an abstract type’s selection set its value type wouldn’t be exact and instead a union of all possible types unless all possible types have selections containing a __typename field themselves.

{
  test { # possible types: A / B
    __typename
    ... on B {
      field
    }
  }
}

The above would result in an incorrect inference since B’s selection set doesn't contain __typename itself:

const before: {
  test: {
    __typename: 'A' | 'B';
  } | {
    __typename: 'A' | 'B';
    field: unknown;
  };
};

const after: {
  test: {
    __typename: 'A';
  } | {
    __typename: 'B';
    field: unknown;
  };
};

Set of changes

  • Move __typename field handling to the selection handler that handles all possible types separately
  • Remove field handling entirely in favour of always handling fields per possible type
  • Refactor and rename utilities as appropriate

Copy link

changeset-bot bot commented Jan 16, 2024

🦋 Changeset detected

Latest commit: e895c89

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

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 github-actions bot temporarily deployed to pull request January 16, 2024 17:06 Inactive
@kitten kitten merged commit 7986c54 into main Jan 16, 2024
4 checks passed
@kitten kitten deleted the fix/typename-on-abstract-types branch January 16, 2024 17:12
@github-actions github-actions bot mentioned this pull request Jan 16, 2024
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.

2 participants