Updated docs for migration from v0.6.0 to v0.7.0

This commit is contained in:
vladar 2016-09-15 18:44:24 +07:00
parent 4b651d80a5
commit cf38297d75

View File

@ -7,22 +7,49 @@ with the spec of April2016
### 1. Context for resolver ### 1. Context for resolver
You can now pass a custom context to the `GraphQL::execute` function that is available in all resolvers. You can now pass a custom context to the `GraphQL::execute` function that is available in all resolvers as 3rd argument.
This can for example be used to pass the current user etc. The new signature looks like this: This can for example be used to pass the current user etc.
Make sure to update all calls to `GraphQL::execute`, `GraphQL::executeAndReturnResult`, `Executor::execute` and all
`'resolve'` callbacks in your app.
Before v0.7.0 `GraphQL::execute` signature looked this way:
```php
GraphQL::execute(
$schema,
$query,
$rootValue,
$variables,
$operationName
);
```
Starting from v0.7.0 the signature looks this way (note the new `$context` argument):
```php ```php
GraphQL::execute( GraphQL::execute(
$schema, $schema,
$query, $query,
$rootObject, $rootValue,
$context, $context,
$variables, $variables,
$operationName $operationName
); );
``` ```
The signature of all resolve methods has changed to the following: Before v.0.7.0 resolve callbacks had following signature:
```php
/**
* @param mixed $object The parent resolved object
* @param array $args Input arguments
* @param ResolveInfo $info ResolveInfo object
* @return mixed
*/
function resolveMyField($object, array $args, ResolveInfo $info) {
//...
}
```
Starting from v0.7.0 the signature has changed to (note the new `$context` argument):
```php ```php
/** /**
* @param mixed $object The parent resolved object * @param mixed $object The parent resolved object
@ -40,6 +67,12 @@ function resolveMyField($object, array $args, $context, ResolveInfo $info){
The signature of the Schema constructor now accepts an associative config array instead of positional arguments: The signature of the Schema constructor now accepts an associative config array instead of positional arguments:
Before v0.7.0:
```php
$schema = new Schema($queryType, $mutationType);
```
Starting from v0.7.0:
```php ```php
$schema = new Schema([ $schema = new Schema([
'query' => $queryType, 'query' => $queryType,
@ -50,9 +83,25 @@ $schema = new Schema([
### 3. Types can be directly passed to schema ### 3. Types can be directly passed to schema
In case your implementation creates types on demand, the types might not be available when an interface There are edge cases when GraphQL cannot infer some types from your schema.
is queried and query validation will fail. In that case, you need to pass the types that implement the One example is when you define a field of interface type and object types implementing
interfaces directly to the schema, so it knows of their existence during query validation. this interface are not referenced anywhere else.
Also see webonyx/graphql-php#38
If your types are created each time the Schema is created, this can be ignored. In such case object types might not be available when an interface is queried and query
validation will fail. In that case, you need to pass the types that implement the
interfaces directly to the schema, so that GraphQL knows of their existence during query validation.
For example:
```php
$schema = new Schema([
'query' => $queryType,
'mutation' => $mutationType,
'types' => $arrayOfTypesWithInterfaces
]);
```
Note that you don't need to pass all types here - only those types that GraphQL "doesn't see"
automatically. Before v7.0.0 the workaround for this was to create a dumb (non-used) field per
each "invisible" object type.
Also see [webonyx/graphql-php#38](https://github.com/webonyx/graphql-php/issues/38)