Completed
Push — master ( 1436fc...7e0f0d )
by Simon
01:30
created

ReadMembersQueryCreator::resolve()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 4
nop 4
1
<?php
2
3
namespace MySite\GraphQL;
4
5
use GraphQL\Type\Definition\ResolveInfo;
6
use GraphQL\Type\Definition\Type;
7
use SilverStripe\Security\Member;
8
use SilverStripe\GraphQL\OperationResolver;
9
use SilverStripe\GraphQL\QueryCreator;
10
use SilverStripe\Security\Security;
11
12
class ReadMembersQueryCreator extends QueryCreator implements OperationResolver
13
{
14
    public function attributes()
15
    {
16
        return [
17
            'name' => 'readMembers'
18
        ];
19
    }
20
21
    public function args()
22
    {
23
        return [
24
            'ID' => ['type' => Type::string()],
25
            'Email' => ['type' => Type::string()],
26
            'Token' => ['type' => Type::string()]
27
        ];
28
    }
29
30
    public function type()
31
    {
32
        return Type::listOf($this->manager->getType('member'));
33
    }
34
35
    public function resolve($object, array $args, $context, ResolveInfo $info)
36
    {
37
        $list = Member::get();
38
39
        // Optional filtering by properties
40
        if (isset($args['Email'])) {
41
            $list = $list->filter('Email', $args['Email']);
42
        }
43
        if (isset($args['ID'])) {
44
            $list = $list->byID($args['ID']);
45
        }
46
47
        return $list;
48
    }
49
}
50