forked from rebing/graphql-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsersQuery.php
87 lines (79 loc) · 2.27 KB
/
UsersQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
declare(strict_types=1);
namespace Rebing\GraphQL\Tests\Database\SelectFields\ValidateDiffNodeTests;
use PHPUnit\Framework\Assert;
use GraphQL\Type\Definition\Type;
use Rebing\GraphQL\Support\Query;
use GraphQL\Type\Definition\ResolveInfo;
use Rebing\GraphQL\Support\SelectFields;
use Rebing\GraphQL\Support\Facades\GraphQL;
use Rebing\GraphQL\Tests\Support\Models\User;
class UsersQuery extends Query
{
protected $attributes = [
'name' => 'users',
];
public function args(): array
{
return [
'id' => [
'type' => Type::int(),
],
'name' => [
'type' => Type::string(),
],
'price' => [
'type' => Type::float(),
],
'status' => [
'type' => Type::boolean(),
],
'flag' => [
'type' => Type::string(),
],
'author' => [
'type' => GraphQL::type('Episode'),
],
'post' => [
'type' => GraphQL::type('Filter'),
],
'keywords' => [
'type' => Type::listOf(Type::string()),
],
'customType' => [
'type' => GraphQL::type('MyCustomScalarString'),
],
];
}
public function type(): Type
{
return Type::nonNull(Type::listOf(Type::nonNull(GraphQL::type('User'))));
}
public function resolve($root, $args, $context, ResolveInfo $resolveInfo, \Closure $getSelectFields)
{
/** @var SelectFields $fields */
$fields = $getSelectFields();
$expectedQueryArgs = [
'id' => 1,
'name' => 'john',
'price' => 1.2,
'status' => true,
'flag' => null,
'author' => 'NEWHOPE',
'post' => [
'body' => 'body',
'id' => 1,
],
'keywords' => [
'key1',
'key2',
'key3',
],
'customType' => 'hello world',
];
Assert::assertSame($expectedQueryArgs, $args);
return User::select($fields->getSelect())
->with($fields->getRelations())
->get();
}
}