Search in sources :

Example 11 with RequestOutput

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");
}
Also used : RequestOutput(org.springframework.graphql.RequestOutput) Author(org.springframework.graphql.Author) Test(org.junit.jupiter.api.Test)

Example 12 with RequestOutput

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");
}
Also used : RequestOutput(org.springframework.graphql.RequestOutput) GraphQLContext(graphql.GraphQLContext) Author(org.springframework.graphql.Author) AtomicReference(java.util.concurrent.atomic.AtomicReference) RequestInput(org.springframework.graphql.RequestInput) TestRequestInput(org.springframework.graphql.TestRequestInput) Test(org.junit.jupiter.api.Test)

Aggregations

RequestOutput (org.springframework.graphql.RequestOutput)12 Test (org.junit.jupiter.api.Test)9 Mono (reactor.core.publisher.Mono)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Author (org.springframework.graphql.Author)4 GraphQlResponse (org.springframework.graphql.GraphQlResponse)4 TestRequestInput (org.springframework.graphql.TestRequestInput)4 ExecutionInput (graphql.ExecutionInput)3 Map (java.util.Map)3 GraphQlSetup (org.springframework.graphql.GraphQlSetup)3 Flux (reactor.core.publisher.Flux)3 ExecutionResult (graphql.ExecutionResult)2 ExecutionResultImpl (graphql.ExecutionResultImpl)2 Duration (java.time.Duration)2 List (java.util.List)2 Locale (java.util.Locale)2 Book (org.springframework.graphql.Book)2 GraphQlService (org.springframework.graphql.GraphQlService)2 QueryMapping (org.springframework.graphql.data.method.annotation.QueryMapping)2 SubscriptionMapping (org.springframework.graphql.data.method.annotation.SubscriptionMapping)2