Hello
How can I integrate Zend expressive with graphql, I’m using the basic example and it does not work.
what is wrong?
The url is localhost:7070/api/ping via GraphIQL Feen!
But it does not return anything
namespace App\Action;
use Interop\Http\ServerMiddleware\DelegateInterface; use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface; use Zend\Diactoros\Response\JsonResponse; use Psr\Http\Message\ServerRequestInterface; use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\Type; use GraphQL\Schema; use GraphQL\GraphQL;
class PingAction implements ServerMiddlewareInterface {
public function process(ServerRequestInterface $request, DelegateInterface $delegate) {
try { $queryType = new ObjectType([ 'name' => 'Query', 'fields' => [ 'echo' => [ 'type' => Type::string(), 'args' => [ 'message' => ['type' => Type::string()], ], 'resolve' => function ($root, $args) { return $root['prefix'] . $args['message']; } ], ], ]);
$mutationType = new ObjectType([ 'name' => 'Calc', 'fields' => [ 'sum' => [ 'type' => Type::int(), 'args' => [ 'x' => ['type' => Type::int()], 'y' => ['type' => Type::int()], ], 'resolve' => function ($root, $args) { return $args['x'] + $args['y']; }, ], ], ]);
$schema = new Schema([ 'query' => $queryType, 'mutation' => $mutationType, ]);
$rawInput = file_get_contents('php://input'); $input = json_decode($rawInput, true); $query = $input['query']; $variableValues = isset($input['variables']) ? $input['variables'] : null;
$rootValue = ['prefix' => 'You said: ']; $result = GraphQL::execute($schema, $query, $rootValue, null, $variableValues); } catch (\Exception $e) { $result = [ 'error' => [ 'message' => 'hola', ] ]; } return new JsonResponse($result); } }