public function setup()
 {
     $this->allUsers = [['name' => 'Dan', 'friends' => [1, 2, 3, 4]], ['name' => 'Nick', 'friends' => [0, 2, 3, 4]], ['name' => 'Lee', 'friends' => [0, 1, 3, 4]], ['name' => 'Joe', 'friends' => [0, 1, 2, 4]], ['name' => 'Tim', 'friends' => [0, 1, 2, 3]]];
     $this->userType = new ObjectType(['name' => 'User', 'fields' => function () {
         return ['name' => ['type' => Type::string()], 'friends' => ['type' => $this->friendConnection, 'args' => Connection::connectionArgs(), 'resolve' => function ($user, $args) {
             return ArrayConnection::connectionFromArray($user['friends'], $args);
         }], 'friendsForward' => ['type' => $this->userConnection, 'args' => Connection::forwardConnectionArgs(), 'resolve' => function ($user, $args) {
             return ArrayConnection::connectionFromArray($user['friends'], $args);
         }], 'friendsBackward' => ['type' => $this->userConnection, 'args' => Connection::backwardConnectionArgs(), 'resolve' => function ($user, $args) {
             return ArrayConnection::connectionFromArray($user['friends'], $args);
         }]];
     }]);
     $this->friendEdge = Connection::createEdgeType(['name' => 'Friend', 'nodeType' => $this->userType, 'resolveNode' => function ($edge) {
         return $this->allUsers[$edge['node']];
     }, 'edgeFields' => function () {
         return ['friendshipTime' => ['type' => Type::string(), 'resolve' => function () {
             return 'Yesterday';
         }]];
     }]);
     $this->friendConnection = Connection::createConnectionType(['name' => 'Friend', 'nodeType' => $this->userType, 'edgeType' => $this->friendEdge, 'connectionFields' => function () {
         return ['totalCount' => ['type' => Type::int(), 'resolve' => function () {
             return count($this->allUsers) - 1;
         }]];
     }]);
     $this->userEdge = Connection::createEdgeType(['nodeType' => $this->userType, 'resolveNode' => function ($edge) {
         return $this->allUsers[$edge['node']];
     }]);
     $this->userConnection = Connection::createConnectionType(['nodeType' => $this->userType, 'edgeType' => $this->userEdge]);
     $this->queryType = new ObjectType(['name' => 'Query', 'fields' => function () {
         return ['user' => ['type' => $this->userType, 'resolve' => function () {
             return $this->allUsers[0];
         }]];
     }]);
     $this->schema = new Schema(['query' => $this->queryType]);
 }
 public function setup()
 {
     $this->simpleMutation = Mutation::mutationWithClientMutationId(['name' => 'SimpleMutation', 'inputFields' => [], 'outputFields' => ['result' => ['type' => Type::int()]], 'mutateAndGetPayload' => function () {
         return ['result' => 1];
     }]);
     $this->simpleMutationWithThunkFields = Mutation::mutationWithClientMutationId(['name' => 'SimpleMutationWithThunkFields', 'inputFields' => function () {
         return ['inputData' => ['type' => Type::int()]];
     }, 'outputFields' => function () {
         return ['result' => ['type' => Type::int()]];
     }, 'mutateAndGetPayload' => function ($inputData) {
         return ['result' => $inputData['inputData']];
     }]);
     $userType = new ObjectType(['name' => 'User', 'fields' => ['name' => ['type' => Type::string()]]]);
     $this->edgeMutation = Mutation::mutationWithClientMutationId(['name' => 'EdgeMutation', 'inputFields' => [], 'outputFields' => ['result' => ['type' => Connection::createEdgeType(['nodeType' => $userType])]], 'mutateAndGetPayload' => function () {
         return ['result' => ['node' => ['name' => 'Robert'], 'cursor' => 'SWxvdmVHcmFwaFFM']];
     }]);
     $this->mutation = new ObjectType(['name' => 'Mutation', 'fields' => ['simpleMutation' => $this->simpleMutation, 'simpleMutationWithThunkFields' => $this->simpleMutationWithThunkFields, 'edgeMutation' => $this->edgeMutation]]);
     $this->schema = new Schema(['mutation' => $this->mutation, 'query' => $this->mutation]);
 }
Exemple #3
0
 /**
  * Returns a GraphQLObjectType for a edge with the given name,
  * and whose nodes are of the specified type.
  *
  * @param array $config
  * @return ObjectType
  */
 public static function edgeType(array $config)
 {
     return Connection::createEdgeType($config);
 }
 public function testEdgeType()
 {
     $nodeType = new ObjectType(['name' => 'test']);
     $config = ['nodeType' => $nodeType];
     $this->assertEquals(Connection::createEdgeType($config), Relay::edgeType($config));
 }
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testConnectionDefinitionThrowsWithoutNodeType()
 {
     Connection::connectionDefinitions([]);
 }