Skip to content

Instantly share code, notes, and snippets.

@onurkose
Last active May 20, 2018 09:00
Show Gist options
  • Save onurkose/fb50e08fc9631405d5997242d52f171a to your computer and use it in GitHub Desktop.
Save onurkose/fb50e08fc9631405d5997242d52f171a to your computer and use it in GitHub Desktop.
<?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