2016-09-14 00:53:55 +03:00
|
|
|
# Upgrade
|
|
|
|
|
2016-11-19 13:46:54 +03:00
|
|
|
## Upgrade v0.7.x > v0.8.x
|
2016-10-17 14:33:47 +03:00
|
|
|
|
2016-11-19 13:46:54 +03:00
|
|
|
### AST node classes
|
|
|
|
AST node classes were renamed to disambiguate with types. e.g.:
|
|
|
|
|
|
|
|
```
|
|
|
|
GraphQL\Language\AST\Field -> GraphQL\Language\AST\FieldNode
|
|
|
|
GraphQL\Language\AST\OjbectValue -> GraphQL\Language\AST\OjbectValueNode
|
|
|
|
```
|
|
|
|
etc.
|
|
|
|
|
|
|
|
Node kind constants were extracted from `GraphQL\Language\AST\Node` to `GraphQL\Language\AST\NodeKind`
|
|
|
|
|
|
|
|
|
|
|
|
### Custom directives handling
|
2016-10-18 21:34:46 +03:00
|
|
|
When passing custom directives to schema, default directives (like `@skip` and `@include`)
|
|
|
|
are not added to schema automatically anymore. If you need them - add them explicitly with your other directives
|
|
|
|
|
|
|
|
Before the change:
|
|
|
|
```php
|
|
|
|
$schema = new Schema([
|
|
|
|
// ...
|
|
|
|
'directives' => [$myDirective]
|
|
|
|
]);
|
|
|
|
```
|
|
|
|
|
|
|
|
After the change:
|
|
|
|
```php
|
|
|
|
$schema = new Schema([
|
|
|
|
// ...
|
|
|
|
'directives' => array_merge(GraphQL::getInternalDirectives(), [$myDirective])
|
|
|
|
]);
|
|
|
|
```
|
|
|
|
|
2016-11-19 13:46:54 +03:00
|
|
|
### Protected property and method naming
|
2016-10-17 14:33:47 +03:00
|
|
|
In order to unify coding style, leading underscores were removed from all private and protected properties
|
|
|
|
and methods.
|
|
|
|
|
|
|
|
Example before the change:
|
|
|
|
```php
|
2016-10-18 18:20:51 +03:00
|
|
|
GraphQL\Schema::$_queryType;
|
2016-10-17 14:33:47 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
Correct usage after the change:
|
|
|
|
```php
|
2016-10-18 18:20:51 +03:00
|
|
|
GraphQL\Schema::$queryType;
|
2016-10-17 14:33:47 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
So if you rely on any protected properties or methods of any GraphQL class, make sure to
|
|
|
|
delete leading underscores.
|
|
|
|
|
2016-11-19 13:46:54 +03:00
|
|
|
### Deprecations
|
|
|
|
There are also several deprecations which still work, but trigger `E_USER_DEPRECATED`
|
|
|
|
when used.
|
|
|
|
|
2016-09-14 00:53:55 +03:00
|
|
|
## Upgrade v0.6.x > v0.7.x
|
|
|
|
|
|
|
|
There are a few new breaking changes in v0.7.0 that were added to the graphql-js reference implementation
|
|
|
|
with the spec of April2016
|
|
|
|
|
|
|
|
### 1. Context for resolver
|
|
|
|
|
2016-09-15 14:44:24 +03:00
|
|
|
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.
|
2016-09-14 00:53:55 +03:00
|
|
|
|
2016-09-15 14:44:24 +03:00
|
|
|
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):
|
2016-09-14 00:53:55 +03:00
|
|
|
```php
|
|
|
|
GraphQL::execute(
|
|
|
|
$schema,
|
|
|
|
$query,
|
2016-09-15 14:44:24 +03:00
|
|
|
$rootValue,
|
2016-09-14 00:53:55 +03:00
|
|
|
$context,
|
|
|
|
$variables,
|
|
|
|
$operationName
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
2016-09-15 14:44:24 +03:00
|
|
|
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) {
|
|
|
|
//...
|
|
|
|
}
|
|
|
|
```
|
2016-09-14 00:53:55 +03:00
|
|
|
|
2016-09-15 14:44:24 +03:00
|
|
|
Starting from v0.7.0 the signature has changed to (note the new `$context` argument):
|
2016-09-14 00:53:55 +03:00
|
|
|
```php
|
|
|
|
/**
|
|
|
|
* @param mixed $object The parent resolved object
|
|
|
|
* @param array $args Input arguments
|
|
|
|
* @param mixed $context The context object hat was passed to GraphQL::execute
|
|
|
|
* @param ResolveInfo $info ResolveInfo object
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function resolveMyField($object, array $args, $context, ResolveInfo $info){
|
|
|
|
//...
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### 2. Schema constructor signature
|
|
|
|
|
2016-09-15 14:44:24 +03:00
|
|
|
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);
|
|
|
|
```
|
2016-09-14 00:53:55 +03:00
|
|
|
|
2016-09-15 14:44:24 +03:00
|
|
|
Starting from v0.7.0:
|
2016-09-14 00:53:55 +03:00
|
|
|
```php
|
|
|
|
$schema = new Schema([
|
|
|
|
'query' => $queryType,
|
|
|
|
'mutation' => $mutationType,
|
|
|
|
'types' => $arrayOfTypesWithInterfaces // See 3.
|
|
|
|
]);
|
|
|
|
```
|
|
|
|
|
|
|
|
### 3. Types can be directly passed to schema
|
|
|
|
|
2016-09-15 14:44:24 +03:00
|
|
|
There are edge cases when GraphQL cannot infer some types from your schema.
|
|
|
|
One example is when you define a field of interface type and object types implementing
|
|
|
|
this interface are not referenced anywhere else.
|
|
|
|
|
|
|
|
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.
|
2016-09-14 00:53:55 +03:00
|
|
|
|
2016-09-15 14:44:24 +03:00
|
|
|
Also see [webonyx/graphql-php#38](https://github.com/webonyx/graphql-php/issues/38)
|