Can I 'resolve' a mutation's input field/arg? #874
Unanswered
rudiedirkx
asked this question in
Q&A
Replies: 1 comment 7 replies
-
Neither this library nor any other implementation of the GraphQL specification includes such capabilities. It is certainly outside of the specification. That said, you can take advantage of directives to attach metadata to input object types. Your resolver may then call a generic handler that applies this metadata to the given arguments. I have implemented such a solution, see https://lighthouse-php.com/master/concepts/arg-resolvers.html#motivation for a description and https://github.com/nuwave/lighthouse/tree/master/src/Execution/Arguments for the bulk of the implementation. |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way to 'resolve' a mutation's input field/arg? I want to always define input field/arg
notes
, but sometimes throw an error, IF it's provided. I can do that in the 'resolve' function of the mutation, but that becomes messy. An optional 'resolve' function would be nice.I don't see it on https://webonyx.github.io/graphql-php/type-definitions/inputs/ but I might well be missing something. Maybe there's another way to scrutinize input fields per-field?
It's similar to creating a custom
ScalarType
and implementingparseValue
/parseLiteral
, but it's not a custom type, it's just a string.Example:
I know I can check for
$args['input']['notes']
in the 'resolve' callback (see[A]
), but that's not very clean, and I want to reuseCreateReservationInput
so I want to keep it close. So I would like to do some extra input checking in the field definition (see[B]
).Beta Was this translation helpful? Give feedback.
All reactions