Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikk Mihkel Nurges committed Dec 17, 2018
2 parents a6e3521 + dd1a5af commit 9dc64aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/Rebing/GraphQL/GraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ public function schema($schema = null)
$this->type($name);
}

$schemaName = is_string($schema) ? $schema : config('graphql.default_schema', 'default');

if (!is_array($schema) && !isset($this->schemas[$schemaName])) {
throw new SchemaNotFound('Type '.$schemaName.' not found.');
}

$schema = is_array($schema) ? $schema:$this->schemas[$schemaName];
$schema = $this->getSchemaConfiguration($schema);

$schemaQuery = array_get($schema, 'query', []);
$schemaMutation = array_get($schema, 'mutation', []);
Expand Down Expand Up @@ -69,7 +63,7 @@ public function schema($schema = null)
$mutation = $this->objectType($schemaMutation, [
'name' => 'Mutation'
]);

$subscription = $this->objectType($schemaSubscription, [
'name' => 'Subscription'
]);
Expand Down Expand Up @@ -336,4 +330,15 @@ public static function routeNameTransformer ($name, $schemaParameterPattern, $qu

return $routeName ?: preg_replace($schemaParameterPattern, '{' . $name . '}', $queryRoute);
}

protected function getSchemaConfiguration($schema)
{
$schemaName = is_string($schema) ? $schema : config('graphql.default_schema', 'default');

if (!is_array($schema) && !isset($this->schemas[$schemaName])) {
throw new SchemaNotFound('Type ' . $schemaName . ' not found.');
}

return is_array($schema) ? $schema : $this->schemas[$schemaName];
}
}
6 changes: 6 additions & 0 deletions src/Rebing/GraphQL/Support/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\ListOfType;
use GraphQL\Type\Definition\WrappingType;
use GraphQL\Type\Definition\NonNull;

class Field extends Fluent {

Expand Down Expand Up @@ -93,6 +94,11 @@ public function inferRulesFromType($type, $prefix, $resolutionArguments)
{
$rules = [];

// make sure we are dealing with the actual type
if ($type instanceof NonNull) {
$type = $type->getWrappedType();
}

// if it is an array type, add an array validation component
if ($type instanceof ListOfType) {
$prefix = "{$prefix}.*";
Expand Down

0 comments on commit 9dc64aa

Please sign in to comment.