Last active
May 20, 2018 09:00
-
-
Save onurkose/fb50e08fc9631405d5997242d52f171a 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\Queries\System\TranslationManager; | |
// Project Model | |
use App\System\TranslationManager\Project\Project; | |
use GraphQL\Type\Definition\Type; | |
use Rebing\GraphQL\Support\Query; | |
use Rebing\GraphQL\Support\SelectFields; | |
class ProjectsQuery extends Query | |
{ | |
protected $attributes = [ | |
'name' => 'ProjectsQuery', | |
'description' => 'A query of projects' | |
]; | |
public function type() | |
{ | |
return Type::listOf(GraphQL::type('projects_type')); | |
} | |
public function args() | |
{ | |
return [ | |
'id' => ['name' => 'id', 'type' => Type::int()], | |
'status' => ['name' => 'status', 'type' => Type::string()] | |
]; | |
} | |
public function resolve($root, $args, SelectFields $fields) | |
{ | |
return Project::where(function ($query) use ($args) { | |
if (isset($args['status'])) { | |
$query->where('status', $args['status']); | |
} | |
if (isset($args['id'])) { | |
$query->where('id', $args['id']); | |
} | |
}) | |
->select($fields->getSelect()) | |
->with($fields->getRelations()) | |
->get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment