nuwave / nuwave/lighthouse

Inject directive not working in scopes

Open
#1,091 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Description

f I want to make a pagination (eg. user blog entries) and make sure that the user is the logged user in the system, I’d like to use @inject

entires(
    order: [OrderByClause!] @orderBy,
    filters: Filters @filters(columns: ["id", "name", "display_name", "description"])
  )[Role!]
    @can(ability: "view")
@inject(context: "user.id", name: "id")
@paginate(scopes: ["assignedToUser"])

Then I imagine to use scopes in order to filter the blog entries for that user
The problem is that id never goes to scope as an argument (I think it should) because the arguments are set here:

$query = $resolveInfo
                    **->argumentSet**
                    ->enhanceBuilder(
                        $query,
                        $this->directiveArgValue('scopes', [])
                    );

argumentSet is not considering the @inject directive that’s why id is not appending to args, when you call:

`public function assignedToUser(array $args) {
dd($args["id"]); _// it is never goes to here!_
}

Lighthouse Version: latest
Laravel Version: latest

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

Trace how resolveInfo->argumentSet and enhanceBuilder handle directive arguments, starting from the scope application shown in the issue. Compare that path with @inject(context: "user.id", name: "id") and verify that assignedToUser receives the injected id in its $args array.

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
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.