Hey good folks, i’m stuck on an Absinthe issue and could use some perspective.
I have a graphql query similar to this (simplified):
query($id: ID!) {
org(id: $id) {
successful
result {
name
accounts {
email
}
}
messages {
field
code
}
}
}
The successful
, result
and messages
fields are used with absinthe_error_payload, which is useful to map changeset errors.
In case the user does not have permission to query the org, they will get a response such as:
successful: false,
result: nil,
messages: [{
field: "org"
code: "permission_denied"
}]
This is working successfully. So far, so good.
Now we have the scenario where a user has permission to query the org, but does not have permission to view the nested accounts. We don’t know ahead of time whether the query will include the accounts
field, and so it has its own resolver which checks permissions. In case of permission denied, I would like to bubble up the error to be collected on the parent org
field, so we will end up with this:
successful: false,
result: nil,
messages: [{
field: "org.accounts"
code: "permission_denied"
}]
I want it so that if any nested field has an error, the entire query has an error and no results are returned.
I have found that the top level org
field must first be resolved before its nested account
field can be resolved. This makes sense, since the parent field is passed to the nested ones in the resolver. There doesn’t seem to be any way to bubble up the error to the top.
I tried creating a middleware similar to Absinthe.Middleware.Async
to redo the resolution phase, however this doesn’t seem to help considering the org
field is already in the :resolved
state by this time.
Any tips as to how I may achieve this?