-
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] Fix bug where masked field could be returned in parent query #12014
Conversation
|
size-limit report 📦
|
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
src/core/masking.ts
Outdated
if ( | ||
!childChanged && | ||
Object.keys(masked).length !== Object.keys(data[keyName]).length | ||
) { | ||
childChanged = true; | ||
} |
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.
if ( | |
!childChanged && | |
Object.keys(masked).length !== Object.keys(data[keyName]).length | |
) { | |
childChanged = true; | |
} | |
childChanged ||= Object.keys(masked).length !== Object.keys(data[keyName]).length; |
Just a suggestion, though - whatever you like better :)
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.
I went with your other suggestion. Thanks a bunch!
src/core/masking.ts
Outdated
) { | ||
childChanged = true; | ||
} | ||
|
||
if (childChanged) { |
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.
if (childChanged) { | |
if (childChanged || Object.keys(masked).length !== Object.keys(data[keyName]).length) { |
or maybe this. Both of these should save a bunch of bytes.
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.
Oh ya I like this one a lot. Don't know why I didn't think of this initially 🤦. Great suggestion!
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.
efc0e64
to
f5b021a
Compare
Because we try and retain object identities as much as possible when running the data masking algorithm, this causes an issue where would-be masked fields are returned in the query when a named fragment selects additional fields on the same child selection as the query.
For example, take this query:
Here the parent asks only for the
id
on theprofile
field while theUserFields
fragment selectsage
onprofile
as well. Prior to this fix, bothid
andage
were returned as part of the parent query even thoughage
should have been masked. This fix ensuresage
would be masked here as expected.