Skip to content

Commit bd44475

Browse files
committed
Documentation and docblock improvements
1 parent 199caf3 commit bd44475

36 files changed

+173
-144
lines changed

docs/complementary-tools.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
- [Integration with Relay](https://github.com/ivome/graphql-relay-php)
44
- [Integration with Laravel 5](https://github.com/Folkloreatelier/laravel-graphql) + [Relay Helpers for Laravel](https://github.com/nuwave/laravel-graphql-relay)
55
- [Symfony Bundle](https://github.com/overblog/GraphQLBundle) by Overblog
6+
- Define types with Doctrine ORM annotations ([for PHP7.1](https://github.com/Ecodev/graphql-doctrine), for [earlier PHP versions](https://github.com/rahuljayaraman/doctrine-graphql))
7+
- Out of the box integration with any PSR-7 compatible framework (like [Slim](http://slimframework.com) or [Zend Expressive](http://zendframework.github.io/zend-expressive/)) via [Standard Server](executing-queries.md/#using-server)
68

79
# Tools
810
- [GraphiQL](https://github.com/graphql/graphiql) - An in-browser IDE for exploring GraphQL

docs/concepts.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ GraphQL is data-centric. On the very top level it is built around three major co
33
**Schema**, **Query** and **Mutation**.
44

55
You are expected to express your application as **Schema** (aka Type System) and expose it
6-
with single [HTTP endpoint](http-endpoint/). Application clients (e.g. web or mobile clients) send **Queries**
6+
with single HTTP endpoint (e.g. using our [standard server](executing-queries.md#using-server)).
7+
Application clients (e.g. web or mobile clients) send **Queries**
78
to this endpoint to request structured data and **Mutations** to perform changes (usually with HTTP POST method).
89

910
## Queries
@@ -34,9 +35,9 @@ It was designed to mirror the structure of expected response:
3435
}
3536
```
3637
**graphql-php** runtime parses Queries, makes sure that they are valid for given Type System
37-
and executes using [data fetching tools](type-system/object-types/#data-fetching) provided by you
38+
and executes using [data fetching tools](data-fetching.md) provided by you
3839
as a part of integration. Queries are supposed to be idempotent.
39-
40+
4041
## Mutations
4142
Mutations use advanced features of the very same query language (like arguments and variables)
4243
and have only semantic difference from Queries:
@@ -135,4 +136,4 @@ $blogPostType = new ObjectType([
135136
# Further Reading
136137
To get deeper understanding of GraphQL concepts - [read the docs on official GraphQL website](http://graphql.org/learn/)
137138

138-
To get started with **graphql-php** - continue to next section ["Getting Started"](getting-started/)
139+
To get started with **graphql-php** - continue to next section ["Getting Started"](getting-started.md)

docs/data-fetching.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plain files or in-memory data structures.
44

55
In order to convert GraphQL query to PHP array **graphql-php** traverses query fields (using depth-first algorithm) and
66
runs special **resolve** function on each field. This **resolve** function is provided by you as a part of
7-
[field definition](type-system/object-types/#field-configuration-options) or [query execution call](executing-queries/#overview).
7+
[field definition](type-system/object-types.md#field-configuration-options) or [query execution call](executing-queries.md#overview).
88

99
Result returned by **resolve** function is directly included in response (for scalars and enums)
1010
or passed down to nested fields (for objects).
@@ -117,11 +117,11 @@ function defaultFieldResolver($source, $args, $context, ResolveInfo $info)
117117
As you see it returns value by key (for arrays) or property (for objects).
118118
If value is not set - it returns **null**.
119119

120-
To override the default resolver, pass it as an argument of [executeQuery](executing-queries) call.
120+
To override the default resolver, pass it as an argument of [executeQuery](executing-queries.md) call.
121121

122122
# Default Field Resolver per Type
123123
Sometimes it might be convenient to set default field resolver per type. You can do so by providing
124-
[resolveField option in type config](type-system/object-types/#configuration-options). For example:
124+
[resolveField option in type config](type-system/object-types.md#configuration-options). For example:
125125

126126
```php
127127
$userType = new ObjectType([

docs/error-handling.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Errors in GraphQL
22

33
Query execution process never throws exceptions. Instead all errors are caught and collected in
4-
[execution result](executing-queries/#execution-result).
4+
[execution result](executing-queries.md#execution-result).
55

66
Later `$result->toArray()` automatically converts these errors to array using default
77
error formatting. But you can apply [custom error filtering and formatting](#custom-error-filtering-and-formatting)
@@ -144,7 +144,7 @@ $result = GraphQL::executeQuery(/* $args */)
144144
->toArray();
145145
```
146146

147-
Note that when you pass [debug flags](#debugging-tools) to `$result->toArray` your custom formatter will still be
147+
Note that when you pass [debug flags](#debugging-tools) to `toArray()` your custom formatter will still be
148148
decorated with same debugging information mentioned above.
149149

150150
# Schema Errors

docs/executing-queries.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Using Facade Method
22
Query execution is a complex process involving multiple steps, including query **parsing**,
3-
**validating** and finally **executing** against your [schema](type-system/schema/).
3+
**validating** and finally **executing** against your [schema](type-system/schema.md).
44

55
**graphql-php** provides convenient facade for this process in class
6-
[`GraphQL\GraphQL`](/reference/#graphqlgraphql):
6+
[`GraphQL\GraphQL`](reference.md#graphqlgraphql):
77

88
```php
99
use GraphQL\GraphQL;
@@ -20,7 +20,7 @@ $result = GraphQL::executeQuery(
2020
);
2121
```
2222

23-
It returns an instance of [`GraphQL\Executor\ExecutionResult`](/reference/#graphqlexecutorexecutionresult)
23+
It returns an instance of [`GraphQL\Executor\ExecutionResult`](reference.md#graphqlexecutorexecutionresult)
2424
which can be easily converted to array:
2525

2626
```php
@@ -30,19 +30,19 @@ $serializableResult = $result->toArray();
3030
Returned array contains **data** and **errors** keys, as described by
3131
[GraphQL spec](http://facebook.github.io/graphql/#sec-Response-Format).
3232
This array is suitable for further serialization (e.g. using **json_encode**).
33-
See also section on [error handling and formatting](error-handling/).
33+
See also section on [error handling and formatting](error-handling.md).
3434

3535
Description of **executeQuery** method arguments:
3636

3737
Argument | Type | Notes
3838
------------ | -------- | -----
39-
schema | [`GraphQL\Type\Schema`](#) | **Required.** Instance of your application [Schema](type-system/schema/)
39+
schema | [`GraphQL\Type\Schema`](#) | **Required.** Instance of your application [Schema](type-system/schema.md)
4040
queryString | `string` or `GraphQL\Language\AST\DocumentNode` | **Required.** Actual GraphQL query string to be parsed, validated and executed. If you parse query elsewhere before executing - pass corresponding ast document here to avoid new parsing.
41-
rootValue | `mixed` | Any value that represents a root of your data graph. It is passed as 1st argument to field resolvers of [Query type](type-system/schema/#query-and-mutation-types). Can be omitted or set to null if actual root values are fetched by Query type itself.
42-
context | `mixed` | Any value that holds information shared between all field resolvers. Most often they use it to pass currently logged in user, locale details, etc.<br><br>It will be available as 3rd argument in all field resolvers. (see section on [Field Definitions](type-system/object-types/#field-configuration-options) for reference) **graphql-php** never modifies this value and passes it *as is* to all underlying resolvers.
41+
rootValue | `mixed` | Any value that represents a root of your data graph. It is passed as 1st argument to field resolvers of [Query type](type-system/schema.md#query-and-mutation-types). Can be omitted or set to null if actual root values are fetched by Query type itself.
42+
context | `mixed` | Any value that holds information shared between all field resolvers. Most often they use it to pass currently logged in user, locale details, etc.<br><br>It will be available as 3rd argument in all field resolvers. (see section on [Field Definitions](type-system/object-types.md#field-configuration-options) for reference) **graphql-php** never modifies this value and passes it *as is* to all underlying resolvers.
4343
variableValues | `array` | Map of variable values passed along with query string. See section on [query variables on official GraphQL website](http://graphql.org/learn/queries/#variables)
4444
operationName | `string` | Allows the caller to specify which operation in queryString will be run, in cases where queryString contains multiple top-level operations.
45-
fieldResolver | `callable` | A resolver function to use when one is not provided by the schema. If not provided, the [default field resolver is used](data-fetching/#default-field-resolver).
45+
fieldResolver | `callable` | A resolver function to use when one is not provided by the schema. If not provided, the [default field resolver is used](data-fetching.md#default-field-resolver).
4646
validationRules | `array` | A set of rules for query validation step. Default value is all available rules. Empty array would allow to skip query validation (may be convenient for persisted queries which are validated before persisting and assumed valid during execution)
4747

4848
# Using Server
@@ -94,17 +94,17 @@ PSR-7 is useful when you want to integrate the server into existing framework:
9494

9595
Argument | Type | Notes
9696
------------ | -------- | -----
97-
schema | [`Schema`](reference/#graphqltypeschema) | **Required.** Instance of your application [Schema](type-system/schema/)
98-
rootValue | `mixed` | Any value that represents a root of your data graph. It is passed as 1st argument to field resolvers of [Query type](type-system/schema/#query-and-mutation-types). Can be omitted or set to null if actual root values are fetched by Query type itself.
99-
context | `mixed` | Any value that holds information shared between all field resolvers. Most often they use it to pass currently logged in user, locale details, etc.<br><br>It will be available as 3rd argument in all field resolvers. (see section on [Field Definitions](type-system/object-types/#field-configuration-options) for reference) **graphql-php** never modifies this value and passes it *as is* to all underlying resolvers.
100-
fieldResolver | `callable` | A resolver function to use when one is not provided by the schema. If not provided, the [default field resolver is used](data-fetching/#default-field-resolver).
101-
validationRules | `array` or `callable` | A set of rules for query validation step. Default value is all available rules. Empty array would allow to skip query validation (may be convenient for persisted queries which are validated before persisting and assumed valid during execution).<br><br>Pass `callable` to return different validation rules for different queries (e.g. empty array for persisted query and full list of rules for regular queries). When passed, it is expected to have following signature: <br><br> **function (OperationParams $params, DocumentNode $node, $operationType): array** <br><br> See also docs on [OperationParams](reference/#graphqlserveroperationparams).
97+
schema | [`Schema`](reference.md#graphqltypeschema) | **Required.** Instance of your application [Schema](type-system/schema/)
98+
rootValue | `mixed` | Any value that represents a root of your data graph. It is passed as 1st argument to field resolvers of [Query type](type-system/schema.md#query-and-mutation-types). Can be omitted or set to null if actual root values are fetched by Query type itself.
99+
context | `mixed` | Any value that holds information shared between all field resolvers. Most often they use it to pass currently logged in user, locale details, etc.<br><br>It will be available as 3rd argument in all field resolvers. (see section on [Field Definitions](type-system/object-types.md#field-configuration-options) for reference) **graphql-php** never modifies this value and passes it *as is* to all underlying resolvers.
100+
fieldResolver | `callable` | A resolver function to use when one is not provided by the schema. If not provided, the [default field resolver is used](data-fetching.md#default-field-resolver).
101+
validationRules | `array` or `callable` | A set of rules for query validation step. Default value is all available rules. Empty array would allow to skip query validation (may be convenient for persisted queries which are validated before persisting and assumed valid during execution).<br><br>Pass `callable` to return different validation rules for different queries (e.g. empty array for persisted query and full list of rules for regular queries). When passed, it is expected to have following signature: <br><br> **function (OperationParams $params, DocumentNode $node, $operationType): array** <br><br> See also docs on [OperationParams](reference.md#graphqlserveroperationparams).
102102
queryBatching | `bool` | Flag indicating whether this server supports query batching ([apollo-style](https://dev-blog.apollodata.com/query-batching-in-apollo-63acfd859862)).<br><br> Defaults to **false**
103-
debug | `int` | Debug flags. See [docs on error debugging](error-handling/#debugging-tools) (flag values are the same).
104-
persistentQueryLoader | `callable` | Function which is called to fetch actual query when server encounters **queryId** in request vs **query**.<br><br> Server does not implement persistence part (which you will have to build on your own), but it allows you to execute queries which were persisted previously.<br><br> Expected function signature:<br> **function ($queryId, OperationParams $params)** <br><br>Function is expected to return query **string** or parsed **DocumentNode** <br><br> See also docs on [OperationParams](reference/#graphqlserveroperationparams). <br><br> [Read more about persisted queries](https://dev-blog.apollodata.com/persisted-graphql-queries-with-apollo-client-119fd7e6bba5).
105-
errorFormatter | `callable` | Custom error formatter. See [error handling docs](error-handling/#custom-error-handling-and-formatting).
106-
errorsHandler | `callable` | Custom errors handler. See [error handling docs](error-handling/#custom-error-handling-and-formatting).
107-
promiseAdapter | [`PromiseAdapter`](reference/#graphqlexecutorpromisepromiseadapter) | Required for [Async PHP](data-fetching/#async-php) only.
103+
debug | `int` | Debug flags. See [docs on error debugging](error-handling.md#debugging-tools) (flag values are the same).
104+
persistentQueryLoader | `callable` | Function which is called to fetch actual query when server encounters **queryId** in request vs **query**.<br><br> Server does not implement persistence part (which you will have to build on your own), but it allows you to execute queries which were persisted previously.<br><br> Expected function signature:<br> **function ($queryId, OperationParams $params)** <br><br>Function is expected to return query **string** or parsed **DocumentNode** <br><br> See also docs on [OperationParams](reference.md#graphqlserveroperationparams). <br><br> [Read more about persisted queries](https://dev-blog.apollodata.com/persisted-graphql-queries-with-apollo-client-119fd7e6bba5).
105+
errorFormatter | `callable` | Custom error formatter. See [error handling docs](error-handling.md#custom-error-handling-and-formatting).
106+
errorsHandler | `callable` | Custom errors handler. See [error handling docs](error-handling.md#custom-error-handling-and-formatting).
107+
promiseAdapter | [`PromiseAdapter`](reference.md#graphqlexecutorpromisepromiseadapter) | Required for [Async PHP](data-fetching/#async-php) only.
108108

109109
**Server config instance**
110110

@@ -129,7 +129,7 @@ $server = new StandardServer($config);
129129
Standard Server supports query batching ([apollo-style](https://dev-blog.apollodata.com/query-batching-in-apollo-63acfd859862)).
130130

131131
One of the major benefits of Server over sequence of **executeQuery()** calls is that
132-
[Deferred resolvers](data-fetching/#solving-n1-problem) won't be isolated in queries.
132+
[Deferred resolvers](data-fetching.md#solving-n1-problem) won't be isolated in queries.
133133

134134
So for example following batch will require single DB request (if user field is deferred):
135135

docs/getting-started.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,18 @@ $queryType = new ObjectType([
6060
],
6161
],
6262
]);
63+
6364
```
6465

65-
(Note: type definition can be expressed in [different styles](type-system/#type-definition-styles),
66+
(Note: type definition can be expressed in [different styles](type-system/index.md#type-definition-styles),
6667
but this example uses **inline** style for simplicity)
6768

6869
The interesting piece here is `resolve` option of field definition. It is responsible for retuning
69-
value of our field. Values of **scalar** fields will be directly included in response while values of
70-
**complex** fields (objects, interfaces, unions) will be passed down to nested field resolvers
70+
a value of our field. Values of **scalar** fields will be directly included in response while values of
71+
**composite** fields (objects, interfaces, unions) will be passed down to nested field resolvers
7172
(not in this example though).
7273

73-
Now when our type is ready, let's create GraphQL endpoint for it `graphql.php`:
74+
Now when our type is ready, let's create GraphQL endpoint file for it **graphql.php**:
7475

7576
```php
7677
<?php
@@ -89,30 +90,32 @@ $variableValues = isset($input['variables']) ? $input['variables'] : null;
8990
try {
9091
$rootValue = ['prefix' => 'You said: '];
9192
$result = GraphQL::executeQuery($schema, $query, $rootValue, null, $variableValues);
93+
$output = $result->toArray();
9294
} catch (\Exception $e) {
93-
$result = [
95+
$output = [
9496
'errors' => [
9597
[
9698
'message' => $e->getMessage()
9799
]
98100
]
99101
];
100102
}
101-
header('Content-Type: application/json; charset=UTF-8');
102-
echo json_encode($result);
103+
header('Content-Type: application/json');
104+
echo json_encode($output);
103105
```
104106

105-
Our example is ready. Try it by running:
107+
Our example is finished. Try it by running:
106108
```sh
107109
php -S localhost:8000 graphql.php
108-
curl http://localhost:8000 -d '{"query": "query { echo(message: \"Hello World\") }" }'
110+
curl http://localhost:8080 -d '{"query": "query { echo(message: \"Hello World\") }" }'
109111
```
110112

111-
Check out the full [source code](https://github.com/webonyx/graphql-php/blob/master/examples/00-hello-world) of this example.
113+
Check out the full [source code](https://github.com/webonyx/graphql-php/blob/master/examples/00-hello-world) of this example
114+
which also includes simple mutation.
112115

113116
Obviously hello world only scratches the surface of what is possible.
114117
So check out next example, which is closer to real-world apps.
115-
Or keep reading about [schema definition](type-system/).
118+
Or keep reading about [schema definition](type-system/index.md).
116119

117120
# Blog example
118121
It is often easier to start with full-featured example and then get back to documentation

docs/how-it-works.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ There are 3 types of errors in GraphQL:
2222
Obviously when **Syntax** or **Validation** error is detected - process is interrupted and query is not
2323
executed.
2424

25+
Execution process never throws exceptions. Instead all errors are caught and collected in
26+
execution result.
27+
2528
GraphQL is forgiving to **Execution** errors which occur in resolvers of nullable fields.
2629
If such field throws or returns unexpected value the value of the field in response will be simply
2730
replaced with `null` and error entry will be registered.
2831

29-
If exception is thrown in non-null field - error bubbles up to first nullable field. This nullable field is
30-
replaced with `null` and error entry is added to response. If all fields up to the root are non-null -
31-
**data** entry will be removed from response and only **errors** key will be presented.
32+
If exception is thrown in non-null field - error bubbles up to first nullable field. This nullable
33+
field is replaced with `null` and error entry is added to response. If all fields up to the root are
34+
non-null - **data** entry will be removed from response and only **errors** key will be presented.

0 commit comments

Comments
 (0)