@@ -117,7 +117,7 @@ private function getFieldsByAnnotations(string $annotationName): array
117117
118118 $ phpdocType = $ typeResolver ->resolve ((string ) $ refMethod ->getReturnType ());
119119
120- $ type = $ this ->mapType ($ phpdocType , $ refMethod ->getDocBlockReturnTypes (), $ standardPhpMethod ->getReturnType ()->allowsNull ());
120+ $ type = $ this ->mapType ($ phpdocType , $ refMethod ->getDocBlockReturnTypes (), $ standardPhpMethod ->getReturnType ()->allowsNull (), false );
121121
122122 $ queryList [] = new QueryField ($ methodName , $ type , $ args , [$ this ->controller , $ methodName ], $ this ->hydrator );
123123 }
@@ -169,7 +169,7 @@ private function mapParameters(ReflectionMethod $refMethod, \ReflectionMethod $s
169169
170170 $ phpdocType = $ typeResolver ->resolve ((string ) $ parameter ->getType ());
171171
172- $ args [$ parameter ->getName ()] = $ this ->mapType ($ phpdocType , $ parameter ->getDocBlockTypes (), $ allowsNull );
172+ $ args [$ parameter ->getName ()] = $ this ->mapType ($ phpdocType , $ parameter ->getDocBlockTypes (), $ allowsNull, true );
173173 }
174174
175175 return $ args ;
@@ -180,7 +180,7 @@ private function mapParameters(ReflectionMethod $refMethod, \ReflectionMethod $s
180180 * @param Type[] $docBlockTypes
181181 * @return TypeInterface
182182 */
183- private function mapType (Type $ type , array $ docBlockTypes , bool $ isNullable ): TypeInterface
183+ private function mapType (Type $ type , array $ docBlockTypes , bool $ isNullable, bool $ mapToInputType ): TypeInterface
184184 {
185185 $ graphQlType = null ;
186186
@@ -194,14 +194,14 @@ private function mapType(Type $type, array $docBlockTypes, bool $isNullable): Ty
194194 // TODO: improve error message
195195 throw new GraphQLException ("Don't know how to handle type " .((string ) $ type ));
196196 } elseif (count ($ filteredDocBlockTypes ) === 1 ) {
197- $ graphQlType = $ this ->toGraphQlType ($ filteredDocBlockTypes [0 ]);
197+ $ graphQlType = $ this ->toGraphQlType ($ filteredDocBlockTypes [0 ], $ mapToInputType );
198198 } else {
199199 throw new GraphQLException ('Union types are not supported (yet) ' );
200200 //$graphQlTypes = array_map([$this, 'toGraphQlType'], $filteredDocBlockTypes);
201201 //$$graphQlType = new UnionType($graphQlTypes);
202202 }
203203 } else {
204- $ graphQlType = $ this ->toGraphQlType ($ type );
204+ $ graphQlType = $ this ->toGraphQlType ($ type, $ mapToInputType );
205205 }
206206
207207 if (!$ isNullable ) {
@@ -216,9 +216,10 @@ private function mapType(Type $type, array $docBlockTypes, bool $isNullable): Ty
216216 * Does not deal with nullable.
217217 *
218218 * @param Type $type
219+ * @param bool $mapToInputType
219220 * @return TypeInterface
220221 */
221- private function toGraphQlType (Type $ type ): TypeInterface
222+ private function toGraphQlType (Type $ type, bool $ mapToInputType ): TypeInterface
222223 {
223224 if ($ type instanceof Integer) {
224225 return new IntType ();
@@ -236,9 +237,14 @@ private function toGraphQlType(Type $type): TypeInterface
236237 throw new GraphQLException ('Type-hinting a parameter against DateTime is not allowed. Please use the DateTimeImmutable type instead. ' );
237238 }
238239
239- return $ this ->typeMapper ->mapClassToType (ltrim ($ type ->getFqsen (), '\\' ));
240+ $ className = ltrim ($ type ->getFqsen (), '\\' );
241+ if ($ mapToInputType ) {
242+ return $ this ->typeMapper ->mapClassToInputType ($ className );
243+ } else {
244+ return $ this ->typeMapper ->mapClassToType ($ className );
245+ }
240246 } elseif ($ type instanceof Array_) {
241- return new ListType (new NonNullType ($ this ->toGraphQlType ($ type ->getValueType ())));
247+ return new ListType (new NonNullType ($ this ->toGraphQlType ($ type ->getValueType (), $ mapToInputType )));
242248 } else {
243249 throw new GraphQLException ("Don't know how to handle type " .((string ) $ type ));
244250 }
0 commit comments