Search in sources :

Example 1 with DocumentSource

use of org.springframework.graphql.support.DocumentSource in project spring-graphql by spring-projects.

the class WebGraphQlClientBuilderTests method mutateDocumentSource.

@ParameterizedTest
@MethodSource("argumentSource")
void mutateDocumentSource(ClientBuilderSetup builderSetup) {
    DocumentSource documentSource = name -> name.equals("name") ? Mono.just(DOCUMENT) : Mono.error(new IllegalArgumentException());
    // Original
    WebGraphQlClient.Builder<?> builder = builderSetup.initBuilder().documentSource(documentSource);
    WebGraphQlClient client = builder.build();
    client.documentName("name").execute().block(TIMEOUT);
    WebInput input = builderSetup.getWebInput();
    assertThat(input.getDocument()).isEqualTo(DOCUMENT);
    // Mutate
    client = client.mutate().build();
    client.documentName("name").execute().block(TIMEOUT);
    input = builderSetup.getWebInput();
    assertThat(input.getDocument()).isEqualTo(DOCUMENT);
}
Also used : RouterFunctions(org.springframework.web.reactive.function.server.RouterFunctions) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DecodingException(org.springframework.core.codec.DecodingException) WebClient(org.springframework.web.reactive.function.client.WebClient) HashMap(java.util.HashMap) TestWebSocketClient(org.springframework.graphql.web.TestWebSocketClient) ExecutionResult(graphql.ExecutionResult) DocumentSource(org.springframework.graphql.support.DocumentSource) MimeType(org.springframework.util.MimeType) Duration(java.time.Duration) Map(java.util.Map) TestWebSocketConnection(org.springframework.graphql.web.TestWebSocketConnection) HttpHandlerConnector(org.springframework.test.web.reactive.server.HttpHandlerConnector) WebInterceptor(org.springframework.graphql.web.WebInterceptor) Nullable(org.springframework.lang.Nullable) WebSocketHandler(org.springframework.web.reactive.socket.WebSocketHandler) URI(java.net.URI) ResolvableType(org.springframework.core.ResolvableType) ExecutionResultImpl(graphql.ExecutionResultImpl) MethodSource(org.junit.jupiter.params.provider.MethodSource) RouterFunctions.route(org.springframework.web.reactive.function.server.RouterFunctions.route) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) WebGraphQlHandler(org.springframework.graphql.web.WebGraphQlHandler) Mono(reactor.core.publisher.Mono) DataBuffer(org.springframework.core.io.buffer.DataBuffer) HandlerStrategies(org.springframework.web.reactive.function.server.HandlerStrategies) ExecutionInput(graphql.ExecutionInput) Test(org.junit.jupiter.api.Test) ClientCodecConfigurer(org.springframework.http.codec.ClientCodecConfigurer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) WebInput(org.springframework.graphql.web.WebInput) HttpHandler(org.springframework.http.server.reactive.HttpHandler) RouterFunction(org.springframework.web.reactive.function.server.RouterFunction) ServerResponse(org.springframework.web.reactive.function.server.ServerResponse) GraphQlWebSocketHandler(org.springframework.graphql.web.webflux.GraphQlWebSocketHandler) Collections(java.util.Collections) RequestOutput(org.springframework.graphql.RequestOutput) GraphQlHttpHandler(org.springframework.graphql.web.webflux.GraphQlHttpHandler) Assert(org.springframework.util.Assert) DocumentSource(org.springframework.graphql.support.DocumentSource) WebInput(org.springframework.graphql.web.WebInput) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with DocumentSource

use of org.springframework.graphql.support.DocumentSource in project spring-graphql by spring-projects.

the class WebGraphQlTesterBuilderTests method mutateDocumentSource.

@ParameterizedTest
@MethodSource("argumentSource")
void mutateDocumentSource(TesterBuilderSetup builderSetup) {
    DocumentSource documentSource = name -> name.equals("name") ? Mono.just(DOCUMENT) : Mono.error(new IllegalArgumentException());
    // Original
    WebGraphQlTester.Builder<?> builder = builderSetup.initBuilder().documentSource(documentSource);
    WebGraphQlTester tester = builder.build();
    tester.documentName("name").execute();
    WebInput input = builderSetup.getWebInput();
    assertThat(input.getDocument()).isEqualTo(DOCUMENT);
    // Mutate
    tester = tester.mutate().build();
    tester.documentName("name").execute();
    input = builderSetup.getWebInput();
    assertThat(input.getDocument()).isEqualTo(DOCUMENT);
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DecodingException(org.springframework.core.codec.DecodingException) HashMap(java.util.HashMap) TestWebSocketClient(org.springframework.graphql.web.TestWebSocketClient) ExecutionResult(graphql.ExecutionResult) DocumentSource(org.springframework.graphql.support.DocumentSource) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) MimeType(org.springframework.util.MimeType) Duration(java.time.Duration) Map(java.util.Map) TestWebSocketConnection(org.springframework.graphql.web.TestWebSocketConnection) WebInterceptor(org.springframework.graphql.web.WebInterceptor) Nullable(org.springframework.lang.Nullable) WebSocketHandler(org.springframework.web.reactive.socket.WebSocketHandler) URI(java.net.URI) ResolvableType(org.springframework.core.ResolvableType) ExecutionResultImpl(graphql.ExecutionResultImpl) MethodSource(org.junit.jupiter.params.provider.MethodSource) RouterFunctions.route(org.springframework.web.reactive.function.server.RouterFunctions.route) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) WebGraphQlHandler(org.springframework.graphql.web.WebGraphQlHandler) Mono(reactor.core.publisher.Mono) DataBuffer(org.springframework.core.io.buffer.DataBuffer) ExecutionInput(graphql.ExecutionInput) Test(org.junit.jupiter.api.Test) ClientCodecConfigurer(org.springframework.http.codec.ClientCodecConfigurer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) WebInput(org.springframework.graphql.web.WebInput) RouterFunction(org.springframework.web.reactive.function.server.RouterFunction) ServerResponse(org.springframework.web.reactive.function.server.ServerResponse) GraphQlWebSocketHandler(org.springframework.graphql.web.webflux.GraphQlWebSocketHandler) Collections(java.util.Collections) RequestOutput(org.springframework.graphql.RequestOutput) GraphQlHttpHandler(org.springframework.graphql.web.webflux.GraphQlHttpHandler) Assert(org.springframework.util.Assert) DocumentSource(org.springframework.graphql.support.DocumentSource) WebInput(org.springframework.graphql.web.WebInput) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with DocumentSource

use of org.springframework.graphql.support.DocumentSource in project spring-graphql by spring-projects.

the class GraphQlClientBuilderTests method mutateDocumentSource.

@Test
void mutateDocumentSource() {
    DocumentSource documentSource = name -> name.equals("name") ? Mono.just(DOCUMENT) : Mono.error(new IllegalArgumentException());
    setMockResponse("{}");
    // Original
    GraphQlClient.Builder<?> builder = graphQlClientBuilder().documentSource(documentSource);
    GraphQlClient client = builder.build();
    client.documentName("name").execute().block(TIMEOUT);
    GraphQlRequest request = request();
    assertThat(request.getDocument()).isEqualTo(DOCUMENT);
    // Mutate
    client = client.mutate().build();
    client.documentName("name").execute().block(TIMEOUT);
    assertThat(request().getDocument()).isEqualTo(DOCUMENT);
}
Also used : Test(org.junit.jupiter.api.Test) DocumentSource(org.springframework.graphql.support.DocumentSource) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) GraphQlRequest(org.springframework.graphql.GraphQlRequest) Mono(reactor.core.publisher.Mono) DocumentSource(org.springframework.graphql.support.DocumentSource) GraphQlRequest(org.springframework.graphql.GraphQlRequest) Test(org.junit.jupiter.api.Test)

Example 4 with DocumentSource

use of org.springframework.graphql.support.DocumentSource in project spring-graphql by spring-projects.

the class GraphQlTesterBuilderTests method mutateDocumentSource.

@Test
void mutateDocumentSource() {
    DocumentSource documentSource = name -> name.equals("name") ? Mono.just(DOCUMENT) : Mono.error(new IllegalArgumentException());
    setMockResponse("{}");
    // Original
    GraphQlTester.Builder<?> builder = graphQlTesterBuilder().documentSource(documentSource);
    GraphQlTester tester = builder.build();
    tester.documentName("name").execute();
    assertThat(requestInput().getDocument()).isEqualTo(DOCUMENT);
    // Mutate
    tester = tester.mutate().build();
    tester.documentName("name").execute();
    assertThat(requestInput().getDocument()).isEqualTo(DOCUMENT);
}
Also used : Test(org.junit.jupiter.api.Test) DocumentSource(org.springframework.graphql.support.DocumentSource) GraphQlService(org.springframework.graphql.GraphQlService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) GraphqlErrorBuilder(graphql.GraphqlErrorBuilder) DocumentSource(org.springframework.graphql.support.DocumentSource) Test(org.junit.jupiter.api.Test)

Aggregations

Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Test (org.junit.jupiter.api.Test)4 DocumentSource (org.springframework.graphql.support.DocumentSource)4 Mono (reactor.core.publisher.Mono)4 ExecutionInput (graphql.ExecutionInput)2 ExecutionResult (graphql.ExecutionResult)2 ExecutionResultImpl (graphql.ExecutionResultImpl)2 URI (java.net.URI)2 Duration (java.time.Duration)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Stream (java.util.stream.Stream)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 ResolvableType (org.springframework.core.ResolvableType)2 DecodingException (org.springframework.core.codec.DecodingException)2 DataBuffer (org.springframework.core.io.buffer.DataBuffer)2 RequestOutput (org.springframework.graphql.RequestOutput)2 TestWebSocketClient (org.springframework.graphql.web.TestWebSocketClient)2