Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 6 additions & 5 deletions Definition/Builder/SchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ public function __construct(TypeResolver $typeResolver, SchemaDecorator $decorat
* @param null|string $mutationAlias
* @param null|string $subscriptionAlias
* @param ResolverMapInterface[] $resolverMaps
* @param string[] $types
*
* @return Schema
*/
public function create($queryAlias = null, $mutationAlias = null, $subscriptionAlias = null, array $resolverMaps = [])
public function create($queryAlias = null, $mutationAlias = null, $subscriptionAlias = null, array $resolverMaps = [], array $types = [])
{
$query = $this->typeResolver->resolve($queryAlias);
$mutation = $this->typeResolver->resolve($mutationAlias);
$subscription = $this->typeResolver->resolve($subscriptionAlias);

$schema = new Schema($this->buildSchemaArguments($query, $mutation, $subscription));
$schema = new Schema($this->buildSchemaArguments($query, $mutation, $subscription, $types));
reset($resolverMaps);
$this->decorator->decorate($schema, 1 === count($resolverMaps) ? current($resolverMaps) : new ResolverMaps($resolverMaps));

Expand All @@ -52,7 +53,7 @@ public function create($queryAlias = null, $mutationAlias = null, $subscriptionA
return $schema;
}

private function buildSchemaArguments(Type $query = null, Type $mutation = null, Type $subscription = null)
private function buildSchemaArguments(Type $query = null, Type $mutation = null, Type $subscription = null, array $types = [])
{
return [
'query' => $query,
Expand All @@ -61,8 +62,8 @@ private function buildSchemaArguments(Type $query = null, Type $mutation = null,
'typeLoader' => function ($name) {
return $this->typeResolver->resolve($name);
},
'types' => function () {
return $this->typeResolver->getSolutions();
'types' => function () use ($types) {
return array_map([$this->typeResolver, 'getSolution'], $types);
},
];
}
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ private function definitionsSchemaSection()
->defaultValue([])
->prototype('scalar')->end()
->end()
->arrayNode('types')
->defaultValue([])
->prototype('scalar')->end()
->end()
->end()
->end()
->end();
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/OverblogGraphQLExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ private function setSchemaArguments(array $config, ContainerBuilder $container)
array_map(function ($id) {
return new Reference($id);
}, $schemaConfig['resolver_maps']),
$schemaConfig['types'],
]);
$definition->setPublic(false);
$container->setDefinition($schemaID, $definition);
Expand Down
14 changes: 14 additions & 0 deletions Resources/doc/definitions/relay/node/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,17 @@ User:
type: String
interfaces: [Node]
```

In above example `Photo` and `User` can't be detected by graphql-php during
static schema analysis. That the reason why their should be explicitly declare
in schema definition:

```yaml
overblog_graphql:
definitions:
schema:
query: Query
mutation: ~
# here how this can be done
types: [User, Photo]
```
4 changes: 4 additions & 0 deletions Resources/doc/definitions/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ overblog_graphql:
schema:
query: Query
mutation: ~
# the name of extra types that can not be detected
# by graphql-php during static schema analysis.
# These types names should be explicitly declare here
types: []
```

## Batching
Expand Down
1 change: 1 addition & 0 deletions Tests/Functional/App/config/node/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ overblog_graphql:
schema:
query: Query
mutation: ~
types: [User, Photo]
mappings:
auto_discover: true
types:
Expand Down
58 changes: 57 additions & 1 deletion UPGRADE-0.11.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ UPGRADE FROM 0.10 to 0.11
- [Promise adapter interface](#promise-adapter-interface)
- [Expression language](#expression-language)
- [Type autoMapping and Symfony DI autoconfigure](#type-automapping-and-symfony-di-autoconfigure)
- [Explicitly declare non detected types](#explicitly-declare-non-detected-types)

### GraphiQL

Expand Down Expand Up @@ -166,7 +167,7 @@ UPGRADE FROM 0.10 to 0.11

class DateTimeType extends ScalarType implements AliasedInterface
{
public $name = 'DateTme';
public $name = 'DateTime';

/**
* {@inheritdoc}
Expand All @@ -178,3 +179,58 @@ UPGRADE FROM 0.10 to 0.11
// ...
}
```

### Explicitly declare non detected types

**Before 0.11** all types was declare as non detected types, this was not the correct way of declaring types.
This could lead to some performances issues or/and wrong types public exposition (in introspection query).
[See webonyx/graphql-php documentations for more details](http://webonyx.github.io/graphql-php/type-system/schema/#configuration-options)

**Since 0.11** Non detect types should be explicitly declare

here a concrete example:
```yaml
Query:
type: object
config:
fields:
foo: {type: FooInterface!}

FooInterface:
type: interface
config:
fields:
id: {type: ID!}
resolveType: '@=resolver("foo", [value])'

Bar:
type: object
config:
fields:
id: {type: ID!}
# ...
interfaces: [FooInterface]

Baz:
type: object
config:
fields:
id: {type: ID!}
# ...
interfaces: [FooInterface]
```
In above example `Baz` an `Bar` can not be detected by graphql-php during static schema analysis,
an `GraphQL\Error\InvariantViolation` exception will be throw with the following message:
```text
Could not find possible implementing types for FooInterface in schema.
Check that schema.types is defined and is an array of all possible types in the schema.
```
here how this can be fix:

```yaml
overblog_graphql:
definitions:
schema:
query: Query
types: [Bar, Baz]
```