2017-08-12 12:31:35 +03:00
|
|
|
## Upgrade v0.8.x, v0.9.x > v0.10.x
|
2017-08-17 16:35:58 +03:00
|
|
|
|
2017-08-17 22:56:22 +03:00
|
|
|
### Breaking: changed minimum PHP version from 5.4 to 5.5
|
2017-08-17 16:35:58 +03:00
|
|
|
It allows us to leverage `::class` constant, `generators` and other features of newer PHP versions.
|
|
|
|
|
2017-07-19 11:52:00 +03:00
|
|
|
### Breaking: default error formatting
|
2017-07-18 16:57:30 +03:00
|
|
|
By default exceptions thrown in resolvers will be reported with generic message `"Internal server error"`.
|
|
|
|
Only exceptions implementing interface `GraphQL\Error\ClientAware` and claiming themselves as `safe` will
|
|
|
|
be reported with full error message.
|
|
|
|
|
2017-08-17 16:35:58 +03:00
|
|
|
This breaking change is done to avoid information leak in production when unhandled
|
|
|
|
exceptions were reported to clients (e.g. database connection errors, file access errors, etc).
|
2017-07-18 16:57:30 +03:00
|
|
|
|
2017-08-12 12:31:35 +03:00
|
|
|
Also every error reported to client now has new `category` key which is either `graphql` or `internal`.
|
|
|
|
Exceptions implementing `ClientAware` interface may define their own custom categories.
|
|
|
|
|
2017-07-18 16:57:30 +03:00
|
|
|
During development or debugging use `$executionResult->toArray(true)`. It will add `debugMessage` key to
|
|
|
|
each error entry in result. If you also want to add `trace` for each error - pass flags instead:
|
|
|
|
|
|
|
|
```
|
|
|
|
use GraphQL\Error\FormattedError;
|
|
|
|
$debug = FormattedError::INCLUDE_DEBUG_MESSAGE | FormattedError::INCLUDE_TRACE;
|
2017-08-12 12:31:35 +03:00
|
|
|
$result = GraphQL::executeAndReturnResult(/*args*/)->toArray($debug);
|
2017-07-18 16:57:30 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
To change default `"Internal server error"` message to something else, use:
|
|
|
|
```
|
|
|
|
GraphQL\Error\FormattedError::setInternalErrorMessage("Unexpected error");
|
|
|
|
```
|
|
|
|
|
|
|
|
**This change only affects default error reporting mechanism. If you set your own error formatter using
|
2017-08-17 16:35:58 +03:00
|
|
|
`$executionResult->setErrorFormatter($myFormatter)` you won't be affected by this change.**
|
|
|
|
|
|
|
|
If you need to revert to old behavior temporary, use:
|
2017-07-18 16:57:30 +03:00
|
|
|
|
2017-08-17 16:35:58 +03:00
|
|
|
```php
|
|
|
|
GraphQL::executeAndReturnResult(/**/)
|
|
|
|
->setErrorFormatter('\GraphQL\Error\Error::formatError')
|
|
|
|
->toArray();
|
|
|
|
```
|
|
|
|
But note that this is deprecated format and will be removed in future versions.
|
|
|
|
|
|
|
|
In general, if new default formatting doesn't work for you - just set [your own error
|
|
|
|
formatter](http://webonyx.github.io/graphql-php/error-handling/#custom-error-handling-and-formatting).
|
2017-07-18 16:57:30 +03:00
|
|
|
|
2017-08-18 16:48:27 +03:00
|
|
|
### Breaking: Validation rules now have abstract base class
|
|
|
|
Previously any callable was accepted by DocumentValidator as validation rule. Now only instances of
|
|
|
|
`GraphQL\Validator\Rules\AbstractValidationRule` are allowed.
|
|
|
|
|
|
|
|
If you were using custom validation rules, just wrap them with
|
|
|
|
`GraphQL\Validator\Rules\CustomValidationRule` (created for backwards compatibility).
|
|
|
|
|
|
|
|
Before:
|
|
|
|
```php
|
|
|
|
use GraphQL\Validator\DocumentValidator;
|
|
|
|
|
|
|
|
$myRule = function(ValidationContext $context) {};
|
|
|
|
DocumentValidator::validate($schema, $ast, [$myRule]);
|
|
|
|
```
|
|
|
|
|
|
|
|
After:
|
|
|
|
```php
|
|
|
|
use GraphQL\Validator\Rules\CustomValidationRule;
|
|
|
|
use GraphQL\Validator\DocumentValidator;
|
|
|
|
|
|
|
|
$myRule = new CustomValidationRule('MyRule', function(ValidationContext $context) {});
|
|
|
|
DocumentValidator::validate($schema, $ast, [$myRule]);
|
|
|
|
```
|
|
|
|
|
|
|
|
Also `DocumentValidator::addRule()` signature changed.
|
|
|
|
|
|
|
|
Before the change:
|
|
|
|
```php
|
|
|
|
use GraphQL\Validator\DocumentValidator;
|
|
|
|
|
|
|
|
$myRule = function(ValidationContext $context) {};
|
|
|
|
DocumentValidator::addRule('MyRuleName', $myRule);
|
|
|
|
```
|
|
|
|
|
|
|
|
After the change:
|
|
|
|
```php
|
|
|
|
use GraphQL\Validator\DocumentValidator;
|
|
|
|
|
|
|
|
$myRule = new CustomValidationRulefunction('MyRule', ValidationContext $context) {});
|
|
|
|
DocumentValidator::addRule($myRule);
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2017-08-12 12:31:35 +03:00
|
|
|
### Breaking: AST now uses `NodeList` vs array for lists of nodes
|
|
|
|
It helps us unserialize AST from array lazily. This change affects you only if you use `array_`
|
|
|
|
functions with AST or mutate AST directly.
|
2017-07-19 11:52:00 +03:00
|
|
|
|
2017-08-12 12:31:35 +03:00
|
|
|
Before the change:
|
|
|
|
```php
|
|
|
|
new GraphQL\Language\AST\DocumentNode([
|
|
|
|
'definitions' => array(/*...*/)
|
|
|
|
]);
|
|
|
|
```
|
|
|
|
After the change:
|
|
|
|
```
|
|
|
|
new GraphQL\Language\AST\DocumentNode([
|
|
|
|
'definitions' => new NodeList([/*...*/])
|
|
|
|
]);
|
|
|
|
```
|
2017-07-19 11:52:00 +03:00
|
|
|
|
|
|
|
|
2017-08-12 12:31:35 +03:00
|
|
|
### Breaking: scalar types now throw different exceptions when parsing and serializing
|
2017-08-17 16:35:58 +03:00
|
|
|
On invalid client input (`parseValue` and `parseLiteral`) they throw standard `GraphQL\Error\Error`
|
|
|
|
but when they encounter invalid output (in `serialize`) they throw `GraphQL\Error\InvariantViolation`.
|
|
|
|
|
|
|
|
Previously they were throwing `GraphQL\Error\UserError`. This exception is no longer used so make sure
|
|
|
|
to adjust if you were checking for this error in your custom error formatters.
|
2017-07-19 11:52:00 +03:00
|
|
|
|
2017-08-17 16:35:58 +03:00
|
|
|
### Breaking: removed previously deprecated ability to define type as callable
|
|
|
|
See https://github.com/webonyx/graphql-php/issues/35
|
|
|
|
|
2017-08-17 22:56:22 +03:00
|
|
|
### Deprecated: `GraphQL\GraphQL::executeAndReturnResult`
|
|
|
|
Method is renamed to `GraphQL\GraphQL::executeQuery`. Old method name is still available,
|
|
|
|
but will trigger deprecation warning in the next version.
|
2017-08-17 16:35:58 +03:00
|
|
|
|
|
|
|
### Deprecated: `GraphQL\GraphQL::execute`
|
|
|
|
Use `GraphQL\GraphQL::executeQuery()->toArray()` instead.
|
|
|
|
Old method still exists, but will trigger deprecation warning in next version.
|
|
|
|
|
|
|
|
### Deprecated: `GraphQL\Schema` moved to `GraphQL\Type\Schema`
|
|
|
|
Old class still exists, but will trigger deprecation warning in next version.
|
2017-07-19 11:52:00 +03:00
|
|
|
|
|
|
|
### Deprecated: `GraphQL\Utils` moved to `GraphQL\Utils\Utils`
|
2017-07-18 16:57:30 +03:00
|
|
|
Old class still exists, but triggers deprecation warning when referenced.
|
2017-07-10 15:50:26 +03:00
|
|
|
|
2017-08-17 16:35:58 +03:00
|
|
|
### Deprecated: `GraphQL\Type\Definition\Config`
|
|
|
|
If you were using config validation in previous versions, replace:
|
|
|
|
```php
|
|
|
|
GraphQL\Type\Definition\Config::enableValidation();
|
|
|
|
```
|
|
|
|
with:
|
|
|
|
```php
|
|
|
|
$schema->assertValid();
|
|
|
|
```
|
|
|
|
See https://github.com/webonyx/graphql-php/issues/148
|
|
|
|
|
2017-08-17 22:56:22 +03:00
|
|
|
### Non-breaking: usage on async platforms
|
|
|
|
When using the library on async platforms use separate method `GraphQL::promiseToExecute()`.
|
|
|
|
It requires promise adapter in it's first argument and always returns a `Promise`.
|
|
|
|
|
|
|
|
Old methods `GraphQL::execute` and `GraphQL::executeAndReturnResult` still work in backwards-compatible manner,
|
|
|
|
but they are deprecated and will be removed eventually.
|
|
|
|
|
2016-11-19 13:46:54 +03:00
|
|
|
## Upgrade v0.7.x > v0.8.x
|
2016-11-25 12:37:00 +03:00
|
|
|
All of those changes apply to those who extends various parts of this library.
|
|
|
|
If you only use the library and don't try to extend it - everything should work without breaks.
|
2016-10-17 14:33:47 +03:00
|
|
|
|
2016-11-19 13:46:54 +03:00
|
|
|
|
2017-07-19 11:52:00 +03:00
|
|
|
### Breaking: Custom directives handling
|
2016-10-18 21:34:46 +03:00
|
|
|
When passing custom directives to schema, default directives (like `@skip` and `@include`)
|
2016-11-25 12:37:00 +03:00
|
|
|
are not added to schema automatically anymore. If you need them - add them explicitly with
|
|
|
|
your other directives.
|
2016-10-18 21:34:46 +03:00
|
|
|
|
|
|
|
Before the change:
|
|
|
|
```php
|
|
|
|
$schema = new Schema([
|
|
|
|
// ...
|
|
|
|
'directives' => [$myDirective]
|
|
|
|
]);
|
|
|
|
```
|
|
|
|
|
|
|
|
After the change:
|
|
|
|
```php
|
|
|
|
$schema = new Schema([
|
|
|
|
// ...
|
|
|
|
'directives' => array_merge(GraphQL::getInternalDirectives(), [$myDirective])
|
|
|
|
]);
|
|
|
|
```
|
|
|
|
|
2017-07-19 11:52:00 +03:00
|
|
|
### Breaking: Schema protected property and methods visibility
|
2016-11-25 12:37:00 +03:00
|
|
|
Most of the `protected` properties and methods of `GraphQL\Schema` were changed to `private`.
|
|
|
|
Please use public interface instead.
|
2016-10-17 14:33:47 +03:00
|
|
|
|
2017-07-19 11:52:00 +03:00
|
|
|
### Breaking: Node kind constants
|
2016-11-25 12:37:00 +03:00
|
|
|
Node kind constants were extracted from `GraphQL\Language\AST\Node` to
|
|
|
|
separate class `GraphQL\Language\AST\NodeKind`
|
|
|
|
|
2017-07-19 11:52:00 +03:00
|
|
|
### Non-breaking: AST node classes renamed
|
2016-11-25 12:37:00 +03:00
|
|
|
AST node classes were renamed to disambiguate with types. e.g.:
|
2016-10-17 14:33:47 +03:00
|
|
|
|
|
|
|
```
|
2016-11-25 12:37:00 +03:00
|
|
|
GraphQL\Language\AST\Field -> GraphQL\Language\AST\FieldNode
|
|
|
|
GraphQL\Language\AST\OjbectValue -> GraphQL\Language\AST\OjbectValueNode
|
|
|
|
```
|
|
|
|
etc.
|
2016-10-17 14:33:47 +03:00
|
|
|
|
2016-11-25 12:37:00 +03:00
|
|
|
Old names are still available via `class_alias` defined in `src/deprecated.php`.
|
|
|
|
This file is included automatically when using composer autoloading.
|
2016-10-17 14:33:47 +03:00
|
|
|
|
2017-07-19 11:52:00 +03:00
|
|
|
### Deprecations
|
2016-11-25 12:37:00 +03:00
|
|
|
There are several deprecations which still work, but trigger `E_USER_DEPRECATED` when used.
|
|
|
|
|
|
|
|
For example `GraphQL\Executor\Executor::setDefaultResolveFn()` is renamed to `setDefaultResolver()`
|
|
|
|
but still works with old name.
|
2016-11-19 13:46:54 +03:00
|
|
|
|
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
|
|
|
|
|
2017-07-19 11:52:00 +03:00
|
|
|
### 1. Context for resolver
|
2016-09-14 00:53:55 +03:00
|
|
|
|
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){
|
|
|
|
//...
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-07-19 11:52:00 +03:00
|
|
|
### 2. Schema constructor signature
|
2016-09-14 00:53:55 +03:00
|
|
|
|
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.
|
|
|
|
]);
|
|
|
|
```
|
|
|
|
|
2017-07-19 11:52:00 +03:00
|
|
|
### 3. Types can be directly passed to schema
|
2016-09-14 00:53:55 +03:00
|
|
|
|
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)
|