Skip to content

Commit 3921770

Browse files
author
Florian Engelhardt
committed
add more documentation to the source code
1 parent 43ea56a commit 3921770

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

api/app.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@
2020

2121
require __DIR__ . '/schema.php';
2222

23+
// GraphQL-PHP needs to know which async implementation we are using
24+
// in this case it's ReactPHP
2325
$react = new ReactPromiseAdapter();
2426

2527
$server = new Server(function (ServerRequestInterface $request) use ($schema, $react) {
28+
// GraphQL Input is "just" a JSON-String
2629
$input = json_decode((string)$request->getBody(), true);
2730
$query = $input['query'];
2831
$variableValues = isset($input['variables']) ? $input['variables'] : null;
32+
// just pass query and variables to the GraphQL lib
2933
$promise = GraphQL::promiseToExecute($react, $schema, $query, [], null, $variableValues);
34+
// promiseToExecute will return a ReactPHP Promise, so we can register our then callback
3035
return $promise->then(function(ExecutionResult $result) {
3136
$output = $result->toArray();
3237
return new Response(

api/schema.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use GraphQL\Type\Definition\ObjectType;
77
use GraphQL\Type\Definition\Type;
88

9+
// the resolver function may return a string or a ReactPHP Promise
910
$productResolver = function ($review) use ($browser) {
1011
return $browser->get('http://product-service:3000/')->then(function($response) {
1112
$rawBody = (string)$response->getBody();
@@ -20,6 +21,8 @@
2021
});
2122
};
2223

24+
// return type definitions
25+
2326
$productType = new ObjectType([
2427
'name' => 'Product',
2528
'fields' => [
@@ -57,6 +60,8 @@
5760
]
5861
]);
5962

63+
// query defintion
64+
6065
$query = new ObjectType([
6166
'name' => 'Query',
6267
'fields' => [
@@ -87,6 +92,8 @@
8792
],
8893
]);
8994

95+
// schema packs query and types together
96+
9097
$schema = new Schema([
9198
'query' => $query,
9299
'types' => [

0 commit comments

Comments
 (0)