Skip to content

Commit

Permalink
Fix GraphQL example
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg-web authored Feb 10, 2017
1 parent 797c493 commit 0387742
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ For example:
$myLoader = new DataLoader(function ($keys) {
echo json_encode($keys);
return someBatchLoadFn($keys);
}, new Option(['cache' => false ]));
}, $promiseAdapter, new Option(['cache' => false ]));

$myLoader->load('A');
$myLoader->load('B');
Expand All @@ -208,7 +208,7 @@ so later requests will load new values.
$myLoader = new DataLoader(function($keys) use ($identityLoader) {
$identityLoader->clearAll();
return someBatchLoadFn($keys);
});
}, $promiseAdapter);
```


Expand Down Expand Up @@ -338,15 +338,24 @@ and possibly fewer if there are cache hits.

```php
<?php
use GraphQL\GraphQL;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use Overblog\DataLoader\DataLoader;
use Overblog\DataLoader\Promise\Adapter\Webonyx\GraphQL\SyncPromiseAdapter;
use Overblog\PromiseAdapter\Adapter\WebonyxGraphQLSyncPromiseAdapter;

/**
* @var \Overblog\DataLoader\DataLoader $userLoader
* @var \PDO $dbh
*/
// ...

$graphQLPromiseAdapter = new SyncPromiseAdapter();
$dataLoaderPromiseAdapter = new WebonyxGraphQLSyncPromiseAdapter($graphQLPromiseAdapter);
$userLoader = new DataLoader(function ($keys) { /*...*/ }, $dataLoaderPromiseAdapter);

GraphQL::setPromiseAdapter($graphQLPromiseAdapter);

$userType = new ObjectType([
'name' => 'User',
'fields' => function () use (&$userType, $userLoader, $dbh) {
Expand Down Expand Up @@ -376,7 +385,7 @@ $userType = new ObjectType([
}
]);
```
You can also see [an example](https://github.com/mcg-web/sandbox-dataloader-graphql-php/blob/master/with-dataloader.php).
You can also see [an example](https://github.com/mcg-web/sandbox-dataloader-graphql-php).

## Using with Symfony

Expand Down

0 comments on commit 0387742

Please sign in to comment.