use of org.springframework.graphql.RequestOutput in project spring-graphql by spring-projects.
the class SchemaMappingInvocationTests method mutation.
@Test
void mutation() {
String document = "mutation { " + " addAuthor(firstName:\"James\", lastName:\"Joyce\") { " + " id" + " firstName" + " lastName" + " }" + "}";
Mono<RequestOutput> resultMono = graphQlService().execute(TestRequestInput.forDocument(document));
Author author = GraphQlResponse.from(resultMono).toEntity("addAuthor", Author.class);
assertThat(author.getId()).isEqualTo(99);
assertThat(author.getFirstName()).isEqualTo("James");
assertThat(author.getLastName()).isEqualTo("Joyce");
}
use of org.springframework.graphql.RequestOutput in project spring-graphql by spring-projects.
the class SchemaMappingInvocationTests method queryWithArgumentViaDataFetchingEnvironment.
@Test
void queryWithArgumentViaDataFetchingEnvironment() {
String document = "{ " + " authorById(id:\"101\") { " + " id" + " firstName" + " lastName" + " }" + "}";
AtomicReference<GraphQLContext> contextRef = new AtomicReference<>();
RequestInput requestInput = TestRequestInput.forDocument(document);
requestInput.configureExecutionInput((executionInput, builder) -> {
contextRef.set(executionInput.getGraphQLContext());
return executionInput;
});
Mono<RequestOutput> resultMono = graphQlService().execute(requestInput);
Author author = GraphQlResponse.from(resultMono).toEntity("authorById", Author.class);
assertThat(author.getId()).isEqualTo(101);
assertThat(author.getFirstName()).isEqualTo("George");
assertThat(author.getLastName()).isEqualTo("Orwell");
assertThat(contextRef.get().<String>get("key")).isEqualTo("value");
}
Aggregations