Youshido\GraphQL\Execution\Processor::getResponseData PHP Method

getResponseData() public method

public getResponseData ( )
    public function getResponseData()
    {
        $result = [];
        if (!empty($this->data)) {
            $result['data'] = $this->data;
        }
        if ($this->executionContext->hasErrors()) {
            $result['errors'] = $this->executionContext->getErrorsArray();
        }
        return $result;
    }

Usage Example

Esempio n. 1
0
 public function testCustomTypes()
 {
     $authorType = null;
     $userInterface = new ObjectType(['name' => 'UserInterface', 'fields' => ['name' => new StringType()], 'resolveType' => function () use($authorType) {
         return $authorType;
     }]);
     $authorType = new ObjectType(['name' => 'Author', 'fields' => ['name' => new StringType()], 'interfaces' => [$userInterface]]);
     $schema = new Schema(['query' => new ObjectType(['name' => 'QueryType', 'fields' => ['user' => ['type' => $userInterface, 'resolve' => function () {
         return ['name' => 'Alex'];
     }]]])]);
     $schema->getTypesList()->addType($authorType);
     $processor = new Processor($schema);
     $processor->processPayload('{ user { name } }');
     $this->assertEquals(['data' => ['user' => ['name' => 'Alex']]], $processor->getResponseData());
     $processor->processPayload('{
                 __schema {
                     types {
                         name
                     }
                 }
             }');
     $data = $processor->getResponseData();
     $this->assertArraySubset([11 => ['name' => 'Author']], $data['data']['__schema']['types']);
     $processor->processPayload('{ user { name { } } }');
     $result = $processor->getResponseData();
     $this->assertEquals(['errors' => [['message' => 'Unexpected token "RBRACE"', 'locations' => [['line' => 1, 'column' => 19]]]]], $result);
     $processor->getExecutionContext()->clearErrors();
     $processor->processPayload('{ user { name { invalidSelection } } }');
     $result = $processor->getResponseData();
     $this->assertEquals(['data' => ['user' => null], 'errors' => [['message' => 'You can\'t specify fields for scalar type "String"', 'locations' => [['line' => 1, 'column' => 10]]]]], $result);
 }
All Usage Examples Of Youshido\GraphQL\Execution\Processor::getResponseData