use of org.springframework.graphql.RequestInput in project spring-integration by spring-projects.
the class GraphQlMessageHandler method handleRequestMessage.
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
RequestInput requestInput;
if (requestMessage.getPayload() instanceof RequestInput) {
requestInput = (RequestInput) requestMessage.getPayload();
} else {
Assert.notNull(this.operationExpression, "'operationExpression' must not be null");
String query = evaluateOperationExpression(requestMessage);
String operationName = evaluateOperationNameExpression(requestMessage);
Map<String, Object> variables = evaluateVariablesExpression(requestMessage);
String id = evaluateExecutionIdExpression(requestMessage);
requestInput = new RequestInput(query, operationName, variables, this.locale, id);
}
return this.graphQlService.execute(requestInput);
}
use of org.springframework.graphql.RequestInput in project spring-integration by spring-projects.
the class GraphQlMessageHandlerTests method testHandleMessageForSubscriptionWithRequestInputProvided.
@Test
@SuppressWarnings("unchecked")
void testHandleMessageForSubscriptionWithRequestInputProvided() {
StepVerifier verifier = StepVerifier.create(Flux.from(this.resultChannel).map(Message::getPayload).cast(RequestOutput.class).mapNotNull(RequestOutput::getData).cast(SubscriptionPublisher.class).map(Flux::from).flatMap(data -> data)).consumeNextWith(requestOutput -> {
Map<String, Object> results = requestOutput.getData();
assertThat(results).containsKey("results");
Map<String, Object> operationResult = (Map<String, Object>) results.get("results");
assertThat(operationResult).containsKey("id").containsValue("test-data-01");
}).expectNextCount(9).thenCancel().verifyLater();
RequestInput payload = new RequestInput("subscription { results { id } }", null, null, null, UUID.randomUUID().toString());
this.inputChannel.send(MessageBuilder.withPayload(payload).build());
verifier.verify(Duration.ofSeconds(10));
}
use of org.springframework.graphql.RequestInput in project spring-integration by spring-projects.
the class GraphQlMessageHandlerTests method testHandleMessageForQueryWithRequestInputProvided.
@Test
@SuppressWarnings("unchecked")
void testHandleMessageForQueryWithRequestInputProvided() {
StepVerifier verifier = StepVerifier.create(Flux.from(this.resultChannel).map(Message::getPayload).cast(RequestOutput.class)).consumeNextWith(result -> {
assertThat(result).isInstanceOf(RequestOutput.class);
Map<String, Object> data = result.getData();
Map<String, Object> testQuery = (Map<String, Object>) data.get("testQuery");
assertThat(testQuery.get("id")).isEqualTo("test-data");
}).thenCancel().verifyLater();
RequestInput payload = new RequestInput("{ testQuery { id } }", null, null, null, UUID.randomUUID().toString());
this.inputChannel.send(MessageBuilder.withPayload(payload).build());
verifier.verify(Duration.ofSeconds(10));
}
use of org.springframework.graphql.RequestInput in project spring-integration by spring-projects.
the class GraphQlMessageHandlerTests method testHandleMessageForMutationWithRequestInputProvided.
@Test
@SuppressWarnings("unchecked")
void testHandleMessageForMutationWithRequestInputProvided() {
String fakeId = UUID.randomUUID().toString();
Update expected = new Update(fakeId);
StepVerifier verifier = StepVerifier.create(Flux.from(this.resultChannel).map(Message::getPayload).cast(RequestOutput.class)).consumeNextWith(result -> {
assertThat(result).isInstanceOf(RequestOutput.class);
Map<String, Object> data = result.getData();
Map<String, Object> update = (Map<String, Object>) data.get("update");
assertThat(update.get("id")).isEqualTo(fakeId);
assertThat(this.updateRepository.current().block()).isEqualTo(expected);
}).thenCancel().verifyLater();
RequestInput payload = new RequestInput("mutation { update(id: \"" + fakeId + "\") { id } }", null, null, null, UUID.randomUUID().toString());
this.inputChannel.send(MessageBuilder.withPayload(payload).build());
verifier.verify(Duration.ofSeconds(10));
StepVerifier.create(this.updateRepository.current()).expectNext(expected).expectComplete().verify();
}
use of org.springframework.graphql.RequestInput in project spring-graphql by spring-projects.
the class GraphQlTesterTests method operationNameAndVariables.
@Test
void operationNameAndVariables() {
String document = "query HeroNameAndFriends($episode: Episode) {" + " hero(episode: $episode) {" + " name" + " }" + "}";
setMockResponse("{\"hero\": {\"name\":\"R2-D2\"}}");
GraphQlTester.Response response = graphQlTester().document(document).operationName("HeroNameAndFriends").variable("episode", "JEDI").variable("foo", "bar").variable("keyOnly", null).execute();
response.path("hero").entity(MovieCharacter.class).isEqualTo(MovieCharacter.create("R2-D2"));
RequestInput input = requestInput();
assertThat(input.getDocument()).contains(document);
assertThat(input.getOperationName()).isEqualTo("HeroNameAndFriends");
assertThat(input.getVariables()).hasSize(3);
assertThat(input.getVariables()).containsEntry("episode", "JEDI");
assertThat(input.getVariables()).containsEntry("foo", "bar");
assertThat(input.getVariables()).containsEntry("keyOnly", null);
}
Aggregations