Last active
May 20, 2018 11:33
-
-
Save onurkose/a2da27ebaba80ce2c198e8864aa79e3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\GraphQL\Mutations\System\TranslationManager\Projects; | |
// Project Model | |
use App\System\TranslationManager\Project\Project; | |
use GraphQL; | |
use GraphQL\Type\Definition\Type; | |
use Rebing\GraphQL\Support\Mutation; | |
use Rebing\GraphQL\Support\SelectFields; | |
use Illuminate\Http\Request; | |
class UpdateProjectMutation extends Mutation | |
{ | |
protected $attributes = [ | |
'name' => 'UpdateProjectMutation' | |
]; | |
public function type() | |
{ | |
return GraphQL::type('projects_type'); | |
} | |
public function args() | |
{ | |
return [ | |
'id' => ['name' => 'id', 'type' => Type::nonNull(Type::int())], | |
'name' => ['name' => 'name', 'type' => Type::nonNull(Type::string())], | |
'status' => ['name' => 'status', 'type' => Type::nonNull(Type::string())], | |
'locales' => ['name' => 'locales', 'type' => Type::listOf(GraphQL::type('locales_input_object_type'))], | |
]; | |
} | |
public function resolve($root, $args, SelectFields $fields) | |
{ | |
$project = Project::find($args['id']); | |
if (!$project) { | |
return null; | |
} | |
$project->update([ | |
'name' => $args['name'], | |
'status' => $args['status'] | |
]); | |
// Use $args['locales'] array to update locale relations of the project model | |
return $project; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment