Youshido\GraphQL\Relay\Connection\ArrayConnection::edgeForObjectWithIndex PHP Метод

edgeForObjectWithIndex() публичный статический Метод

public static edgeForObjectWithIndex ( $object, $index )
    public static function edgeForObjectWithIndex($object, $index)
    {
        return ['cursor' => ArrayConnection::offsetToCursor($index), 'node' => $object];
    }

Usage Example

Пример #1
0
 public function testConnectionDefinition()
 {
     $data = ['a', 'b', 'c', 'd', 'e'];
     $edges = [];
     foreach ($data as $key => $item) {
         $edges[] = ArrayConnection::edgeForObjectWithIndex($item, $key);
     }
     $this->assertEquals(['edges' => $edges, 'pageInfo' => ['startCursor' => $edges[0]['cursor'], 'endCursor' => $edges[count($edges) - 1]['cursor'], 'hasPreviousPage' => false, 'hasNextPage' => false]], ArrayConnection::connectionFromArray($data));
     $this->assertEquals(['edges' => array_slice($edges, 0, 2), 'pageInfo' => ['startCursor' => $edges[0]['cursor'], 'endCursor' => $edges[1]['cursor'], 'hasPreviousPage' => false, 'hasNextPage' => true]], ArrayConnection::connectionFromArray($data, ['first' => 2, 'last' => 4]));
 }