Skip to content

Commit 577b1cc

Browse files
committed
some adjustments
1 parent 07add82 commit 577b1cc

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

commercetools/internal-docs/src/test/java/example/ExamplesTest.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.commercetools.api.models.common.LocalizedStringBuilder;
2929
import com.commercetools.api.models.customer.*;
3030
import com.commercetools.api.models.customer_group.*;
31+
import com.commercetools.api.models.graph_ql.GraphQLVariablesMap;
3132
import com.commercetools.api.models.product.AttributesAccessor;
3233
import com.commercetools.api.models.product.ProductProjection;
3334
import com.commercetools.api.models.product.ProductVariant;
@@ -390,22 +391,36 @@ public void graphQLAllOrders() {
390391
int limit = 10, total_length = 0;
391392
String lastId = null;
392393
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);
397405
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);
400408
}
409+
orderBuilder.variables(variables.build());
401410

402411
var result = projectRoot.graphql().query(orderBuilder.build()).executeBlocking();
403412
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+
404419
var length = orders.size();
405420
total_length += length;
406421
lastId = result.getBody().getData().getResults().get(length - 1).getId();
407422

408-
limitNotReached = total_length < limit;
423+
limitNotReached = length == limit;
409424
}
410425
}
411426

0 commit comments

Comments
 (0)