You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This could either be combined with the skip attribute (from #463) or validated elsewhere to ensure that context.current_user has authorization to set the author of a Message to the provided value.
Drawbacks
Not sure how "official" this is and would have to be documented in playground/graphiql etc...
Alternatives
Making the field an Option and then later mutating it/creating a new struct with the default from the Context. I don't like this method because then you have to be careful about exactly when the field will become Some and what sets it.
Using a different struct and using a custom From like trait to fill it in with the field from Context
The text was updated successfully, but these errors were encountered:
Not sure I understand this request. This is just so you can use the derive without breaking out into the juniper::object proc macro? What is the advantage over doing something like:
Ahhh. I guess I should have been more explicit—I am proposing adding the ability to derive default values for GraphQLInputObjects with access to Context.
Yeah, in most cases it is easier to understand with a separate From impl; although for small and quick things (which is what I would use it for), I think it cuts down on the boiler plate and keeps things simple and clean.
Is it possible to access
Context
when defaulting fields forGraphQLInputObjects
? (I don't believe it is...)I think it would be really useful to support dynamic defaulting of input field values based on the current
Context
:This could either be combined with the
skip
attribute (from #463) or validated elsewhere to ensure thatcontext.current_user
has authorization to set theauthor
of aMessage
to the provided value.Drawbacks
Alternatives
Option
and then later mutating it/creating a new struct with the default from theContext
. I don't like this method because then you have to be careful about exactly when the field will becomeSome
and what sets it.From
like trait to fill it in with the field fromContext
The text was updated successfully, but these errors were encountered: