-
Notifications
You must be signed in to change notification settings - Fork 432
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
[Newsfeed] Getting a type error when using readUpdatableFragment for StoryLikeButton #285
Comments
It might be helpful to put your code as a fork on github so that we can see the whole thing. |
I am stuck at the same point. When running
When running
|
The types forces me to use But I also get error during runtime:
When I switch to
|
With Relay v16, The |
The only way I could make this work was by spreading the updatable fragment on the page query itself (looks like you cannot spread it on the component fragment?), and then doing some type-casting when running it, e.g: const fragment = graphql`
fragment StoryLikeButton_updatable on Story @updatable {
likeCount
doesViewerLike
}
`;
const { updatableData } = store.readUpdatableFragment<StoryLikeButton_updatable$key>(
fragment,
story as any
);
const alreadyLikes = updatableData.doesViewerLike;
updatableData.doesViewerLike = !alreadyLikes;
updatableData.likeCount += alreadyLikes ? -1 : 1; Spreading the fragment on the query is what made the warnings go away, but I did not see this being mentioned in the page. Spreading it on the fragment causes relay to throw an error saying the updatable fragment cannot be spread on the root. Having to spread it on the root query feels wrong to me, and makes this basically break the composability of the fragments, as now the root query has to know about all the updates on the children components. I am still trying to figure out how to update non-scalar values tho, as it seems the TS generated setters do not include the nested fields of the linked record? |
I'm getting the following type error when following the guide here: https://relay.dev/docs/tutorial/mutations-updates/#step-3--call-readupdatablefragment
Here is the entire onLikeButtonClicked function:
The text was updated successfully, but these errors were encountered: