-
Notifications
You must be signed in to change notification settings - Fork 51
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: Allow readFragment
to be called on already unmasked fragments
#124
Conversation
🦋 Changeset detectedLatest commit: 41ebcce 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 |
I don't think this actually solves the issue. Consider: import { FC } from "react";
const MyComponent: FC<{
user1: FragmentOf<typeof UserFrag>;
user2: FragmentOf<typeof UserFrag>;
}> = ({ user1: data1, user2: data2 }) => {
const user1 = readFragment(UserFrag, data1);
const user2 = readFragment(UserFrag, data2);
const winner = user1.score > user2.score ? user1 : user2;
return <OtherComponent user={winner} />;
};
const OtherComponent: FC<{ user: FragmentOf<typeof UserFrag> }> = ({
user: data,
}) => {
const user = readFragment(UserFrag, data);
return <strong>{user.name}</strong>;
}; The issue isn't the (Poor example since OtherComponent should use it's own fragments, but consider passing this to utility functions and what not which would want to declare data in the same way.) Intuitively it feels like you should be able to pass a |
Is there a type helper for the unwrapped version of a fragment? |
@benjie: |
I'll merge this for now, since I think this is a good change either way. But I'll keep that comment in mind. I think what we could ponder is whether But there must be a middleground here somewhere 🤔 |
Supersedes #121
cc @benjie
Summary
This allows
readFragment
to be called on already unmasked fragments, which will most likely happen if we try to callreadFragment
on data that's already typed by (i.e. has already been unwrapped by) anotherreadFragment
call.See #121 for more details
Set of changes
readFragment
that accepts already unwrapped data