Skip to content

Commit f52a17e

Browse files
authored
[GraphQL] Fix serializer context attributes for page-based pagination (#3517)
1 parent 8d7290e commit f52a17e

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* MongoDB: Mercure support (#3290)
77
* GraphQL: Subscription support with Mercure (#3321)
88
* GraphQL: Allow to format GraphQL errors based on exceptions (#3063)
9-
* GraphQL: Add page-based pagination (#3175)
9+
* GraphQL: Add page-based pagination (#3175, #3517)
1010
* GraphQL: Possibility to add a custom description for queries, mutations and subscriptions (#3477, #3514)
1111
* GraphQL: Support for field name conversion (serialized name) (#3455, #3516)
1212
* OpenAPI: Add PHP default values to the documentation (#2386)

features/graphql/collection.feature

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ Feature: GraphQL collection support
690690
fooDummies(page: 1) {
691691
collection {
692692
id
693+
name
693694
}
694695
paginationInfo {
695696
itemsPerPage
@@ -703,8 +704,11 @@ Feature: GraphQL collection support
703704
And the response should be in JSON
704705
And the JSON node "data.fooDummies.collection" should have 3 elements
705706
And the JSON node "data.fooDummies.collection[0].id" should exist
707+
And the JSON node "data.fooDummies.collection[0].name" should exist
706708
And the JSON node "data.fooDummies.collection[1].id" should exist
709+
And the JSON node "data.fooDummies.collection[1].name" should exist
707710
And the JSON node "data.fooDummies.collection[2].id" should exist
711+
And the JSON node "data.fooDummies.collection[2].name" should exist
708712
And the JSON node "data.fooDummies.paginationInfo.itemsPerPage" should be equal to the number 3
709713
And the JSON node "data.fooDummies.paginationInfo.lastPage" should be equal to the number 2
710714
And the JSON node "data.fooDummies.paginationInfo.totalCount" should be equal to the number 5
@@ -714,6 +718,7 @@ Feature: GraphQL collection support
714718
fooDummies(page: 2) {
715719
collection {
716720
id
721+
name
717722
}
718723
}
719724
}
@@ -727,6 +732,7 @@ Feature: GraphQL collection support
727732
fooDummies(page: 3) {
728733
collection {
729734
id
735+
name
730736
}
731737
}
732738
}
@@ -744,6 +750,7 @@ Feature: GraphQL collection support
744750
fooDummies(page: 1, itemsPerPage: 2) {
745751
collection {
746752
id
753+
name
747754
}
748755
}
749756
}
@@ -752,13 +759,16 @@ Feature: GraphQL collection support
752759
And the response should be in JSON
753760
And the JSON node "data.fooDummies.collection" should have 2 elements
754761
And the JSON node "data.fooDummies.collection[0].id" should exist
762+
And the JSON node "data.fooDummies.collection[0].name" should exist
755763
And the JSON node "data.fooDummies.collection[1].id" should exist
764+
And the JSON node "data.fooDummies.collection[1].name" should exist
756765
When I send the following GraphQL request:
757766
"""
758767
{
759768
fooDummies(page: 2, itemsPerPage: 2) {
760769
collection {
761770
id
771+
name
762772
}
763773
}
764774
}
@@ -772,6 +782,7 @@ Feature: GraphQL collection support
772782
fooDummies(page: 3, itemsPerPage: 2) {
773783
collection {
774784
id
785+
name
775786
}
776787
}
777788
}

src/GraphQl/Serializer/SerializerContextBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private function fieldsToAttributes(?string $resourceClass, ?ResourceMetadata $r
7878
$fields = $info->getFieldSelection(PHP_INT_MAX);
7979
}
8080

81-
$attributes = $this->replaceIdKeys($fields['edges']['node'] ?? $fields, $resourceClass, $context);
81+
$attributes = $this->replaceIdKeys($fields['edges']['node'] ?? $fields['collection'] ?? $fields, $resourceClass, $context);
8282

8383
if ($resolverContext['is_mutation'] || $resolverContext['is_subscription']) {
8484
if (!$resourceMetadata) {

0 commit comments

Comments
 (0)