Search in sources :

Example 6 with RequestInput

use of org.springframework.graphql.RequestInput 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

RequestInput (org.springframework.graphql.RequestInput)6 Test (org.junit.jupiter.api.Test)5 Map (java.util.Map)3 StepVerifier (reactor.test.StepVerifier)3 RequestOutput (org.springframework.graphql.RequestOutput)2 GraphQLContext (graphql.GraphQLContext)1 SubscriptionPublisher (graphql.execution.reactive.SubscriptionPublisher)1 Duration (java.time.Duration)1 Locale (java.util.Locale)1 UUID (java.util.UUID)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Author (org.springframework.graphql.Author)1 GraphQlService (org.springframework.graphql.GraphQlService)1 TestRequestInput (org.springframework.graphql.TestRequestInput)1 Argument (org.springframework.graphql.data.method.annotation.Argument)1