Skip to content

Commit 80bccbd

Browse files
epouraildunglas
authored andcommitted
Unset the filter (with a dot character), in case of a relation, once it has been sanitized (#2081)
* Unset the filter, in case of a relation, once it has been sanitized * Unitary test on the SchemaBuilder::convertFilterArgsToType() method'
1 parent 01da289 commit 80bccbd

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/GraphQl/Type/SchemaBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ private function convertFilterArgsToTypes(array $args): array
300300
if (strpos($key, '.')) {
301301
// Declare relations/nested fields in a GraphQL compatible syntax.
302302
$args[str_replace('.', '_', $key)] = $value;
303+
unset($args[$key]);
303304
}
304305
}
305306

tests/GraphQl/Type/SchemaBuilderTest.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,32 @@ public function testGetSchemaResourceClassNotFound()
9595
$this->assertArrayNotHasKey('objectProperty', $type->getFields());
9696
}
9797

98+
public function testConvertFilterArgsToTypes()
99+
{
100+
$propertyMetadataMockBuilder = function ($builtinType, $resourceClassName) {
101+
return new PropertyMetadata();
102+
};
103+
$mockedSchemaBuilder = $this->createSchemaBuilder($propertyMetadataMockBuilder, false);
104+
105+
$reflectionClass = new \ReflectionClass(SchemaBuilder::class);
106+
$method = $reflectionClass->getMethod('convertFilterArgsToTypes');
107+
$method->setAccessible(true);
108+
$filterArgs = [
109+
'aField' => 'string',
110+
'GraphqlRelatedResource.nestedFieldA' => 'string',
111+
'GraphqlRelatedResource.nestedFieldB' => 'string',
112+
];
113+
114+
$this->assertSame(
115+
[
116+
'aField' => 'string',
117+
'GraphqlRelatedResource_nestedFieldA' => 'string',
118+
'GraphqlRelatedResource_nestedFieldB' => 'string',
119+
],
120+
$method->invoke($mockedSchemaBuilder, $filterArgs)
121+
);
122+
}
123+
98124
/**
99125
* @dataProvider paginationProvider
100126
*/
@@ -230,8 +256,10 @@ private function createSchemaBuilder($propertyMetadataMockBuilder, bool $paginat
230256
$resourceNameCollection = new ResourceNameCollection($resourceClassNames);
231257
$resourceNameCollectionFactoryProphecy->create()->willReturn($resourceNameCollection);
232258

233-
$collectionResolverFactoryProphecy->__invoke(Argument::cetera())->willReturn(function () {});
234-
$itemMutationResolverFactoryProphecy->__invoke(Argument::cetera())->willReturn(function () {});
259+
$collectionResolverFactoryProphecy->__invoke(Argument::cetera())->willReturn(function () {
260+
});
261+
$itemMutationResolverFactoryProphecy->__invoke(Argument::cetera())->willReturn(function () {
262+
});
235263

236264
return new SchemaBuilder(
237265
$propertyNameCollectionFactoryProphecy->reveal(),
@@ -240,8 +268,10 @@ private function createSchemaBuilder($propertyMetadataMockBuilder, bool $paginat
240268
$resourceMetadataFactoryProphecy->reveal(),
241269
$collectionResolverFactoryProphecy->reveal(),
242270
$itemMutationResolverFactoryProphecy->reveal(),
243-
function () {},
244-
function () {},
271+
function () {
272+
},
273+
function () {
274+
},
245275
null,
246276
$paginationEnabled
247277
);

0 commit comments

Comments
 (0)