Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryBus with FinalizeGuard enabled returns null #24

Closed
lezhnev74 opened this issue Dec 24, 2017 · 5 comments
Closed

QueryBus with FinalizeGuard enabled returns null #24

lezhnev74 opened this issue Dec 24, 2017 · 5 comments

Comments

@lezhnev74
Copy link
Contributor

lezhnev74 commented Dec 24, 2017

Hi, I am lost with FinalizeGuard and how to set it up properly. I am not sure if this relates to Laravel package or to MessageBus core.

  1. I have my query and corresponding finder. On success it resolves Deferred like this:
class QueryFinder {
    function __invoke($query, Deferred $deferred = null): void
    {
        //...
        $deferred->resolve($query_result);
    }
}
  1. I enabled FinalizeGuard in prooph.php config file.

  2. But the result of the query returns null.

// I use facade
$query_result = QueryBus::resultFrom($query);
// $query_result is null now
  1. If I disable the FinalizeGuard then query returns valid result. So it led me into looking inside of the FinalizeGuard code.

  2. Looking at 48 line: https://github.com/prooph/service-bus/blob/c239acfd43cf8eec577e30ce0aa7da86d87b6191/src/Plugin/Guard/FinalizeGuard.php#L48
    It creates a new Promise and here it losts resolved result.

It seems that I misuse QueryBus. Can you suggest the right way of resolving Deferred object inside my QueryFinder which works with FinalizeGuard?

@lezhnev74 lezhnev74 changed the title FinalizeGuard issue QueryBus with FinalizeGuard enabled returns null Dec 24, 2017
@basz
Copy link
Member

basz commented Dec 24, 2017

It seems that I misuse QueryBus

Why you think you misuse the query bus?

$this->queryBus
            ->dispatch(
                (new GetCustomer(['customer_id' => ...]))
            )
            ->done(function (QueryResult $result) use (&$dto) {
                $dto = $result->data();
            });

This works for me with FinalizeGuard enabled

@lezhnev74
Copy link
Contributor Author

Hmm, can you show how you resolve deferred promise inside the finder class?

@basz
Copy link
Member

basz commented Dec 24, 2017

    public function getCustomer(GetCustomer $query, Deferred $deferred): void
    {
        /** @var Customer $customer */
        if ($customer = $this->entityManager->getRepository(Customer::class)->find($query->customerId())) {
            $customerDTO = CustomerDTO::fromEntity($customer, $query->included());

            $deferred->resolve(JsonApiQueryResult::with($customerDTO, [], new EncodingParameters($query->included())));
        } else {
            $deferred->reject(new DomainException('Not found', 404));
        }
    }

@lezhnev74
Copy link
Contributor Author

lezhnev74 commented Dec 24, 2017

I have removed everything and included just bare message bus and implemented this test:
https://github.com/lezhnev74/prooph-query-test/blob/prooph-bare/tests/QueryTest.php

It has 3 tests:

  • executing query with no guards [pass]
  • executing query with RouteGuard [pass]
  • executing query with FinalizeGuard [fail]

Hmm, why does it fail in the last test?

@lezhnev74
Copy link
Contributor Author

This is not about Laravel packag I'd say, so I am closing this issue.
The issue in message bus hub: prooph/service-bus#177

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants