Skip to content

Request body not available when using Server #340

Closed
@enumag

Description

@enumag

Note: I'm completely new to React and async programming. I'm experimenting with both reactphp and amphp to get the gist of what this is all about. So this is my feedback as a complete noob about one of the total WTFs I had with React.

I was trying to setup a very basic HTTP server using an event loop and then integrate https://github.com/webonyx/graphql-php to make a GraphQL server example.

GraphQL takes the query as a JSON in the request body. So I was trying this:

$server = new Server(function (ServerRequestInterface $request) {
    $rawInput = $request->getBody()->getContents();

    $input = json_decode($rawInput, true);
    $query = $input['query'];

    $promise = GraphQL::promiseToExecute(
        new ReactPromiseAdapter(),
        $this->createSchema(),
        $query
    );

	// ...
});

The problem I ran into was that $request->getBody()->getContents() returned an empty string instead of the body.

After some debugging I found the reason:

Once I understood the issue it was of course easy to fix using StreamingServer without the RequestBodyParserMiddleware.

That's all. I'd not call this a bug but it certainly is a complete WTF for a React noob like me. It's up to you if you want to do something about it or not. Doing the same thing in Amphp was very easy in comparison because there was no WTF moment.


On a side note React is a complete nightmare to debug for me at the moment since it seems to hide errors by default. I'd like to ask someone more experienced about it but I'm unsure where to ask.

I'm also not quite satisfied with my final code, especially compared to the same thing written with Amphp which most likely means I missed something so I'd like to ask some react expert how to make it cleaner. Not posting it here because it's off-topic.

Where can I reach the React PHP community to ask such questions?

(I was unable to connect to the IRC channel linked on the website. Not to mention that IRC is not exacly a modern platform - it would be much better if there was a gitter, slack, discord or something like that.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions