Skip to content

Empty request body parsing error for automatic persisted queries #614

@oojacoboo

Description

@oojacoboo

@oprypkhantc I was giving the new persisted queries a go to test the implementation, since I wasn't able to do so prior. In doing so, I'm running into the following issue.

InvalidArgumentException: Syntax error in body: ""

/srv/www/vendor/thecodingmachine/graphqlite/src/Http/WebonyxGraphqlMiddleware.php:70

This is part of the process method for the middleware, which looks for the request body contents. For reference, the process method is as follows:

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        if (! $this->isGraphqlRequest($request)) {
            return $handler->handle($request);
        }

        // Let's json deserialize if this is not already done.
        if (empty($request->getParsedBody())) {
            $content = $request->getBody()->getContents();
            $data = json_decode($content, true);

            if ($data === false || json_last_error() !== JSON_ERROR_NONE) {
                throw new InvalidArgumentException(json_last_error_msg() . ' in body: "' . $content . '"'); // @codeCoverageIgnore
            }

            $request = $request->withParsedBody($data);
        }

        $context = $this->config->getContext();
        if ($context instanceof ResetableContextInterface) {
            $context->reset();
        }
        $result = $this->standardServer->executePsrRequest($request);
        //return $this->standardServer->processPsrRequest($request, $this->responseFactory->createResponse(), $this->streamFactory->createStream());

        return $this->getJsonResponse($this->processResult($result), $this->decideHttpCode($result));
    }

Was this overlooked? We need an integration test for persisted queries for sure. Am I missing something here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions