1 | <?php |
||
18 | class Connection |
||
19 | { |
||
20 | |||
21 | 1 | public static function connectionArgs() |
|
25 | |||
26 | 1 | public static function forwardArgs() |
|
27 | { |
||
28 | return [ |
||
29 | 1 | 'after' => ['type' => TypeMap::TYPE_STRING], |
|
30 | 1 | 'first' => ['type' => TypeMap::TYPE_INT] |
|
31 | 1 | ]; |
|
32 | } |
||
33 | |||
34 | 1 | public static function backwardArgs() |
|
35 | { |
||
36 | return [ |
||
37 | 1 | 'before' => ['type' => TypeMap::TYPE_STRING], |
|
38 | 1 | 'last' => ['type' => TypeMap::TYPE_INT] |
|
39 | 1 | ]; |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * @param AbstractType $type |
||
44 | * @param null|string $name |
||
45 | * @param array $config |
||
46 | * @option string edgeFields |
||
47 | * |
||
48 | * @return ObjectType |
||
49 | */ |
||
50 | 2 | public static function edgeDefinition(AbstractType $type, $name = null, $config = []) |
|
51 | { |
||
52 | 2 | $name = $name ?: $type->getName(); |
|
53 | 2 | $edgeFields = !empty($config['edgeFields']) ? $config['edgeFields'] : []; |
|
54 | |||
55 | 2 | $edgeType = new ObjectType([ |
|
56 | 2 | 'name' => $name . 'Edge', |
|
57 | 2 | 'description' => 'An edge in a connection.', |
|
58 | 2 | 'fields' => array_merge([ |
|
59 | 'node' => [ |
||
60 | 2 | 'type' => $type, |
|
61 | 2 | 'description' => 'The item at the end of the edge', |
|
62 | 2 | 'resolve' => [__CLASS__, 'getNode'], |
|
63 | 2 | ], |
|
64 | 'cursor' => [ |
||
65 | 2 | 'type' => TypeMap::TYPE_STRING, |
|
66 | 'description' => 'A cursor for use in pagination' |
||
67 | 2 | ] |
|
68 | 2 | ], $edgeFields) |
|
69 | 2 | ]); |
|
70 | |||
71 | 2 | return $edgeType; |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * @param AbstractType $type |
||
76 | * @param null|string $name |
||
77 | * @param array $config |
||
78 | * @option string connectionFields |
||
79 | * |
||
80 | * @return ObjectType |
||
81 | */ |
||
82 | 1 | public static function connectionDefinition(AbstractType $type, $name = null, $config = []) |
|
83 | { |
||
84 | 1 | $name = $name ?: $type->getName(); |
|
85 | 1 | $connectionFields = !empty($config['connectionFields']) ? $config['connectionFields'] : []; |
|
86 | |||
87 | 1 | $connectionType = new ObjectType([ |
|
88 | 1 | 'name' => $name . 'Connection', |
|
89 | 1 | 'description' => 'A connection to a list of items.', |
|
90 | 1 | 'fields' => array_merge([ |
|
91 | 'pageInfo' => [ |
||
92 | 1 | 'type' => new NonNullType(new PageInfoType()), |
|
93 | 1 | 'description' => 'Information to aid in pagination.', |
|
94 | 1 | 'resolve' => [__CLASS__, 'getPageInfo'], |
|
95 | 1 | ], |
|
96 | 'edges' => [ |
||
97 | 1 | 'type' => new ListType(self::edgeDefinition($type, $name, $config)), |
|
98 | 1 | 'description' => 'A list of edges.', |
|
99 | 1 | 'resolve' => [__CLASS__, 'getEdges'], |
|
100 | ] |
||
101 | 1 | ], $connectionFields) |
|
102 | 1 | ]); |
|
103 | |||
104 | 1 | return $connectionType; |
|
105 | } |
||
106 | |||
107 | public static function getEdges($value) |
||
111 | |||
112 | public static function getPageInfo($value) |
||
116 | |||
117 | public static function getNode($value) |
||
121 | } |
||
122 |