Closed paolojulian closed 8 months ago
Hey @paolojulian 👋
This happens because we don't know if the cache can fulfill the entirety of the fragment
or not. useFragment
will return any data it can, therefore it can be partial. useFragment
also returns a complete
property that you can use to determine if the cache could fulfill the entire fragment. The types will adjust to the non-partial type if you check for complete
first.
const { complete, data } = useFragment<MyFragment>({ fragment })
// ^? DeepPartial<MyFragment>
if (complete) {
data
// ^? MyFragment
}
Hope this helps!
@jerelmiller Ahhh, I wonder why I didn't notice it 😅 , i was also looking at the useFragment.d.ts but didn't catch it, thanks for this!
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.
You're welcome! Glad I could help 🙂
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. For general questions, we recommend using StackOverflow or our discord server.
We have just started implementing useFragment. But the problem is we need to add typeguard of use typecast for the DeepPartialObject. useQuery is not doing this.