-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[Data masking] Warn when using data masking with no-cache
operations
#12121
Conversation
✅ Docs Preview ReadyNo new or changed pages found. |
|
src/core/QueryManager.ts
Outdated
} | ||
|
||
invariant.warn( | ||
'Fragments masked by data masking when using fetch policy "no-cache" cannot be read by `watchFragment` or `useFragment`. Please add `@unmask` to the fragment to read the fragment data.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions welcome on better wording here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
-...to read the fragment data.+
+...to make the fragment data available for reading without those hooks.
?
It might also be helpful to include the name of the document.
commit: |
size-limit report 📦
|
@@ -517,6 +517,7 @@ export class ApolloClient<TCacheShape> implements DataProxy { | |||
data: this.queryManager.maskOperation({ | |||
document: options.query, | |||
data: result.data, | |||
fetchPolicy: options.fetchPolicy, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subscriptions don't have a queryId
so this would mean the warning would be emitted for every subscription event. Are we ok with that? Should we use something else as the query ID to try and only emit this warning once per subscription?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think a counter on module level and using something like "subscription"+(id++)
as queryId
would be fine here. Might make sense to rename the queryId
option to something like id
then.
src/utilities/graphql/fragments.ts
Outdated
return BREAK; | ||
} | ||
|
||
isUnmasked &&= node.directives.some( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isUnmasked &&= node.directives.some( | |
isUnmasked = node.directives.some( |
I think we can safely assume that at this point, isUnmasked
is always true
, right?
src/utilities/graphql/fragments.ts
Outdated
FragmentSpread: (node) => { | ||
if (!node.directives) { | ||
isUnmasked = false; | ||
return BREAK; | ||
} | ||
|
||
isUnmasked &&= node.directives.some( | ||
(directive) => directive.name.value === "unmask" | ||
); | ||
|
||
if (!isUnmasked) { | ||
return BREAK; | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FragmentSpread: (node) => { | |
if (!node.directives) { | |
isUnmasked = false; | |
return BREAK; | |
} | |
isUnmasked &&= node.directives.some( | |
(directive) => directive.name.value === "unmask" | |
); | |
if (!isUnmasked) { | |
return BREAK; | |
} | |
}, | |
FragmentSpread: (node) => { | |
isUnmasked = !!node.directives && node.directives.some( | |
(directive) => directive.name.value === "unmask" | |
); | |
if (!isUnmasked) { | |
return BREAK; | |
} | |
}, |
I think this whole block could be simplified like this.
}); | ||
const stream = new ObservableStream(observable); | ||
|
||
link.simulateResult({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if the client.subscribe
tests would show more than one subscription result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a bunch of comments and suggestions, but as a whole: approved :)
Reminder to self: don't forget a changeset |
3c8b82b
to
f57d5a9
Compare
Closes #11678
Emits a warning when using
no-cache
operations with data masking sincewatchFragment
anduseFragment
rely on the cache to read fragment data. This warning will not be emitted when eitherdataMasking
is disabled or if the operation already contains@unmask
for all fragments.