Giter Club home page Giter Club logo

Comments (15)

Jalle19 avatar Jalle19 commented on June 21, 2024

Related to #320

from graphql-php.

crisu83 avatar crisu83 commented on June 21, 2024

@Jalle19 I took a look at this and you're right. The issue is that the promise is resolved immediately. I need to do some research. It might be that we need to introduce our own Deferred concept, like they have done in Webonyx implementation. I don't like the idea, but if it that's what it takes then we'll do that.

from graphql-php.

inanc-g avatar inanc-g commented on June 21, 2024

Any news on this?

from graphql-php.

Jalle19 avatar Jalle19 commented on June 21, 2024

@crisu83 do you have time to look into this?

from graphql-php.

Jalle19 avatar Jalle19 commented on June 21, 2024

or @hungneox

from graphql-php.

acelot avatar acelot commented on June 21, 2024

Confirm this issue. loadBuffered() is called everytime.

from graphql-php.

acelot avatar acelot commented on June 21, 2024

Guys, this issue is critical for production use. Do you have any suggestions? If you do not have time, tell me which way to dig?

from graphql-php.

asheliahut avatar asheliahut commented on June 21, 2024

This is literally the only reason I haven't swapped to this over my Youshido Fork.

from graphql-php.

crisu83 avatar crisu83 commented on June 21, 2024

@acelot I have my hands full right now with work, but the easiest way to look at it is to debug the deferred resolver test cases. I think that the main issue is related to how we're handling promises when executing them. CC @hungneox

from graphql-php.

asheliahut avatar asheliahut commented on June 21, 2024

Is there any thought to use https://github.com/overblog/dataloader-php
to solve the problem like almost everyone in node does?

from graphql-php.

acelot avatar acelot commented on June 21, 2024

I'm trying to adapt this library for my reactphp-project. I was able to perform a deferred request using lordthorzonus/php-dataloader. But for this I had to change the graphql-php code to support async calls. Because the existing executor have a race condition problem Execution::execute():

if ($data instanceof PromiseInterface) {
    $data->then(function ($resolvedData) use (&$data) {
        $data = $resolvedData;
    });
}

<...>

return new ExecutionResult($data, $context->getErrors());

In this section of the code, the $data variable will always be null and will throw an exception.
To add support for asynchronous calls, I suggest adding a new method promiseExecute which implements new PromisedExecutionInterface:

class Execution implements ExecutionInterface, PromisedExecutionInterface
{
    <...>

    public function promiseExecute(
        Schema $schema,
        DocumentNode $documentNode,
        $rootValue = null,
        $contextValue = null,
        array $variableValues = [],
        ?string $operationName = null,
        ?callable $fieldResolver = null,
        ?ErrorHandlerInterface $errorHandler = null
    ): PromiseInterface {
        <...>

        if ($data instanceof PromiseInterface) {
            return $data->then(function ($resolvedData) use ($context) {
                return new ExecutionResult($resolvedData, $context->getErrors());
            });
        }

        <...>

        return resolve(new ExecutionResult($data, $context->getErrors()));
    }

    <...>
}

I can provide PR, but I need help with tests.

from graphql-php.

Jalle19 avatar Jalle19 commented on June 21, 2024

@acelot PRs are more than welcome, I'll help you out with the tests!

from graphql-php.

acelot avatar acelot commented on June 21, 2024

@Jalle19 #345

from graphql-php.

crisu83 avatar crisu83 commented on June 21, 2024

@acelot is this issue resolved?

from graphql-php.

acelot avatar acelot commented on June 21, 2024

Yes, completely.

from graphql-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.