|
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; |
34 | 35 | import com.commercetools.api.models.product.ProductVariantBuilder; |
35 | 36 | import com.commercetools.api.models.product_type.AttributeLocalizedEnumValue; |
36 | 37 | import com.commercetools.api.models.project.Project; |
37 | 38 | import com.commercetools.api.models.tax_category.TaxCategoryPagedQueryResponse; |
| 39 | +import com.commercetools.graphql.CommercetoolsTestUtils; |
| 40 | +import com.commercetools.graphql.api.GraphQL; |
| 41 | +import com.commercetools.graphql.api.GraphQLData; |
| 42 | +import com.commercetools.graphql.api.GraphQLRequestBuilder; |
| 43 | +import com.commercetools.graphql.api.types.OrderQueryResult; |
38 | 44 | import com.commercetools.http.apachehttp.CtApacheHttpClient; |
39 | 45 | import com.commercetools.http.javanet.CtJavaNetHttpClient; |
40 | 46 | import com.commercetools.http.netty.CtNettyHttpClient; |
@@ -379,6 +385,45 @@ public void queryAll() { |
379 | 385 | .join(); |
380 | 386 | } |
381 | 387 |
|
| 388 | + public void graphQLAllOrders() { |
| 389 | + final ProjectApiRoot projectRoot = CommercetoolsTestUtils.getProjectApiRoot(); |
| 390 | + boolean limitNotReached = true; |
| 391 | + int limit = 10, total_length = 0; |
| 392 | + String lastId = null; |
| 393 | + while (limitNotReached) { |
| 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); |
| 405 | + if (lastId != null) { |
| 406 | + String whereQuery = "id > \"%s\"".formatted(lastId); |
| 407 | + variables.addValue("where", whereQuery); |
| 408 | + } |
| 409 | + orderBuilder.variables(variables.build()); |
| 410 | + |
| 411 | + var result = projectRoot.graphql().query(orderBuilder.build()).executeBlocking(); |
| 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 | + |
| 419 | + var length = orders.size(); |
| 420 | + total_length += length; |
| 421 | + lastId = result.getBody().getData().getResults().get(length - 1).getId(); |
| 422 | + |
| 423 | + limitNotReached = length == limit; |
| 424 | + } |
| 425 | + } |
| 426 | + |
382 | 427 | public void middleware() { |
383 | 428 | ProjectApiRoot apiRoot = ApiRootBuilder.of() |
384 | 429 | .defaultClient(ClientCredentials.of() |
|
0 commit comments