|
28 | 28 | import com.commercetools.api.models.common.LocalizedStringBuilder; |
29 | 29 | import com.commercetools.api.models.customer.*; |
30 | 30 | import com.commercetools.api.models.customer_group.*; |
| 31 | +import com.commercetools.api.models.graph_ql.GraphQLVariablesMap; |
31 | 32 | import com.commercetools.api.models.product.AttributesAccessor; |
32 | 33 | import com.commercetools.api.models.product.ProductProjection; |
33 | 34 | import com.commercetools.api.models.product.ProductVariant; |
@@ -390,22 +391,36 @@ public void graphQLAllOrders() { |
390 | 391 | int limit = 10, total_length = 0; |
391 | 392 | String lastId = null; |
392 | 393 | while (limitNotReached) { |
393 | | - GraphQLRequestBuilder<OrderQueryResult> orderBuilder = GraphQL |
394 | | - .query("query getOrders { " + "orders (limit: " + limit + ") {" + "results {id}}}") |
395 | | - .dataMapper(GraphQLData::getOrders); |
396 | | - |
| 394 | + GraphQLRequestBuilder<OrderQueryResult> orderBuilder = GraphQL.query(""" |
| 395 | + query Orders($where: String, $limit: Int!) { |
| 396 | + orders(where: $where, sort: "id asc", limit: $limit) { |
| 397 | + results { |
| 398 | + id |
| 399 | + version |
| 400 | + } |
| 401 | + } |
| 402 | + }""").dataMapper(GraphQLData::getOrders); |
| 403 | + |
| 404 | + var variables = GraphQLVariablesMap.builder().addValue("limit", limit); |
397 | 405 | if (lastId != null) { |
398 | | - String whereQuery = "id > " + lastId; |
399 | | - orderBuilder.variables(builder -> builder.addValue("where", whereQuery)); |
| 406 | + String whereQuery = "id > \"%s\"".formatted(lastId); |
| 407 | + variables.addValue("where", whereQuery); |
400 | 408 | } |
| 409 | + orderBuilder.variables(variables.build()); |
401 | 410 |
|
402 | 411 | var result = projectRoot.graphql().query(orderBuilder.build()).executeBlocking(); |
403 | 412 | var orders = result.getBody().getData().getResults(); |
| 413 | + |
| 414 | + orders.forEach(order -> { |
| 415 | + Assertions.assertThat(order.getId()).isNotNull(); |
| 416 | + Assertions.assertThat(order.getVersion()).isNotNull(); |
| 417 | + }); |
| 418 | + |
404 | 419 | var length = orders.size(); |
405 | 420 | total_length += length; |
406 | 421 | lastId = result.getBody().getData().getResults().get(length - 1).getId(); |
407 | 422 |
|
408 | | - limitNotReached = total_length < limit; |
| 423 | + limitNotReached = length == limit; |
409 | 424 | } |
410 | 425 | } |
411 | 426 |
|
|
0 commit comments