Skip to content

Commit 473bdb6

Browse files
ivomevladar
authored andcommitted
Updated documentation to spec April2016, upgrade instructions
1 parent 1f71ffc commit 473bdb6

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ $> curl -sS https://getcomposer.org/installer | php
4242
$> php composer.phar require webonyx/graphql-php='dev-master'
4343
```
4444

45+
If you are upgrading, see [upgrade instructions](UPGRADE.md)
46+
4547
## Requirements
4648
PHP >=5.4
4749

@@ -52,7 +54,7 @@ Examples below implement the type system described in this document.
5254
### Type System
5355
To start using GraphQL you are expected to implement a Type system.
5456

55-
GraphQL PHP provides several *kinds* of types to build hierarchical type system:
57+
GraphQL PHP provides several *kinds* of types to build a hierarchical type system:
5658
`scalar`, `enum`, `object`, `interface`, `union`, `listOf`, `nonNull`.
5759

5860
#### Internal types
@@ -357,7 +359,17 @@ $queryType = new ObjectType([
357359
// TODOC
358360
$mutationType = null;
359361

360-
$schema = new Schema($queryType, $mutationType);
362+
$schema = new Schema([
363+
'query' => $queryType,
364+
'mutation' => $mutationType,
365+
366+
// We need to pass the types that implement interfaces in case the types are only created on demand.
367+
// This ensures that they are available during query validation phase for interfaces.
368+
'types' => [
369+
$humanType,
370+
$droidType
371+
]
372+
]);
361373
```
362374

363375
**Notes:**
@@ -447,6 +459,7 @@ try {
447459
$schema,
448460
$requestString,
449461
/* $rootValue */ null,
462+
/* $context */ null, // A custom context that can be used to pass current User object etc to resolvers.
450463
$variableValues,
451464
$operationName
452465
);

UPGRADE.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Upgrade
2+
3+
## Upgrade v0.6.x > v0.7.x
4+
5+
There are a few new breaking changes in v0.7.0 that were added to the graphql-js reference implementation
6+
with the spec of April2016
7+
8+
### 1. Context for resolver
9+
10+
You can now pass a custom context to the `GraphQL::execute` function that is available in all resolvers.
11+
This can for example be used to pass the current user etc. The new signature looks like this:
12+
13+
```php
14+
GraphQL::execute(
15+
$schema,
16+
$query,
17+
$rootObject,
18+
$context,
19+
$variables,
20+
$operationName
21+
);
22+
```
23+
24+
The signature of all resolve methods has changed to the following:
25+
26+
```php
27+
/**
28+
* @param mixed $object The parent resolved object
29+
* @param array $args Input arguments
30+
* @param mixed $context The context object hat was passed to GraphQL::execute
31+
* @param ResolveInfo $info ResolveInfo object
32+
* @return mixed
33+
*/
34+
function resolveMyField($object, array $args, $context, ResolveInfo $info){
35+
//...
36+
}
37+
```
38+
39+
### 2. Schema constructor signature
40+
41+
The signature of the Schema constructor now accepts an associative config array instead of positional arguments:
42+
43+
```php
44+
$schema = new Schema([
45+
'query' => $queryType,
46+
'mutation' => $mutationType,
47+
'types' => $arrayOfTypesWithInterfaces // See 3.
48+
]);
49+
```
50+
51+
### 3. Types can be directly passed to schema
52+
53+
In case your implementation creates types on demand, the types might not be available when an interface
54+
is queried and query validation will fail. In that case, you need to pass the types that implement the
55+
interfaces directly to the schema, so it knows of their existence during query validation.
56+
Also see webonyx/graphql-php#38
57+
58+
If your types are created each time the Schema is created, this can be ignored.

0 commit comments

Comments
 (0)