Skip to content

Commit

Permalink
add UserQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
ucan-lab committed Oct 14, 2018
1 parent d79f2fc commit 7a9abd1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
54 changes: 46 additions & 8 deletions app/GraphQL/Query/UserQuery.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,71 @@
<?php

declare(strict_types = 1);

namespace App\GraphQL\Query;

use Folklore\GraphQL\Support\Query;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\ObjectType;
use GraphQL;
use App\User;

/**
* Userクエリの定義
*/
class UserQuery extends Query
{
/**
* クエリ名の定義と概要
*
* @var array
*/
protected $attributes = [
'name' => 'UserQuery',
'description' => 'A query'
'name' => 'user',
'description' => 'user query'
];

public function type()
/**
* クエリが扱う型を定義
*
* @return ObjectType
*/
public function type() : ObjectType
{
return Type::listOf(Type::string());
return GraphQL::type('UserType');
}

public function args()
/**
* クエリが取り得る引数を定義
*
* @return array
*/
public function args() : array
{
return [

'id' => [
'name' => 'id',
'type' => Type::id(),
],
];
}

public function resolve($root, $args, $context, ResolveInfo $info)
/**
* クエリに対する実処理
*
* @param array $root
* @param array $args
* @return User
*/
public function resolve($root, $args, $context, ResolveInfo $info) : User
{
return [];
$query = User::query();

if (isset($args['id'])) {
$query->where('id', $args['id']);
}

return $query->first();
}
}
2 changes: 1 addition & 1 deletion config/graphql.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
'schemas' => [
'default' => [
'query' => [

App\GraphQL\Query\UserQuery::class,
],
'mutation' => [

Expand Down

0 comments on commit 7a9abd1

Please sign in to comment.