Youshido\GraphQL\Relay\Connection\Connection::connectionDefinition PHP Method

connectionDefinition() public static method

public static connectionDefinition ( AbstractType $type, null | string $name = null, array $config = [] ) : ObjectType
$type Youshido\GraphQL\Type\AbstractType
$name null | string
$config array
return Youshido\GraphQL\Type\Object\ObjectType
    public static function connectionDefinition(AbstractType $type, $name = null, $config = [])
    {
        $name = $name ?: $type->getName();
        $connectionFields = !empty($config['connectionFields']) ? $config['connectionFields'] : [];
        $connectionType = new ObjectType(['name' => $name . 'Connection', 'description' => 'A connection to a list of items.', 'fields' => array_merge(['pageInfo' => ['type' => new NonNullType(self::getPageInfoType()), 'description' => 'Information to aid in pagination.', 'resolve' => [__CLASS__, 'getPageInfo']], 'edges' => ['type' => new ListType(self::edgeDefinition($type, $name, $config)), 'description' => 'A list of edges.', 'resolve' => [__CLASS__, 'getEdges']]], $connectionFields)]);
        return $connectionType;
    }

Usage Example

Example #1
0
 public function testConnectionDefinition()
 {
     $connection = Connection::connectionDefinition(new TestObjectType(), 'user');
     $this->assertEquals($connection->getName(), 'userConnection');
     $this->assertTrue($connection->hasField('pageInfo'));
     $this->assertTrue($connection->hasField('edges'));
 }
All Usage Examples Of Youshido\GraphQL\Relay\Connection\Connection::connectionDefinition