-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
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(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,7 @@ | |
'schemas' => [ | ||
'default' => [ | ||
'query' => [ | ||
|
||
App\GraphQL\Query\UserQuery::class, | ||
], | ||
'mutation' => [ | ||
|
||
|