From 79b20deacc3020c23cc578c6a249ed693e4a5e46 Mon Sep 17 00:00:00 2001 From: Stepan Anchugov Date: Wed, 22 Jan 2020 01:49:36 +0500 Subject: [PATCH] Always pass arguments from expression function Previously, if I was passing arguments to my resolvers with the expression function, I would get `null` instead of an instance if the query has no arguments (e.g. no parens at all in GQL). However, this breaks resolvers that require an instance argument. This makes `@arguments` always try to return an instance of an InputObject whenever it is required. --- src/Transformer/ArgumentsTransformer.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Transformer/ArgumentsTransformer.php b/src/Transformer/ArgumentsTransformer.php index 06ecf2bf9..c4e65507f 100644 --- a/src/Transformer/ArgumentsTransformer.php +++ b/src/Transformer/ArgumentsTransformer.php @@ -81,6 +81,9 @@ private function getType(string $type, ResolveInfo $info): Type private function populateObject(Type $type, $data, bool $multiple, ResolveInfo $info) { if (null === $data) { + if ($type instanceof InputObjectType) { + return $this->getTypeClassInstance($type->name) ?: null; + } return $data; } @@ -129,9 +132,9 @@ private function populateObject(Type $type, $data, bool $multiple, ResolveInfo $ } return $instance; - } else { - return $data; } + + return $data; } /** @@ -170,9 +173,9 @@ public function getInstanceAndValidate(string $argType, $data, ResolveInfo $info if (\count($errors) > 0) { throw new InvalidArgumentError($argName, $errors); - } else { - return $result; } + + return $result; } /**