Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port 0.12.3 changes from graphql-js #248

Merged
merged 50 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
eb9ac66
Fix how TypeInfo handles inline fragments without type
danez Feb 8, 2018
46816a7
Uniform parsing of queries with short-hand syntax with regular queries
danez Feb 8, 2018
8747ff8
RFC: Block String
danez Feb 8, 2018
e65638f
Improvements to printing block strings
danez Feb 8, 2018
022c490
RFC: Descriptions as strings
danez Feb 8, 2018
7705e50
Fix print of block string with leading space and quotation
danez Feb 8, 2018
4e26de3
Support for union types when using buildSchema
danez Feb 9, 2018
98e397c
Add additional number lexing test
danez Feb 8, 2018
1fdb3da
Remove notes about subscription being experimental
danez Feb 8, 2018
17a8c26
Simplify operationTypes validation
danez Feb 9, 2018
2123946
Add warnings for nullable changes
danez Feb 9, 2018
27ce24b
Fix parsing of default values in build-schema
danez Feb 9, 2018
48c3330
(Potentially Breaking) Allow serializing scalars as null.
danez Feb 9, 2018
2cbccb8
Remove duplicated code from buildASTSchema and extendSchema
danez Feb 9, 2018
c4f11a5
Allow to extend GraphQL errors with additional properties
danez Feb 9, 2018
1da3801
Add predicates to for built-in types
danez Feb 9, 2018
d6add77
Add Docs
danez Feb 9, 2018
0c32982
Fix KnownDirectives validator to support all directives
danez Feb 11, 2018
d70a9a5
Update to match SDL changes
danez Feb 11, 2018
58453c3
Improve validation error message when field names conflict
danez Feb 11, 2018
7b05673
Validation: improving overlapping fields quality
danez Feb 11, 2018
6e358eb
Fix infinite loop on invalid queries in OverlappingFields
danez Feb 11, 2018
ff63e07
Improve introspection types + new getIntrospectionQuery()
danez Feb 11, 2018
74854d5
Read-only AST types
danez Feb 11, 2018
b5106a0
SDL Spec changes
danez Feb 11, 2018
0c984a8
Allow constructing GraphQLError with single node.
danez Feb 11, 2018
481cdc9
Include test that printSchema includes non-spec directives.
danez Feb 11, 2018
f661f38
Fix unhandled error when parsing custom scalar literals.
danez Feb 11, 2018
15374a3
New: printError()
danez Feb 12, 2018
06c6c4b
Validate schema root types and directives
danez Feb 12, 2018
cf27634
Fix printError/locations for multiple nodes.
danez Feb 13, 2018
6d45a22
Always extract extensions from the original error if possible
danez Feb 13, 2018
60df83f
Preserve original coercion errors, improve error quality.
danez Feb 13, 2018
9387548
Better Predicates
danez Feb 13, 2018
50cbfb4
Fix Bug in PossibleFragmentSpreads validator
danez Feb 13, 2018
6d08c34
Address recent SDL spec changes
danez Feb 13, 2018
97e8a9e
Move schema validation into separate step (type constructors)
danez Feb 15, 2018
fde7df5
Robust type info
danez Feb 15, 2018
949b853
Add experimental support for parsing variable definitions in fragments
danez Feb 15, 2018
1752087
Update some validators to latest upstream version
danez Feb 15, 2018
58e0c7a
Validate literals in a single rule with finer precision
danez Feb 15, 2018
ddfeee3
Fix path argument. Enchance visit test to validate all arguments
danez Feb 15, 2018
d71b45d
Find breaking directive changes
danez Feb 15, 2018
48c5e64
Adding an interface to a type is now a dangerous change.
danez Feb 16, 2018
d92a2da
Add suggestions for invalid values
danez Feb 16, 2018
dc6e814
Fix orList to be the same as in JS and follow the chicago style for c…
danez Feb 16, 2018
5e7cf2a
Skip test on PHP < 7
danez Feb 16, 2018
61fe317
Update docs
danez Feb 16, 2018
f9a366e
Add Fallback for DirectiveLocations
danez Feb 16, 2018
3e067cc
Readd type decorator and fix lazy type loading
danez Mar 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
## Upgrade v0.10.x > dev-master
## Upgrade v0.11.x > dev-master

### Breaking: Descriptions in comments are not used as descriptions by default anymore
Descriptions now need to be inside Strings or BlockStrings in order to be picked up as
description. If you want to keep the old behaviour you can supply the option `commentDescriptions`
to BuildSchema::buildAST(), BuildSchema::build() or Printer::doPrint().

Here is the official way now to define descriptions in the graphQL language:

Old:

```graphql
# Description
type Dog {
...
}
```

New:

```graphql
"Description"
type Dog {
...
}

"""
Long Description
"""
type Dog {
...
}
```

### Breaking: Custom types need to return `Utils::undefined()` or throw on invalid value
As null might be a valid value custom types need to return now `Utils::undefined()` or throw an
Exception inside `parseLiteral()`, `parseValue()` and `serialize()`.

Returning null from any of these methods will now be treated as valid result.

### Breaking: TypeConfigDecorator was removed from BuildSchema
TypeConfigDecorator was used as second argument in `BuildSchema::build()` and `BuildSchema::buildAST()` to
enable generated schemas with Unions or Interfaces to be used for resolving. This was fixed in a more
generalised approach so that the TypeConfigDecorator is not needed anymore and can be removed.

The concrete Types are now resolved based on the `__typename` field.

### Possibly Breaking: AST to array serialization excludes nulls
Most users won't be affected. It *may* affect you only if you do your own manipulations
Expand Down
126 changes: 101 additions & 25 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static function float()
```php
/**
* @api
* @param ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType|NonNull $wrappedType
* @param Type|ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType|NonNull $wrappedType
* @return ListOfType
*/
static function listOf($wrappedType)
Expand Down Expand Up @@ -231,6 +231,15 @@ static function isCompositeType($type)
static function isAbstractType($type)
```

```php
/**
* @api
* @param Type $type
* @return bool
*/
static function isType($type)
```

```php
/**
* @api
Expand Down Expand Up @@ -374,28 +383,28 @@ public $variableValues;
*/
function getFieldSelection($depth = 0)
```
# GraphQL\Type\Definition\DirectiveLocation
# GraphQL\Language\DirectiveLocation
List of available directive locations

**Class Constants:**
```php
const IFACE = "INTERFACE";
const SUBSCRIPTION = "SUBSCRIPTION";
const FRAGMENT_SPREAD = "FRAGMENT_SPREAD";
const QUERY = "QUERY";
const MUTATION = "MUTATION";
const SUBSCRIPTION = "SUBSCRIPTION";
const FIELD = "FIELD";
const FRAGMENT_DEFINITION = "FRAGMENT_DEFINITION";
const INPUT_OBJECT = "INPUT_OBJECT";
const FRAGMENT_SPREAD = "FRAGMENT_SPREAD";
const INLINE_FRAGMENT = "INLINE_FRAGMENT";
const UNION = "UNION";
const SCHEMA = "SCHEMA";
const SCALAR = "SCALAR";
const OBJECT = "OBJECT";
const FIELD_DEFINITION = "FIELD_DEFINITION";
const ARGUMENT_DEFINITION = "ARGUMENT_DEFINITION";
const IFACE = "INTERFACE";
const UNION = "UNION";
const ENUM = "ENUM";
const OBJECT = "OBJECT";
const ENUM_VALUE = "ENUM_VALUE";
const FIELD = "FIELD";
const SCHEMA = "SCHEMA";
const INPUT_OBJECT = "INPUT_OBJECT";
const INPUT_FIELD_DEFINITION = "INPUT_FIELD_DEFINITION";
```

Expand Down Expand Up @@ -431,7 +440,7 @@ static function create(array $options = [])
* @param ObjectType $query
* @return SchemaConfig
*/
function setQuery(GraphQL\Type\Definition\ObjectType $query)
function setQuery($query)
```

```php
Expand All @@ -440,7 +449,7 @@ function setQuery(GraphQL\Type\Definition\ObjectType $query)
* @param ObjectType $mutation
* @return SchemaConfig
*/
function setMutation(GraphQL\Type\Definition\ObjectType $mutation)
function setMutation($mutation)
```

```php
Expand All @@ -449,7 +458,7 @@ function setMutation(GraphQL\Type\Definition\ObjectType $mutation)
* @param ObjectType $subscription
* @return SchemaConfig
*/
function setSubscription(GraphQL\Type\Definition\ObjectType $subscription)
function setSubscription($subscription)
```

```php
Expand Down Expand Up @@ -670,6 +679,18 @@ function getDirectives()
function getDirective($name)
```

```php
/**
* Validates schema.
*
* This operation requires full schema scan. Do not use in production environment.
*
* @api
* @return InvariantViolation[]|Error[]
*/
function validate()
```

```php
/**
* Validates schema.
Expand Down Expand Up @@ -697,10 +718,25 @@ Parses string containing GraphQL query or [type definition](type-system/type-lan
* in the source that they correspond to. This configuration flag
* disables that behavior for performance or testing.)
*
* experimentalFragmentVariables: boolean,
* (If enabled, the parser will understand and parse variable definitions
* contained in a fragment definition. They'll be represented in the
* `variableDefinitions` field of the FragmentDefinitionNode.
*
* The syntax is identical to normal, query-defined variables. For example:
*
* fragment A($var: Boolean = false) on T {
* ...
* }
*
* Note: this feature is experimental and may change or be removed in the
* future.)
*
* @api
* @param Source|string $source
* @param array $options
* @return DocumentNode
* @throws SyntaxError
*/
static function parse($source, array $options = [])
```
Expand Down Expand Up @@ -936,7 +972,12 @@ const UNION_TYPE_DEFINITION = "UnionTypeDefinition";
const ENUM_TYPE_DEFINITION = "EnumTypeDefinition";
const ENUM_VALUE_DEFINITION = "EnumValueDefinition";
const INPUT_OBJECT_TYPE_DEFINITION = "InputObjectTypeDefinition";
const TYPE_EXTENSION_DEFINITION = "TypeExtensionDefinition";
const SCALAR_TYPE_EXTENSION = "ScalarTypeExtension";
const OBJECT_TYPE_EXTENSION = "ObjectTypeExtension";
const INTERFACE_TYPE_EXTENSION = "InterfaceTypeExtension";
const UNION_TYPE_EXTENSION = "UnionTypeExtension";
const ENUM_TYPE_EXTENSION = "EnumTypeExtension";
const INPUT_OBJECT_TYPE_EXTENSION = "InputObjectTypeExtension";
const DIRECTIVE_DEFINITION = "DirectiveDefinition";
```

Expand Down Expand Up @@ -1319,7 +1360,6 @@ Also it is possible to override warning handler (which is **trigger_error()** by

**Class Constants:**
```php
const WARNING_NAME = 1;
const WARNING_ASSIGN = 2;
const WARNING_CONFIG = 4;
const WARNING_FULL_SCHEMA_SCAN = 8;
Expand Down Expand Up @@ -1352,7 +1392,7 @@ static function setWarningHandler(callable $warningHandler = null)
* @api
* @param bool|int $suppress
*/
static function suppress($suppress = false)
static function suppress($suppress = true)
```

```php
Expand All @@ -1367,7 +1407,7 @@ static function suppress($suppress = false)
* @api
* @param bool|int $enable
*/
static function enable($enable = false)
static function enable($enable = true)
```
# GraphQL\Error\ClientAware
This interface is used for [default error formatting](error-handling.md).
Expand Down Expand Up @@ -1697,7 +1737,7 @@ function setPersistentQueryLoader(callable $persistentQueryLoader)
* @param bool|int $set
* @return $this
*/
function setDebug($set = false)
function setDebug($set = true)
```

```php
Expand Down Expand Up @@ -1927,13 +1967,19 @@ See [section in docs](type-system/type-language.md) for details.
* Given that AST it constructs a GraphQL\Type\Schema. The resulting schema
* has no resolve methods, so execution will use default resolvers.
*
* Accepts options as a second argument:
*
* - commentDescriptions:
* Provide true to use preceding comments as the description.
*
*
* @api
* @param DocumentNode $ast
* @param callable $typeConfigDecorator
* @param array $options
* @return Schema
* @throws Error
*/
static function buildAST(GraphQL\Language\AST\DocumentNode $ast, callable $typeConfigDecorator = null)
static function buildAST(GraphQL\Language\AST\DocumentNode $ast, array $options = [])
```

```php
Expand All @@ -1943,10 +1989,10 @@ static function buildAST(GraphQL\Language\AST\DocumentNode $ast, callable $typeC
*
* @api
* @param DocumentNode|Source|string $source
* @param callable $typeConfigDecorator
* @param array $options
* @return Schema
*/
static function build($source, callable $typeConfigDecorator = null)
static function build($source, array $options = [])
```
# GraphQL\Utils\AST
Various utilities dealing with AST
Expand Down Expand Up @@ -2049,6 +2095,32 @@ static function astFromValue($value, GraphQL\Type\Definition\InputType $type)
static function valueFromAST($valueNode, GraphQL\Type\Definition\InputType $type, $variables = null)
```

```php
/**
* Produces a PHP value given a GraphQL Value AST.
*
* Unlike `valueFromAST()`, no type is provided. The resulting JavaScript value
* will reflect the provided GraphQL value AST.
*
* | GraphQL Value | PHP Value |
* | -------------------- | ------------- |
* | Input Object | Assoc Array |
* | List | Array |
* | Boolean | Boolean |
* | String | String |
* | Int / Float | Int / Float |
* | Enum | Mixed |
* | Null | null |
*
* @api
* @param Node $valueNode
* @param array|null $variables
* @return mixed
* @throws \Exception
*/
static function valueFromASTUntyped($valueNode, array $variables = null)
```

```php
/**
* Returns type definition for given AST Type node
Expand All @@ -2057,7 +2129,7 @@ static function valueFromAST($valueNode, GraphQL\Type\Definition\InputType $type
* @param Schema $schema
* @param NamedTypeNode|ListTypeNode|NonNullTypeNode $inputTypeNode
* @return Type
* @throws InvariantViolation
* @throws \Exception
*/
static function typeFromAST(GraphQL\Type\Schema $schema, $inputTypeNode)
```
Expand All @@ -2079,11 +2151,15 @@ Given an instance of Schema, prints it in GraphQL type language.
**Class Methods:**
```php
/**
* Accepts options as a second argument:
*
* - commentDescriptions:
* Provide true to use preceding comments as the description.
* @api
* @param Schema $schema
* @return string
*/
static function doPrint(GraphQL\Type\Schema $schema)
static function doPrint(GraphQL\Type\Schema $schema, array $options = [])
```

```php
Expand All @@ -2092,5 +2168,5 @@ static function doPrint(GraphQL\Type\Schema $schema)
* @param Schema $schema
* @return string
*/
static function printIntrosepctionSchema(GraphQL\Type\Schema $schema)
static function printIntrosepctionSchema(GraphQL\Type\Schema $schema, array $options = [])
```
2 changes: 1 addition & 1 deletion docs/type-system/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ In **graphql-php** custom directive is an instance of `GraphQL\Type\Definition\D

```php
<?php
use GraphQL\Language\DirectiveLocation;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\Directive;
use GraphQL\Type\Definition\DirectiveLocation;
use GraphQL\Type\Definition\FieldArgument;

$trackDirective = new Directive([
Expand Down
31 changes: 3 additions & 28 deletions docs/type-system/type-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,11 @@ $contents = file_get_contents('schema.graphql');
$schema = BuildSchema::build($contents);
```

By default, such schema is created without any resolvers. As a result, it doesn't support **Interfaces** and **Unions**
because it is impossible to resolve actual implementations during execution.
By default, such schema is created without any resolvers.

Also, we have to rely on [default field resolver](../data-fetching.md#default-field-resolver) and **root value** in
We have to rely on [default field resolver](../data-fetching.md#default-field-resolver) and **root value** in
order to execute a query against this schema.

# Defining resolvers
Since 0.10.0

In order to enable **Interfaces**, **Unions** and custom field resolvers you can pass the second argument:
**type config decorator** to schema builder.

It accepts default type config produced by the builder and is expected to add missing options like
[**resolveType**](interfaces.md#configuration-options) for interface types or
[**resolveField**](object-types.md#configuration-options) for object types.

```php
<?php
use GraphQL\Utils\BuildSchema;

$typeConfigDecorator = function($typeConfig, $typeDefinitionNode) {
$name = $typeConfig['name'];
// ... add missing options to $typeConfig based on type $name
return $typeConfig;
};

$contents = file_get_contents('schema.graphql');
$schema = BuildSchema::build($contents, $typeConfigDecorator);
```

# Performance considerations
Since 0.10.0

Expand All @@ -89,4 +64,4 @@ if (!file_exists($cacheFilename)) {

$typeConfigDecorator = function () {};
$schema = BuildSchema::build($document, $typeConfigDecorator);
```
```
Loading