Skip to content

Commit

Permalink
Merge pull request #16 from mcg-web/fix-nested-loader-using-webonyx-a…
Browse files Browse the repository at this point in the history
…dapter

Fix nested loaders using webonyx adapter
  • Loading branch information
mcg-web authored Aug 18, 2017
2 parents fa8286f + b9dfaea commit 4983227
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 65 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dist: trusty

language: php

php:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"guzzlehttp/promises": "^1.3.0",
"phpunit/phpunit": "^4.1|^5.1",
"react/promise": "^2.5.0",
"webonyx/graphql-php": "^0.9.0"
"webonyx/graphql-php": "^0.9.14"
},
"suggest": {
"guzzlehttp/promises": "To use with Guzzle promise",
Expand Down
100 changes: 50 additions & 50 deletions lib/promise-adapter/src/PromiseAdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,60 +22,60 @@ interface PromiseAdapterInterface
*
* @return mixed a Promise
*/
public function create(&$resolve = null, &$reject = null, callable $canceller = null);
public function create(&$resolve = null, &$reject = null, callable $canceller = null);

/**
* Creates a full filed Promise for a value if the value is not a promise.
*
* @param mixed $promiseOrValue
*
* @return mixed a full filed Promise
*/
public function createFulfilled($promiseOrValue = null);
/**
* Creates a full filed Promise for a value if the value is not a promise.
*
* @param mixed $promiseOrValue
*
* @return mixed a full filed Promise
*/
public function createFulfilled($promiseOrValue = null);

/**
* Creates a rejected promise for a reason if the reason is not a promise. If
* the provided reason is a promise, then it is returned as-is.
*
* @param mixed $reason
*
* @return mixed a rejected promise
*/
public function createRejected($reason);
/**
* Creates a rejected promise for a reason if the reason is not a promise. If
* the provided reason is a promise, then it is returned as-is.
*
* @param mixed $reason
*
* @return mixed a rejected promise
*/
public function createRejected($reason);

/**
* Given an array of promises, return a promise that is fulfilled when all the
* items in the array are fulfilled.
*
* @param mixed $promisesOrValues Promises or values.
*
* @return mixed a Promise
*/
public function createAll($promisesOrValues);
/**
* Given an array of promises, return a promise that is fulfilled when all the
* items in the array are fulfilled.
*
* @param mixed $promisesOrValues Promises or values.
*
* @return mixed a Promise
*/
public function createAll($promisesOrValues);

/**
* Check if value is a promise
*
* @param mixed $value
* @param bool $strict
*
* @return bool
*/
public function isPromise($value, $strict = false);
/**
* Check if value is a promise
*
* @param mixed $value
* @param bool $strict
*
* @return bool
*/
public function isPromise($value, $strict = false);

/**
* Cancel a promise
*
* @param $promise
*/
public function cancel($promise);
/**
* Cancel a promise
*
* @param $promise
*/
public function cancel($promise);

/**
* wait for Promise to complete
* @param mixed $promise
* @param bool $unwrap
*
* @return mixed
*/
public function await($promise = null, $unwrap = false);
/**
* wait for Promise to complete
* @param mixed $promise
* @param bool $unwrap
*
* @return mixed
*/
public function await($promise = null, $unwrap = false);
}
1 change: 0 additions & 1 deletion lib/promise-adapter/tests/AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/


namespace Overblog\PromiseAdapter\Tests;

use Overblog\PromiseAdapter\Adapter\GuzzleHttpPromiseAdapter;
Expand Down
18 changes: 5 additions & 13 deletions src/Promise/Adapter/Webonyx/GraphQL/SyncPromiseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,19 @@

namespace Overblog\DataLoader\Promise\Adapter\Webonyx\GraphQL;

use GraphQL\Deferred;
use GraphQL\Executor\Promise\Adapter\SyncPromise;
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter as BaseSyncPromiseAdapter;
use GraphQL\Executor\Promise\Promise;
use Overblog\DataLoader\DataLoader;

class SyncPromiseAdapter extends BaseSyncPromiseAdapter
{
/**
* Synchronously wait when promise completes
*
* @param Promise $promise
* @return mixed
*/
public function wait(Promise $promise)
protected function beforeWait(Promise $promise)
{
DataLoader::await();
Deferred::runQueue();
SyncPromise::runQueue();
DataLoader::await();
}

return parent::wait($promise);
protected function onWait(Promise $promise)
{
DataLoader::await();
}
}

0 comments on commit 4983227

Please sign in to comment.