nuwave / nuwave/lighthouse

Lighthouse should not return the 'data' key if an exception was thrown in the custom builder

Open
#1,583 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs reproduction
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.