-
Notifications
You must be signed in to change notification settings - Fork 26
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
Mutation errors mechanism seems sub-optimal #62
Comments
One more point: after just now reviewing the linked video about errors, she actually uses the pattern I describe above, not the pattern in the text of the rule. |
@rocketraman I agree with you, I'm on that side too. |
I think it will be valuable to contribute that discussion/issue to the actual rules. |
Not at all. The payload type is a union of the success type (or types) and all the relevant problem types i.e. in the example above:
both the
With this model, a common per-mutation problem union type doesn't add much value. There is already a common interface (
or if discrimination of one or more problem types is necessary:
Adding a |
I reviewed https://graphql-rules.com/rules/mutation-payload-errors closely. There seems to be a better approach.
The rule suggests:
Note the statement:
Of course, the downside of this is that making
record: Post
nullable solely for this reason conflicts with rule https://graphql-rules.com/rules/output-non-null. Typed languages on the client side that handle nullability (Kotlin, Elm, Typescript, Rescript, etc.) now lose the field nullability information for the success case.Instead, why not define the payload as a union type of both success and error conditions:
The
LikePostPayload
union very nicely documents in one place all the possible return values for the mutation, and typed client languages with pattern matching or equivalent functionality deal very nicely with this. Furthermore, theLikePostSuccess
type correctly models the nullability of therecordId
andrecord
fields for the success case.The mutation is cleaner because it is now symmetric and
__typename
can now be a top-level field rather than being buried underneatherrors
. In other words, there is a single top-level discriminator for clients, rather than the client having to inspect the errors field first:NOTE: As an aside, I also removed
message
from... on SpikeProtectionProblem
and... on PostDoesNotExistsProblem
. It is not necessary becausemessage
will already be returned in both those cases via... on ProblemInterface
.The text was updated successfully, but these errors were encountered: