apollo-client: Data masking with fragment that should never be masked
Moved from https://github.com/apollographql/apollo-client/issues/11666#issuecomment-2518099996
What happens if a fragment is expected to NOT be masked, always? I have some fragment on types that don’t have clear ids, so I can’t useFragment on it.
So far I’ve been using useFragment from GraphQL Codegen client preset (which I renamed unmaskFragmentData) in the component using the fragment In that case it is expected that, while the typings are masked, the data is available at runtime to be unmasked.
I can go put @unmask everywhere that fragment is spread, but that’s error-prone.
I’m fiddling with a custom directive @disableMasking on the FragmentDefinition to ensure all places using that fragment are using @unmask and are not using @nonreactive
Now I’m hitting a typings issue because it unmasks the fragment, effectively making all the data available top-level, but I really only want it to be available on the component.
How can I make sure that the data will be available at runtime, but is masked in the typings?
I basically want @unmask at runtime, but it shouldn’t be there for typings codegen
Right now, my approach is to enforce the @unmask directive for those fragment spreads and during codegen I strip them before running typescript-operations and leave them for the runtime (at some point because I’m not ready to try apollo data masking)
Note that I’m working with a heavily customized fork GraphQL Codegen client preset to make it work with Apollo client more natively
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (16 by maintainers)
That would be amazing! Hope all goes well when you do start using it! Appreciate the conversation!
Phew 🎉. For a second I thought 3.12.1 might have to be on its way 😆
Urgg I just saw the
setIsSubmittingin my screenshot and I got so sad… please ignore that I’m fixing it to useconst [revertAuditEntry, { loading: isSubmitting} ] = useRevertAuditEntryMutation()hahahaCorrect
Yup! Give me a bit of time to get good examples in a readable format and I’ll post it here