nuwave / lighthouse

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

Mutation `@update` for multiple records #1550

Open mentamarindos opened 4 years ago

mentamarindos commented 4 years ago

What problem does this feature proposal attempt to solve?

Update multiple records

schema.graphql:
updateCheckList(ID: [ID!], status: Int): [checkList] @update

from client:
mutation{
updateCheckList(ID: [44,266,36,46], status: 1){
 ITEM
 CHECKED
}
}

I've try it but throws the error:

Argument 2 passed to Nuwave\\Lighthouse\\Execution\\Arguments\\ArgPartitioner::relationMethods()
must be an instance of Illuminate\\Database\\Eloquent\\Model, instance of Illuminate\\Database\\Eloquent\\Collection given
spawnia commented 4 years ago

My initial impression is that this feature is unnecessary and quite complicated to fit in with existing functionality in Lighthouse. See https://github.com/nuwave/lighthouse/blob/master/src/Schema/Directives/UpdateDirective.php

Directive resolvers are meant to be useful abstractions for common use cases, not necessarily cover every use case ever. You can just create a resolver class through:

php artisan lighthouse:mutation UpdateCheckList

Alternatively, a custom directive might also be useful:

php artisan lighthouse:directive MassUpdateDirective
mentamarindos commented 4 years ago

Yep, that's what I've been doing, I create a custom resolver but it would be nice if Lighthouse implemented it by default :) Thanks for your response :+1:

henzeb commented 4 years ago

You can create your own directive that does this for you. write it once, use it twice or even thrice. Lighthouse is very flexible and extensible, just for usecases like yours. You could even make your directives into a composer package for sharing.