Lighthouse should not return the 'data' key if an exception was thrown in the custom builder
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.5k
- Forks
- 468
- Avg merge
- 3h 9m
- Merged PRs (30d)
- 2
Description
Are you willing to provide a PR for this issue or aid in developing it?
No, I do apologize.
What problem does this feature proposal attempt to solve?
I am using the paginator directive with the builder parameter for a field as such:
@paginate(builder: "App\\GraphQL\\Builders\\foo@bar")
and in the bar function (probably mistakingly) I check the user permissions before returning the query builder:
public function bar($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): Builder
{
if ($context->user->can('Foo Bar')) {
return Model::query();
} else {
throw new Unauthorized();
}
}
And this works fine (sort of) in the way that the error is displayed correctly but a null data section is also returned:
{
"errors": ["CORRECT EXCEPTION HANDLING"],
"data": {
"Query name": null
}
}
Which possible solutions should be considered?
If an exception was thrown during a custom builder, Lighthouse should not return the data key in the results.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported @paginate query with a custom builder that throws Unauthorized, then trace the paginator and GraphQL response error-handling path. Add regression coverage for the exception case; done means the errors remain present while the response omits the data key.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, laravel, php
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100