nuwave / lighthouse

A framework for serving GraphQL from Laravel
https://lighthouse-php.com
MIT License
3.36k stars 438 forks source link

input.id in @can(find: ) #2565

Closed WTFace closed 3 months ago

WTFace commented 3 months ago

Describe the bug

it works with @can(ability: "your ability", find: "id") or @canFind not working with @can(ability: "your ability", find: "input.id") or @canFind if I pass "input.id" not "id" I always get "Got no key to find a model at the expected input path: input.id."

so for now I end up separate the primary key from input updateSupport ( id: ID! input: UpdateSupportInput! @spread ): Support @canFind(ability: "update", find: "id") @update

Expected behavior/Solution

updateSupport (
        input: UpdateSupportInput! @spread
    ): Support @can(ability: "update", find: "input.id") @update

Steps to reproduce

  1. setup User hasMany Support, Support belongsTo User relationship.

  2. 
    type Mutation {
    updateSupport (
        input: UpdateSupportInput! @spread
    ): Support @can(ability: "update", find: "input.id") @update
    }

input UpdateSupportInput { id: ID! title: String @rules(apply: ["max:40"]) body: String }

SupportPolicy public function update(User $user, Support $support): bool { return $user->id === $support->user_id; }

3. query from GraphiQL

mutation MyMutation { updateSupport(input: {id: "100", body: "blah", title: "test"}) { body id replied reply title } }


**Output/Logs**

<details><summary>Click to expand</summary>

"errors": [ { "message": "Got no key to find a model at the expected input path: input.id.", "locations": [ { "line": 2, "column": 3 } ], "path": [ "updateSupport" ],



</details></br>

**Lighthouse Version**
6.36
spawnia commented 3 months ago

Since you are using @spread, using find: "id" should work.