From 5af006c6a0063903bfb7ff7f63fec7feee1c2b65 Mon Sep 17 00:00:00 2001 From: David Bennett Date: Mon, 26 Apr 2021 18:32:28 +0100 Subject: [PATCH 1/3] Fix GraphQL `FieldsBuilder` not always fully unwrapping a type before deciding if a resolver is needed. --- src/GraphQl/Type/FieldsBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GraphQl/Type/FieldsBuilder.php b/src/GraphQl/Type/FieldsBuilder.php index aa462454c73..a082bdf27c5 100644 --- a/src/GraphQl/Type/FieldsBuilder.php +++ b/src/GraphQl/Type/FieldsBuilder.php @@ -276,7 +276,7 @@ private function getResourceFieldConfiguration(?string $property, ?string $field return null; } - $graphqlWrappedType = $graphqlType instanceof WrappingType ? $graphqlType->getWrappedType() : $graphqlType; + $graphqlWrappedType = $graphqlType instanceof WrappingType ? $graphqlType->getWrappedType(true) : $graphqlType; $isStandardGraphqlType = \in_array($graphqlWrappedType, GraphQLType::getStandardTypes(), true); if ($isStandardGraphqlType) { $resourceClass = ''; From 9867f76016b2d675d4da1aaabdcbb419ddc2323d Mon Sep 17 00:00:00 2001 From: David Bennett Date: Tue, 27 Apr 2021 13:01:01 +0100 Subject: [PATCH 2/3] Add unit test. --- tests/GraphQl/Type/FieldsBuilderTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/GraphQl/Type/FieldsBuilderTest.php b/tests/GraphQl/Type/FieldsBuilderTest.php index df2f13f055a..82561bf2039 100644 --- a/tests/GraphQl/Type/FieldsBuilderTest.php +++ b/tests/GraphQl/Type/FieldsBuilderTest.php @@ -505,6 +505,7 @@ public function testGetResourceObjectTypeFields(string $resourceClass, ResourceM $this->typeConverterProphecy->convertType(Argument::type(Type::class), Argument::type('bool'), null, $mutationName, null, '', $resourceClass, $propertyName, 1)->willReturn(GraphQLType::string()); $this->typeConverterProphecy->convertType(Argument::type(Type::class), Argument::type('bool'), null, null, $subscriptionName, '', $resourceClass, $propertyName, 1)->willReturn(GraphQLType::string()); $this->typeConverterProphecy->convertType(Argument::type(Type::class), true, null, $mutationName, null, 'subresourceClass', $propertyName, 1)->willReturn(GraphQLType::string()); + $this->typeConverterProphecy->convertType(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)), Argument::type('bool'), $queryName, null, null, '', $resourceClass, $propertyName, 1)->willReturn(GraphQLType::nonNull(GraphQLType::listOf(GraphQLType::nonNull(GraphQLType::string())))); } $this->typesContainerProphecy->has('NotRegisteredType')->willReturn(false); $this->typesContainerProphecy->all()->willReturn([]); @@ -592,6 +593,24 @@ public function resourceObjectTypeFieldsProvider(): array ], ], ], + 'query with simple non-null string array property' => ['resourceClass', new ResourceMetadata(), + [ + 'property' => new PropertyMetadata(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)), null, true, false), + ], + false, 'item_query', null, null, null, + [ + 'id' => [ + 'type' => GraphQLType::nonNull(GraphQLType::id()), + ], + 'property' => [ + 'type' => GraphQLType::nonNull(GraphQLType::listOf(GraphQLType::nonNull(GraphQLType::string()))), + 'description' => null, + 'args' => [], + 'resolve' => null, + 'deprecationReason' => null, + ], + ], + ], 'mutation non input' => ['resourceClass', new ResourceMetadata(), [ 'property' => new PropertyMetadata(), From 8ef71c2d904911f0b1bd0915124436e0d6a9eacb Mon Sep 17 00:00:00 2001 From: David Bennett Date: Tue, 27 Apr 2021 13:01:12 +0100 Subject: [PATCH 3/3] Add CHANGELOG entry. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 440b5515c98..6a756f7c07a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Serializer: Convert internal error to HTTP 400 in Ramsey uuid denormalization from invalid body string (#4200) * Symfony: Add tests with Symfony Uuid (#4230) * OpenAPI: Allow to set extensionProperties with YAML schema definition (#4228) +* GraphQL: Fix `FieldsBuilder` not fully unwrapping nested types before deciding if a resolver is needed (#4251) ## 2.6.4