1 | <?php |
||
17 | class Connection |
||
18 | { |
||
19 | |||
20 | 1 | public static function connectionArgs() |
|
24 | |||
25 | 1 | public static function forwardArgs() |
|
32 | |||
33 | 1 | public static function backwardArgs() |
|
40 | |||
41 | /** |
||
42 | * @param AbstractType $type |
||
43 | * @param null|string $name |
||
44 | * @param array $config |
||
45 | * @option string edgeFields |
||
46 | * |
||
47 | * @return ObjectType |
||
48 | */ |
||
49 | 2 | public static function edgeDefinition(AbstractType $type, $name = null, $config = []) |
|
50 | { |
||
51 | 2 | $name = $name ?: $type->getName(); |
|
52 | 2 | $edgeFields = !empty($config['edgeFields']) ? $config['edgeFields'] : []; |
|
53 | |||
54 | 2 | $edgeType = new ObjectType([ |
|
55 | 2 | 'name' => $name . 'Edge', |
|
56 | 2 | 'description' => 'An edge in a connection.', |
|
57 | 2 | 'fields' => array_merge([ |
|
58 | 'node' => [ |
||
59 | 2 | 'type' => $type, |
|
60 | 2 | 'description' => 'The item at the end of the edge', |
|
61 | 2 | 'resolve' => [__CLASS__, 'getNode'], |
|
62 | 2 | ], |
|
63 | 'cursor' => [ |
||
64 | 2 | 'type' => TypeMap::TYPE_STRING, |
|
65 | 'description' => 'A cursor for use in pagination' |
||
66 | 2 | ] |
|
67 | 2 | ], $edgeFields) |
|
68 | 2 | ]); |
|
69 | |||
70 | 2 | return $edgeType; |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param AbstractType $type |
||
75 | * @param null|string $name |
||
76 | * @param array $config |
||
77 | * @option string connectionFields |
||
78 | * |
||
79 | * @return ObjectType |
||
80 | */ |
||
81 | 1 | public static function connectionDefinition(AbstractType $type, $name = null, $config = []) |
|
82 | { |
||
83 | 1 | $name = $name ?: $type->getName(); |
|
84 | 1 | $connectionFields = !empty($config['connectionFields']) ? $config['connectionFields'] : []; |
|
85 | |||
86 | 1 | $connectionType = new ObjectType([ |
|
87 | 1 | 'name' => $name . 'Connection', |
|
88 | 1 | 'description' => 'A connection to a list of items.', |
|
89 | 1 | 'fields' => array_merge([ |
|
90 | 'pageInfo' => [ |
||
91 | 1 | 'type' => new NonNullType(self::getPageInfoType()), |
|
92 | 1 | 'description' => 'Information to aid in pagination.', |
|
93 | 1 | 'resolve' => [__CLASS__, 'getPageInfo'], |
|
94 | 1 | ], |
|
95 | 'edges' => [ |
||
96 | 1 | 'type' => new ListType(self::edgeDefinition($type, $name, $config)), |
|
97 | 1 | 'description' => 'A list of edges.', |
|
98 | 1 | 'resolve' => [__CLASS__, 'getEdges'], |
|
99 | ] |
||
100 | 1 | ], $connectionFields) |
|
101 | 1 | ]); |
|
102 | |||
103 | 1 | return $connectionType; |
|
104 | } |
||
105 | |||
106 | 2 | public static function getPageInfoType() |
|
107 | { |
||
108 | 2 | return new ObjectType([ |
|
109 | 2 | 'name' => 'PageInfo', |
|
110 | 2 | 'description' => 'Information about pagination in a connection.', |
|
111 | 'fields' => [ |
||
112 | 'hasNextPage' => [ |
||
113 | 2 | 'type' => new NonNullType(TypeMap::TYPE_BOOLEAN), |
|
114 | 'description' => 'When paginating forwards, are there more items?' |
||
115 | 2 | ], |
|
116 | 'hasPreviousPage' => [ |
||
117 | 2 | 'type' => new NonNullType(TypeMap::TYPE_BOOLEAN), |
|
118 | 'description' => 'When paginating backwards, are there more items?' |
||
119 | 2 | ], |
|
120 | 'startCursor' => [ |
||
121 | 2 | 'type' => TypeMap::TYPE_STRING, |
|
122 | 'description' => 'When paginating backwards, the cursor to continue.' |
||
123 | 2 | ], |
|
124 | 'endCursor' => [ |
||
125 | 2 | 'type' => TypeMap::TYPE_STRING, |
|
126 | 'description' => 'When paginating forwards, the cursor to continue.' |
||
127 | 2 | ], |
|
128 | ] |
||
129 | 2 | ]); |
|
130 | } |
||
131 | |||
132 | public static function getEdges($value) |
||
136 | |||
137 | public static function getPageInfo($value) { |
||
140 | |||
141 | public static function getNode($value) { |
||
144 | } |
||
145 |