-
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
Ergonomic improvements for field policy merge and keyArgs functions. #6714
Conversation
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 love these enhancements @benjamn - great ideas!
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.
This looks like what we talked about! Nice!
merge(existing: any[], incoming: any[], { | ||
isReference, | ||
}) { | ||
const merged = existing ? existing.slice(0) : []; |
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 can't usefully review this part of the test without a lot more learning.
This provides features I didn't even know I wanted; thank you @benjamn ! |
These improvements are available now in |
@benjamn Do you think it's possible to also get access to these variables when writing your custom keyargs function? I have some types that don't have unique enough data (think weeks in a calendar). But together with the context from the query they do. A week number is not unique enough (if you have multiple calendars) but it is in combination with the calendar id. And the only way to get the weeks is through a calendar query. |
This PR introduces two minor improvements for
merge
andkeyArgs
functions in field policies.First, if you need to write a custom
keyArgs
function (unusual), you can now access the variables of the current read/write operation throughcontext.variables
.Second, you can now write
as a shorthand for
to enable merging of
author
objects associated with a givenBook
.You can also specify
merge: false
to do the opposite:This ensures the
verdict
field of theCourtCase
object always overwrites any existingverdict
, without warning about clobbering data (see #6372). In other words,merge: false
is a shorthand for