File tree Expand file tree Collapse file tree 3 files changed +67
-1
lines changed Expand file tree Collapse file tree 3 files changed +67
-1
lines changed Original file line number Diff line number Diff line change 1+ Data fetching
2+ =============
3+
4+ * [ Promise] ( promise.md )
5+
6+ Next step [ secure your server] ( ../security/index.md ) .
Original file line number Diff line number Diff line change 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\G raphQLBundle\E xecutor\P romise\P romiseAdapterInterface;
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\P romise\P romise 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+ ` ` `
Original file line number Diff line number Diff 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 ) .
You can’t perform that action at this time.
0 commit comments