0

I tried

type Mutation {
    deleteUser(id: ID!): User @delete @broadcast(subscription: "userDeleted")
}

type Subscription {
    userDeleted(id: ID!): User
}

and I created a subcription where the methods authorize and filter return true.

But I get this error:

Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\User]

The deleteUser mutation works. Only the subscription does not work. I use Pusher for broadcast and the error appeared in the horizon dashboard.

Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183
Serban Robu
  • 3
  • 1
  • 4
  • The problem here is that the broadcast event is trying to fetch the user from the database, however that is impossible as you just deleted that user. Are you soft deleting the user? – Oliver Nybroe Nov 20 '19 at 09:32
  • I understand that. But how can I do it right? I just want to trigger the userDeleted subscription. I don't need whole user object. I just need to broadcast the id of the deleted user. – Serban Robu Nov 29 '19 at 19:19

2 Answers2

1

If you really need a solution right now, just make a custom resolver where you firstly brodcast the event and then delete the user... (you can even make a custom directive that generalizes it).

Otherwise, you will have to dig a bit into the Lighthouse's internals to find a solution.

Enzo Notario
  • 639
  • 4
  • 9
0

It might be too late for you by now, but could help future developers looking for a solution.

I found that you can trigger the subscription in the model's 'deleting' event using Laravel's model events: https://laravel.com/docs/7.x/eloquent#events This means that the model will exist in the database when the subscription gets it from the database, and shouldn't throw an error.

Ideally, the accepted solution would probably be the cleanest way to do it, but this works in the meantime.