Skip to content

Commit dd35bf4

Browse files
author
Jeremiah VALERIE
committed
📝 Add promise documentation
1 parent cbc43b7 commit dd35bf4

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Data fetching
2+
=============
3+
4+
* [Promise](promise.md)
5+
6+
Next step [secure your server](../security/index.md).
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Promise
2+
3+
The bundle is totally "promise ready", by default it use **Webonyx/GraphQL-Php**
4+
SyncPromise adapter (supporting the native deferred feature) and it also comes
5+
with [ReactPHP/Promise](https://github.com/reactphp/promise) adapter.
6+
To integrate an other promise implementation, you must create a new service that
7+
implements `Overblog\GraphQLBundle\Executor\Promise\PromiseAdapterInterface`.
8+
9+
Config bundle to use the new service:
10+
11+
```yaml
12+
overblog_graphql:
13+
services:
14+
promise_adapter: "my.promise_adapter"
15+
```
16+
17+
You can use the in box `overblog_graphql.react.promise_adapter` service
18+
to manage ReactPHP/Promise.
19+
20+
The `overblog_graphql.promise_adapter` service to create promises
21+
in resolver like this:
22+
23+
```php
24+
<?php
25+
26+
use Overblog\GraphQLBundle\Executor\Promise\PromiseAdapterInterface;
27+
28+
class MyResolver
29+
{
30+
public function __construct(PromiseAdapterInterface $promiseAdapter)
31+
{
32+
$this->promiseAdapter = $promiseAdapter;
33+
}
34+
35+
public function resolveQuery()
36+
{
37+
return $this->promiseAdapter->create(function (callable $resolve) {
38+
return $resolve(['name' => 'Luke']);
39+
});
40+
}
41+
}
42+
```
43+
44+
or using native supported promise like this:
45+
46+
```php
47+
<?php
48+
49+
use React\Promise\Promise as ReactPromise;
50+
51+
class MyResolver
52+
{
53+
public function resolveQuery()
54+
{
55+
return new ReactPromise(function (callable $resolve) {
56+
return $resolve(['name' => 'Luke']);
57+
});
58+
}
59+
}
60+
```

Resources/doc/definitions/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Go further
1313
* [Expression language](expression-language.md)
1414
* [Debug](debug/index.md)
1515

16-
Next step [secure your server](../security/index.md).
16+
Next step [Data fetching](../data-fetching/index.md).

0 commit comments

Comments
 (0)