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

change UseFragmentResult to union type #10765

Merged
merged 5 commits into from
May 4, 2023

Conversation

phryneas
Copy link
Member

This should be merged after #10764 and is the second half of suggestions from #10760 and would address #10650.

It also adds a test to make sure the types actually reflect the real behaviour.

Checklist:

  • If this PR contains changes to the library itself (not necessary for e.g. docs updates), please include a changeset (see CONTRIBUTING.md)
  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

@changeset-bot
Copy link

changeset-bot bot commented Apr 14, 2023

🦋 Changeset detected

Latest commit: 930623f

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

This PR includes changesets to release 1 package
Name Type
@apollo/client 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

@@ -115,7 +121,7 @@ function diffToResult<TData>(
diff: Cache.DiffResult<TData>,
): UseFragmentResult<TData> {
const result: UseFragmentResult<TData> = {
data: diff.result,
data: diff.result!,
Copy link
Member Author

Choose a reason for hiding this comment

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

From what I saw in the tests, this will never be undefined, but come out as {} - I adjusted the types accordingly.
@benjamn, can you please take a look here to make sure I didn't forget about some edge case?

@@ -349,9 +350,10 @@ describe("useFragment", () => {
from: { __typename: "Query" },
});
expect(complete).toBe(true);
assert(!!complete)
Copy link
Member Author

Choose a reason for hiding this comment

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

the assert call is here so TypeScript knows that data is complete in the JSX.

Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

Had a couple minor suggestions. Thanks for getting this updated!

src/react/hooks/useFragment.ts Outdated Show resolved Hide resolved
.changeset/grumpy-tips-know.md Outdated Show resolved Hide resolved
missing?: MissingTree;
}
| {
data: Partial<TData>;
Copy link
Member

Choose a reason for hiding this comment

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

Should we use a DeepPartial here since you can give a fragment that could contain nested field selections?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. We don't have a DeepPartial type at this point yet though - and the one added with #10766 will land in 3.8. We should coordinate around that.

@phryneas phryneas self-assigned this Apr 17, 2023
Base automatically changed from pr/deprecate-useFragment-returnPartialData to main May 3, 2023 14:13
@phryneas phryneas force-pushed the useFragment-union-return-type branch from f65bf2f to d4e3f0a Compare May 3, 2023 15:01
@phryneas phryneas changed the base branch from main to release-3.8 May 3, 2023 15:02
@netlify
Copy link

netlify bot commented May 3, 2023

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit d4e3f0a
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/64527760efd99d00081f53c1
😎 Deploy Preview https://deploy-preview-10765--apollo-client-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@phryneas
Copy link
Member Author

phryneas commented May 3, 2023

@jerelmiller this now uses DeepPartial - once you have given it another glance I'm gonna merge this into the 3.8 branch.

Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

Thanks for updating to DeepPartial! These types look great!

@phryneas phryneas merged commit 35f36c5 into release-3.8 May 4, 2023
5 checks passed
@jerelmiller jerelmiller deleted the useFragment-union-return-type branch May 8, 2023 16:55
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants