Skip to content

Commit cf38297

Browse files
committed
Updated docs for migration from v0.6.0 to v0.7.0
1 parent 4b651d8 commit cf38297

File tree

1 file changed

+59
-10
lines changed

1 file changed

+59
-10
lines changed

UPGRADE.md

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,49 @@ with the spec of April2016
77

88
### 1. Context for resolver
99

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:
10+
You can now pass a custom context to the `GraphQL::execute` function that is available in all resolvers as 3rd argument.
11+
This can for example be used to pass the current user etc.
1212

13+
Make sure to update all calls to `GraphQL::execute`, `GraphQL::executeAndReturnResult`, `Executor::execute` and all
14+
`'resolve'` callbacks in your app.
15+
16+
Before v0.7.0 `GraphQL::execute` signature looked this way:
17+
```php
18+
GraphQL::execute(
19+
$schema,
20+
$query,
21+
$rootValue,
22+
$variables,
23+
$operationName
24+
);
25+
```
26+
27+
Starting from v0.7.0 the signature looks this way (note the new `$context` argument):
1328
```php
1429
GraphQL::execute(
1530
$schema,
1631
$query,
17-
$rootObject,
32+
$rootValue,
1833
$context,
1934
$variables,
2035
$operationName
2136
);
2237
```
2338

24-
The signature of all resolve methods has changed to the following:
39+
Before v.0.7.0 resolve callbacks had following signature:
40+
```php
41+
/**
42+
* @param mixed $object The parent resolved object
43+
* @param array $args Input arguments
44+
* @param ResolveInfo $info ResolveInfo object
45+
* @return mixed
46+
*/
47+
function resolveMyField($object, array $args, ResolveInfo $info) {
48+
//...
49+
}
50+
```
2551

52+
Starting from v0.7.0 the signature has changed to (note the new `$context` argument):
2653
```php
2754
/**
2855
* @param mixed $object The parent resolved object
@@ -38,8 +65,14 @@ function resolveMyField($object, array $args, $context, ResolveInfo $info){
3865

3966
### 2. Schema constructor signature
4067

41-
The signature of the Schema constructor now accepts an associative config array instead of positional arguments:
68+
The signature of the Schema constructor now accepts an associative config array instead of positional arguments:
69+
70+
Before v0.7.0:
71+
```php
72+
$schema = new Schema($queryType, $mutationType);
73+
```
4274

75+
Starting from v0.7.0:
4376
```php
4477
$schema = new Schema([
4578
'query' => $queryType,
@@ -50,9 +83,25 @@ $schema = new Schema([
5083

5184
### 3. Types can be directly passed to schema
5285

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
86+
There are edge cases when GraphQL cannot infer some types from your schema.
87+
One example is when you define a field of interface type and object types implementing
88+
this interface are not referenced anywhere else.
89+
90+
In such case object types might not be available when an interface is queried and query
91+
validation will fail. In that case, you need to pass the types that implement the
92+
interfaces directly to the schema, so that GraphQL knows of their existence during query validation.
93+
94+
For example:
95+
```php
96+
$schema = new Schema([
97+
'query' => $queryType,
98+
'mutation' => $mutationType,
99+
'types' => $arrayOfTypesWithInterfaces
100+
]);
101+
```
102+
103+
Note that you don't need to pass all types here - only those types that GraphQL "doesn't see"
104+
automatically. Before v7.0.0 the workaround for this was to create a dumb (non-used) field per
105+
each "invisible" object type.
57106

58-
If your types are created each time the Schema is created, this can be ignored.
107+
Also see [webonyx/graphql-php#38](https://github.com/webonyx/graphql-php/issues/38)

0 commit comments

Comments
 (0)