use of com.graphql_java_generator.samples.forum.client.graphql.forum.client.GraphQLRequest in project graphql-maven-plugin-project by graphql-java-generator.
the class FullRequestIT method setupAll.
@BeforeAll
static void setupAll() throws GraphQLRequestPreparationException {
// We have one GraphQL endpoint. So we use the static configuration.
GraphQLRequest.setStaticConfiguration(new GraphQLConfiguration(GRAPHQL_ENDPOINT_URL));
// Let's build once the request, and use it for each further execution
boardsRequest = new GraphQLRequest("query{boards{id name topics {id}}}");
}
use of com.graphql_java_generator.samples.forum.client.graphql.forum.client.GraphQLRequest in project graphql-maven-plugin-project by graphql-java-generator.
the class SubscriptionRequests method execSubscription.
public void execSubscription() throws GraphQLRequestPreparationException, GraphQLRequestExecutionException, IOException {
// Preparation
GraphQLRequest subscriptionRequest = subscriptionTypeExecutor.getSubscribeToNewPostGraphQLRequest("{id date author publiclyAvailable title content}");
GraphQLRequest createPostRequest = mutationTypeExecutor.getCreatePostGraphQLRequest("{id date author{id} title content publiclyAvailable}");
PostSubscriptionCallback postSubscriptionCallback = new PostSubscriptionCallback();
Member author = new Member();
author.setId("12");
PostInput postInput = new PostInput();
postInput.setTopicId("22");
postInput.setInput(getTopicPostInput(author, "Some other content", new GregorianCalendar(2020, 11 - 1, 21).getTime(), false, "The good title for a post"));
// Go, go, go
System.out.println("Submitting the 'subscribeToNewPostWithBindValues' GraphQL subscription");
SubscriptionClient subscriptionClient = subscriptionTypeExecutor.subscribeToNewPost(subscriptionRequest, postSubscriptionCallback, "Board name 1");
// For this test, we need to be sure that the subscription is active, before creating the post (that we will
// receive a notification about). 3s: that's long, but my PC is so slow from time to time... :(
final int TIMEOUT1 = 3000;
for (int i = 0; i < TIMEOUT1 / 10; i += 1) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
throw new RuntimeException(e.getMessage(), e);
}
if (postSubscriptionCallback.connected) {
break;
}
}
// Let's check that everything is ready
if (!postSubscriptionCallback.connected) {
throw new RuntimeException("The subscription should be active");
}
System.out.println("Creating a post (for which we expect a notification) from this postInput: " + postInput.toString());
mutationTypeExecutor.createPost(createPostRequest, postInput);
// ////////////////////////////////////////////////////////////////////////////////////
// Let's check that we've received the expected notification, for this post creation
// Let's wait 10 seconds max for the post creation notification (from the subscription). We'll get interrupted
// before, as soon as we receive the notification
// (see the callback implementation in the PostSubscriptionCallback class)
Post notifiedPost = null;
// Let's wait 10s max, until the connection is active
final int TIMEOUT2 = 10;
for (int i = 0; i < TIMEOUT2 * 1000 / 10; i += 1) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
throw new RuntimeException(e.getMessage(), e);
}
if ((notifiedPost = postSubscriptionCallback.lastReceivedMessage) != null) {
// Ok, we're connected. We're done
break;
}
}
if (notifiedPost == null) {
throw new RuntimeException("The notification for the post creation was not received");
}
// We need to free the server resources, at the end
subscriptionClient.unsubscribe();
}
use of com.graphql_java_generator.samples.forum.client.graphql.forum.client.GraphQLRequest in project graphql-maven-plugin-project by graphql-java-generator.
the class FullRequestWithFragmentIT method setupAll.
@BeforeAll
static void setupAll() throws GraphQLRequestPreparationException {
// We have one GraphQL endpoint. So we use the static configuration.
GraphQLRequest.setStaticConfiguration(new GraphQLConfiguration(GRAPHQL_ENDPOINT_URL));
// Let's build once the request, and use it for each further execution
boardsRequestWithGlobalFragments = new GraphQLRequest(//
"" + "fragment member on Member {name alias} " + "fragment post on Post {date content author{...member id}}\n" + "fragment topic on Topic {title posts(since: &sinceParam){id ...post} author{...member}}\r" + "query{boards{id name topics {id ...topic}}}");
// The same request, with inline fragments
boardsRequestWithInlineFragments = new GraphQLRequest(//
"" + //
"query{boards{" + //
" id name topics {" + //
" id ... on Topic {" + //
" title " + //
" posts(since: &sinceParam){id ... on Post {date content author{... on Member {name alias} id}} } " + //
" author{... on Member {name alias}}" + //
" } " + //
" }" + "}}");
}
Aggregations