use of org.springframework.graphql.GraphQlRequest in project spring-graphql by spring-projects.
the class GraphQlClientBuilderTests method mutateDocumentSource.
@Test
void mutateDocumentSource() {
DocumentSource documentSource = name -> name.equals("name") ? Mono.just(DOCUMENT) : Mono.error(new IllegalArgumentException());
setMockResponse("{}");
// Original
GraphQlClient.Builder<?> builder = graphQlClientBuilder().documentSource(documentSource);
GraphQlClient client = builder.build();
client.documentName("name").execute().block(TIMEOUT);
GraphQlRequest request = request();
assertThat(request.getDocument()).isEqualTo(DOCUMENT);
// Mutate
client = client.mutate().build();
client.documentName("name").execute().block(TIMEOUT);
assertThat(request().getDocument()).isEqualTo(DOCUMENT);
}
use of org.springframework.graphql.GraphQlRequest in project spring-graphql by spring-projects.
the class MockWebSocketGraphQlTransportTests method requestCancelled.
@Test
void requestCancelled() {
GraphQlRequest request = this.mockServer.expectOperation("{Query1}").andRespond(Mono.never());
StepVerifier.create(this.transport.execute(request)).thenAwait(Duration.ofMillis(200)).thenCancel().verify(TIMEOUT);
assertActualClientMessages(GraphQlMessage.connectionInit(null), GraphQlMessage.subscribe("1", request));
}
use of org.springframework.graphql.GraphQlRequest in project spring-graphql by spring-projects.
the class MockWebSocketGraphQlTransportTests method requestStreamError.
@Test
void requestStreamError() {
GraphQlRequest request = this.mockServer.expectOperation("{Sub1}").andStreamWithError(Flux.just(this.result1), GraphqlErrorBuilder.newError().message("boo").build());
StepVerifier.create(this.transport.executeSubscription(request)).expectNext(this.result1).expectErrorSatisfies(actualEx -> {
List<GraphQLError> errorList = ((SubscriptionErrorException) actualEx).getErrors();
assertThat(errorList).extracting(GraphQLError::getMessage).containsExactly("boo");
}).verify(TIMEOUT);
assertActualClientMessages(GraphQlMessage.connectionInit(null), GraphQlMessage.subscribe("1", request));
}
use of org.springframework.graphql.GraphQlRequest in project spring-graphql by spring-projects.
the class MockWebSocketGraphQlTransportTests method requestStreamCancelled.
@Test
void requestStreamCancelled() {
GraphQlRequest request = this.mockServer.expectOperation("{Sub1}").andStream(Flux.just(this.result1).concatWith(Flux.never()));
StepVerifier.create(this.transport.executeSubscription(request)).expectNext(this.result1).thenAwait(Duration.ofMillis(200)).thenCancel().verify(TIMEOUT);
assertActualClientMessages(GraphQlMessage.connectionInit(null), GraphQlMessage.subscribe("1", request), GraphQlMessage.complete("1"));
}
use of org.springframework.graphql.GraphQlRequest in project spring-graphql by spring-projects.
the class GraphQlClientTests method operationNameAndVariables.
@Test
void operationNameAndVariables() {
String document = "query HeroNameAndFriends($episode: Episode) {" + " hero(episode: $episode) {" + " name" + " }" + "}";
setMockResponse("{\"hero\": {\"name\":\"R2-D2\"}}");
GraphQlClient.Response response = graphQlClient().document(document).operationName("HeroNameAndFriends").variable("episode", "JEDI").variable("foo", "bar").variable("keyOnly", null).execute().block(TIMEOUT);
assertThat(response).isNotNull();
MovieCharacter character = response.toEntity("hero", MovieCharacter.class);
assertThat(character).isEqualTo(MovieCharacter.create("R2-D2"));
GraphQlRequest request = request();
assertThat(request.getDocument()).contains(document);
assertThat(request.getOperationName()).isEqualTo("HeroNameAndFriends");
assertThat(request.getVariables()).hasSize(3);
assertThat(request.getVariables()).containsEntry("episode", "JEDI");
assertThat(request.getVariables()).containsEntry("foo", "bar");
assertThat(request.getVariables()).containsEntry("keyOnly", null);
}
Aggregations