From 2d6132f678d3e508d66e29f9aca3f7158150574e Mon Sep 17 00:00:00 2001 From: Alan Michel Willms Quinot Date: Sun, 2 Dec 2018 08:22:46 -0200 Subject: [PATCH 1/2] Extract method GraphQL\GraphQL::getSchemaConfiguration (#156) --- src/Rebing/GraphQL/GraphQL.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Rebing/GraphQL/GraphQL.php b/src/Rebing/GraphQL/GraphQL.php index 29515025..bfa2401f 100644 --- a/src/Rebing/GraphQL/GraphQL.php +++ b/src/Rebing/GraphQL/GraphQL.php @@ -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', []); @@ -69,7 +63,7 @@ public function schema($schema = null) $mutation = $this->objectType($schemaMutation, [ 'name' => 'Mutation' ]); - + $subscription = $this->objectType($schemaSubscription, [ 'name' => 'Subscription' ]); @@ -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]; + } } From dd1a5af0db7d673aa70f8540f8bae5885deb736e Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 14 Dec 2018 18:15:34 +0100 Subject: [PATCH 2/2] fix validation (#160) fix validation for input types with listOf wrapped in nonNull --- src/Rebing/GraphQL/Support/Field.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Rebing/GraphQL/Support/Field.php b/src/Rebing/GraphQL/Support/Field.php index c6bed0b4..9e1dccd4 100644 --- a/src/Rebing/GraphQL/Support/Field.php +++ b/src/Rebing/GraphQL/Support/Field.php @@ -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 { @@ -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}.*";