Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for subscriptions with dynamic GraphQL clients #17856

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Test for subscriptions with dynamic GraphQL clients
jmartisk committed Jun 11, 2021

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 326263201dd22bda16c9b10e825f03ee58defef2
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@
import org.eclipse.microprofile.graphql.Mutation;
import org.eclipse.microprofile.graphql.Query;

import io.smallrye.graphql.api.Subscription;
import io.smallrye.mutiny.Multi;

@GraphQLApi
@ApplicationScoped
public class LuckyNumbersResource {
@@ -23,4 +26,9 @@ public Integer setLuckyNumber(Integer newLuckyNumber) {
return luckyNumber;
}

@Subscription
public Multi<Integer> primeNumbers() {
return Multi.createFrom().items(2, 3, 5, 7, 11, 13);
}

}
Original file line number Diff line number Diff line change
@@ -6,8 +6,11 @@
import static io.smallrye.graphql.client.core.Field.field;
import static io.smallrye.graphql.client.core.Operation.operation;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

import java.net.URL;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.jupiter.api.Test;

@@ -44,4 +47,23 @@ public void testDynamicClient() throws Exception {
assertEquals(15, response.getData().getInt("get"), response.toString());
}
}

@Test
public void testDynamicClientSubscription() throws Exception {
try (DynamicGraphQLClient client = DynamicGraphQLClientBuilder.newBuilder().url(url.toString() + "/graphql").build()) {
Document op = document(
operation(OperationType.SUBSCRIPTION,
field("primeNumbers")));
List<Integer> expectedNumbers = List.of(2, 3, 5, 7, 11, 13);
List<Response> responses = client.subscription(op)
.subscribe()
.asStream()
.collect(Collectors.toList());
for (int i = 0; i < expectedNumbers.size(); i++) {
assertEquals(expectedNumbers.get(i), responses.get(i).getData().getInt("primeNumbers"));
assertFalse(responses.get(i).hasError());
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.quarkus.it.smallrye.graphql.client;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.net.URL;
@@ -20,7 +19,6 @@ public class TypesafeClientTest {

@Test
public void testTypesafeClient() throws Exception {

LuckyNumbersClientApi client = TypesafeGraphQLClientBuilder.newBuilder()
.endpoint(url.toString() + "/graphql")
.build(LuckyNumbersClientApi.class);