Skip to content

Commit ec376e2

Browse files
authored
Add a nonNull wrapper around input objets (#2696)
1 parent b7afbf8 commit ec376e2

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

features/graphql/mutation.feature

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Feature: GraphQL mutation support
1717
type {
1818
name
1919
kind
20+
ofType {
21+
name
22+
kind
23+
}
2024
}
2125
}
2226
}
@@ -31,8 +35,9 @@ Feature: GraphQL mutation support
3135
And the JSON node "data.__type.fields[0].type.name" should match "/^delete[A-z0-9]+Payload$/"
3236
And the JSON node "data.__type.fields[0].type.kind" should be equal to "OBJECT"
3337
And the JSON node "data.__type.fields[0].args[0].name" should be equal to "input"
34-
And the JSON node "data.__type.fields[0].args[0].type.name" should match "/^delete[A-z0-9]+Input$/"
35-
And the JSON node "data.__type.fields[0].args[0].type.kind" should be equal to "INPUT_OBJECT"
38+
And the JSON node "data.__type.fields[0].args[0].type.kind" should be equal to "NON_NULL"
39+
And the JSON node "data.__type.fields[0].args[0].type.ofType.name" should match "/^delete[A-z0-9]+Input$/"
40+
And the JSON node "data.__type.fields[0].args[0].type.ofType.kind" should be equal to "INPUT_OBJECT"
3641

3742
Scenario: Create an item
3843
When I send the following GraphQL request:

src/GraphQl/Type/SchemaBuilder.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Doctrine\Common\Inflector\Inflector;
2727
use GraphQL\Type\Definition\InputObjectType;
2828
use GraphQL\Type\Definition\InterfaceType;
29+
use GraphQL\Type\Definition\NonNull;
2930
use GraphQL\Type\Definition\ObjectType;
3031
use GraphQL\Type\Definition\Type as GraphQLType;
3132
use GraphQL\Type\Definition\WrappingType;
@@ -99,7 +100,13 @@ public function getSchema(): Schema
99100
'fields' => $queryFields,
100101
]),
101102
'typeLoader' => function ($name) {
102-
return $this->graphqlTypes[$name];
103+
$type = $this->graphqlTypes[$name];
104+
105+
if ($type instanceof WrappingType) {
106+
return $type->getWrappedType(true);
107+
}
108+
109+
return $type;
103110
},
104111
];
105112

@@ -394,7 +401,7 @@ private function convertType(Type $type, bool $input = false, string $mutationNa
394401
/**
395402
* Gets the object type of the given resource.
396403
*
397-
* @return ObjectType|InputObjectType
404+
* @return ObjectType|NonNull
398405
*/
399406
private function getResourceObjectType(?string $resourceClass, ResourceMetadata $resourceMetadata, bool $input = false, string $mutationName = null, bool $wrapped = false, int $depth = 0): GraphQLType
400407
{
@@ -451,7 +458,7 @@ private function getResourceObjectType(?string $resourceClass, ResourceMetadata
451458
'interfaces' => $wrapData ? [] : [$this->getNodeInterface()],
452459
];
453460

454-
return $this->graphqlTypes[$shortName] = $input ? new InputObjectType($configuration) : new ObjectType($configuration);
461+
return $this->graphqlTypes[$shortName] = $input ? GraphQLType::nonNull(new InputObjectType($configuration)) : new ObjectType($configuration);
455462
}
456463

457464
/**

0 commit comments

Comments
 (0)