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 readFragment() not deriving complex return types #15

Merged
merged 4 commits into from
Jan 17, 2024

Conversation

kitten
Copy link
Member

@kitten kitten commented Jan 17, 2024

Summary

When a complex fragment type (e.g. any fragment that derives to a union type of multiple object shapes) is passed to readFragment() then the return type would only infer as the first type of the union.

// derives to `{ wallOfText: string } | { maxLength: number }`
const fragment = graphql(`
  fragment Fields on ITodo {
    ... on BigTodo {
      wallOfText
    }
    ... on SmallTodo {
      maxLength
    }
  }
`);

// previously derived to: `{ wallOfText: string }`
// rather than: `{ wallOfText: string } | { maxLength: number }`
const fields = readFragment(fragment, data);

Set of changes

  • Add tests for readFragment inputs
  • Remove Data generic on readFragment and instead infer Data from Document directly

Copy link

changeset-bot bot commented Jan 17, 2024

🦋 Changeset detected

Latest commit: dccaf72

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

Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

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

What a find

@kitten kitten merged commit 018823f into main Jan 17, 2024
3 checks passed
@kitten kitten deleted the fix/read-fragment-of-unions branch January 17, 2024 14:03
@github-actions github-actions bot mentioned this pull request Jan 17, 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.

None yet

2 participants