use of org.springframework.graphql.RequestOutput 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.RequestOutput in project spring-integration by spring-projects.
the class GraphQlMessageHandlerTests method testHandleMessageForQueryWithQueryProvided.
@Test
@SuppressWarnings("unchecked")
void testHandleMessageForQueryWithQueryProvided() {
String fakeQuery = "{ testQuery { id } }";
this.graphQlMessageHandler.setOperation(fakeQuery);
Locale locale = Locale.getDefault();
this.graphQlMessageHandler.setLocale(locale);
Mono<RequestOutput> resultMono = (Mono<RequestOutput>) this.graphQlMessageHandler.handleRequestMessage(new GenericMessage<>(fakeQuery));
StepVerifier.create(resultMono).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");
}).expectComplete().verify();
}
use of org.springframework.graphql.RequestOutput in project spring-graphql by spring-projects.
the class ClassNameTypeResolverTests method typeResolutionViaMapping.
@Test
void typeResolutionViaMapping() {
String document = "" + "query Sightings {" + " sightings {" + " __typename" + " ... on Bird {" + " name" + " }" + " ... on Mammal {" + " name" + " }" + " ... on Plant {" + " family" + " }" + " }" + "}";
ClassNameTypeResolver typeResolver = new ClassNameTypeResolver();
typeResolver.addMapping(Tree.class, "Plant");
Mono<RequestOutput> result = graphQlSetup.queryFetcher("sightings", env -> animalAndPlantList).typeResolver(typeResolver).toGraphQlService().execute(TestRequestInput.forDocument(document));
GraphQlResponse response = GraphQlResponse.from(result);
for (int i = 0; i < animalAndPlantList.size(); i++) {
Object sighting = animalAndPlantList.get(i);
if (sighting instanceof Animal) {
Animal animal = (Animal) response.toEntity("sightings[" + i + "]", sighting.getClass());
assertThat(animal.getName()).isEqualTo(((Animal) sighting).getName());
} else if (sighting instanceof Tree) {
Tree tree = (Tree) response.toEntity("sightings[" + i + "]", sighting.getClass());
assertThat(tree.getFamily()).isEqualTo(((Tree) sighting).getFamily());
} else {
throw new IllegalStateException();
}
}
}
use of org.springframework.graphql.RequestOutput in project spring-graphql by spring-projects.
the class ClassNameTypeResolverTests method typeResolutionViaSuperHierarchy.
@Test
void typeResolutionViaSuperHierarchy() {
String document = "" + "query Animals {" + " animals {" + " __typename" + " name" + " ... on Bird {" + " flightless" + " }" + " ... on Mammal {" + " herbivore" + " }" + " }" + "}";
Mono<RequestOutput> resultMono = graphQlSetup.queryFetcher("animals", env -> animalList).toGraphQlService().execute(TestRequestInput.forDocument(document));
GraphQlResponse response = GraphQlResponse.from(resultMono);
for (int i = 0; i < animalList.size(); i++) {
Animal animal = animalList.get(i);
if (animal instanceof Bird) {
Bird bird = (Bird) response.toEntity("animals[" + i + "]", animal.getClass());
assertThat(bird.isFlightless()).isEqualTo(((Bird) animal).isFlightless());
} else if (animal instanceof Mammal) {
Mammal mammal = (Mammal) response.toEntity("animals[" + i + "]", animal.getClass());
assertThat(mammal.isHerbivore()).isEqualTo(((Mammal) animal).isHerbivore());
} else {
throw new IllegalStateException();
}
}
}
use of org.springframework.graphql.RequestOutput in project spring-graphql by spring-projects.
the class SchemaMappingInvocationTests method queryWithScalarArgument.
@Test
void queryWithScalarArgument() {
String document = "{ " + " bookById(id:\"1\") { " + " id" + " name" + " author {" + " firstName" + " lastName" + " }" + " }" + "}";
Mono<RequestOutput> resultMono = graphQlService().execute(TestRequestInput.forDocument(document));
Book book = GraphQlResponse.from(resultMono).toEntity("bookById", Book.class);
assertThat(book.getId()).isEqualTo(1);
assertThat(book.getName()).isEqualTo("Nineteen Eighty-Four");
Author author = book.getAuthor();
assertThat(author.getFirstName()).isEqualTo("George");
assertThat(author.getLastName()).isEqualTo("Orwell");
}
Aggregations