@@ -133,37 +133,34 @@ protected function normalizeCollectionOfRelations(ApiProperty $propertyMetadata,
133133 // Handle relationships for mercure subscriptions
134134 if ($ operation instanceof QueryCollection && 'mercure_subscription ' === $ context ['graphql_operation_name ' ] && $ attributeValue instanceof Collection && !$ attributeValue ->isEmpty ()) {
135135 $ relationContext = $ context ;
136- // Grab collection attributes
137136 $ relationContext ['attributes ' ] = $ context ['attributes ' ]['collection ' ];
138- // Iterate over the collection and normalize each item
139- $ data ['collection ' ] = $ attributeValue
140- ->map (fn ($ item ) => $ this ->normalize ($ item , $ format , $ relationContext ))
141- // Convert the collection to an array
142- ->toArray ();
143-
144- // Handle pagination if it's enabled in the query
145- return $ this ->addPagination ($ attributeValue , $ data , $ context );
137+ $ data ['collection ' ] = [];
138+ foreach ($ attributeValue as $ item ) {
139+ $ data ['collection ' ][] = $ this ->normalize ($ item , $ format , $ relationContext );
140+ }
141+
142+ return $ this ->addPagination ($ attributeValue ->count (), $ data , $ context );
146143 }
147144
148145 // to-many are handled directly by the GraphQL resolver
149146 return [];
150147 }
151148
152- private function addPagination (Collection $ collection , array $ data , array $ context ): array
149+ private function addPagination (int $ totalCount , array $ data , array $ context ): array
153150 {
154151 if ($ context ['attributes ' ]['paginationInfo ' ] ?? false ) {
155152 $ data ['paginationInfo ' ] = [];
156153 if (\array_key_exists ('hasNextPage ' , $ context ['attributes ' ]['paginationInfo ' ])) {
157- $ data ['paginationInfo ' ]['hasNextPage ' ] = $ collection -> count () > ($ context ['pagination ' ]['itemsPerPage ' ] ?? 10 );
154+ $ data ['paginationInfo ' ]['hasNextPage ' ] = $ totalCount > ($ context ['pagination ' ]['itemsPerPage ' ] ?? 10 );
158155 }
159156 if (\array_key_exists ('itemsPerPage ' , $ context ['attributes ' ]['paginationInfo ' ])) {
160157 $ data ['paginationInfo ' ]['itemsPerPage ' ] = $ context ['pagination ' ]['itemsPerPage ' ] ?? 10 ;
161158 }
162159 if (\array_key_exists ('lastPage ' , $ context ['attributes ' ]['paginationInfo ' ])) {
163- $ data ['paginationInfo ' ]['lastPage ' ] = (int ) ceil ($ collection -> count () / ($ context ['pagination ' ]['itemsPerPage ' ] ?? 10 ));
160+ $ data ['paginationInfo ' ]['lastPage ' ] = (int ) ceil ($ totalCount / ($ context ['pagination ' ]['itemsPerPage ' ] ?? 10 ));
164161 }
165162 if (\array_key_exists ('totalCount ' , $ context ['attributes ' ]['paginationInfo ' ])) {
166- $ data ['paginationInfo ' ]['totalCount ' ] = $ collection -> count () ;
163+ $ data ['paginationInfo ' ]['totalCount ' ] = $ totalCount ;
167164 }
168165 }
169166
0 commit comments