Merge branch '1.1.x'
This commit is contained in:
@@ -223,6 +223,17 @@ Once `ExecutionGraphQlServiceTester` is created, you can begin to
|
||||
<<testing.requests, execute requests>> using the same API, independent of the underlying
|
||||
transport.
|
||||
|
||||
`ExecutionGraphQlServiceTester.Builder` provides an option to customize `ExecutionInput` details:
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes"]
|
||||
----
|
||||
GraphQlService service = ... ;
|
||||
ExecutionGraphQlServiceTester tester = ExecutionGraphQlServiceTester.builder(service)
|
||||
.configureExecutionInput((executionInput, builder) -> builder.executionId(id).build())
|
||||
.build();
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[testing.webgraphqltester]]
|
||||
=== `WebGraphQlHandler`
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,9 +17,14 @@
|
||||
package org.springframework.graphql.test.tester;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import graphql.ExecutionInput;
|
||||
|
||||
import org.springframework.core.codec.Decoder;
|
||||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.graphql.ExecutionGraphQlService;
|
||||
@@ -40,6 +45,8 @@ final class DefaultExecutionGraphQlServiceTesterBuilder
|
||||
|
||||
private final ExecutionGraphQlService service;
|
||||
|
||||
private final List<BiFunction<ExecutionInput, ExecutionInput.Builder, ExecutionInput>> executionInputConfigurers;
|
||||
|
||||
@Nullable
|
||||
private Encoder<?> encoder;
|
||||
|
||||
@@ -50,10 +57,20 @@ final class DefaultExecutionGraphQlServiceTesterBuilder
|
||||
DefaultExecutionGraphQlServiceTesterBuilder(ExecutionGraphQlService service) {
|
||||
Assert.notNull(service, "GraphQlService is required");
|
||||
this.service = service;
|
||||
this.executionInputConfigurers = new ArrayList<>();
|
||||
}
|
||||
|
||||
DefaultExecutionGraphQlServiceTesterBuilder(GraphQlServiceGraphQlTransport transport) {
|
||||
this.service = transport.getGraphQlService();
|
||||
this.executionInputConfigurers = new ArrayList<>(transport.getExecutionInputConfigurers());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultExecutionGraphQlServiceTesterBuilder configureExecutionInput(
|
||||
BiFunction<ExecutionInput, ExecutionInput.Builder, ExecutionInput> configurer) {
|
||||
|
||||
this.executionInputConfigurers.add(configurer);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,7 +88,7 @@ final class DefaultExecutionGraphQlServiceTesterBuilder
|
||||
@Override
|
||||
public ExecutionGraphQlServiceTester build() {
|
||||
registerJsonPathMappingProvider();
|
||||
GraphQlServiceGraphQlTransport transport = new GraphQlServiceGraphQlTransport(this.service);
|
||||
GraphQlServiceGraphQlTransport transport = createTransport();
|
||||
GraphQlTester tester = super.buildGraphQlTester(transport);
|
||||
return new DefaultExecutionGraphQlServiceTester(tester, transport, getBuilderInitializer());
|
||||
}
|
||||
@@ -86,6 +103,10 @@ final class DefaultExecutionGraphQlServiceTesterBuilder
|
||||
}
|
||||
}
|
||||
|
||||
private GraphQlServiceGraphQlTransport createTransport() {
|
||||
return new GraphQlServiceGraphQlTransport(this.service, this.executionInputConfigurers);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default {@link ExecutionGraphQlServiceTester} implementation.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
package org.springframework.graphql.test.tester;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import graphql.ExecutionInput;
|
||||
|
||||
import org.springframework.core.codec.Decoder;
|
||||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.graphql.ExecutionGraphQlService;
|
||||
@@ -54,6 +58,14 @@ public interface ExecutionGraphQlServiceTester extends GraphQlTester {
|
||||
*/
|
||||
interface Builder<B extends Builder<B>> extends GraphQlTester.Builder<B> {
|
||||
|
||||
/**
|
||||
* Provide a {@code BiFunction} to help initialize the
|
||||
* {@link ExecutionInput} with.
|
||||
* @since 1.1.2
|
||||
* @see org.springframework.graphql.ExecutionGraphQlRequest#configureExecutionInput(BiFunction)
|
||||
*/
|
||||
B configureExecutionInput(BiFunction<ExecutionInput, ExecutionInput.Builder, ExecutionInput> configurer);
|
||||
|
||||
/**
|
||||
* Configure the JSON encoder to use for mapping response data to
|
||||
* higher level objects.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,11 @@
|
||||
package org.springframework.graphql.test.tester;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import graphql.ExecutionInput;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.graphql.ExecutionGraphQlRequest;
|
||||
@@ -35,10 +40,16 @@ final class GraphQlServiceGraphQlTransport extends AbstractDirectGraphQlTranspor
|
||||
|
||||
private final ExecutionGraphQlService graphQlService;
|
||||
|
||||
private final List<BiFunction<ExecutionInput, ExecutionInput.Builder, ExecutionInput>> executionInputConfigurers;
|
||||
|
||||
|
||||
GraphQlServiceGraphQlTransport(
|
||||
ExecutionGraphQlService graphQlService,
|
||||
List<BiFunction<ExecutionInput, ExecutionInput.Builder, ExecutionInput>> executionInputConfigurers) {
|
||||
|
||||
GraphQlServiceGraphQlTransport(ExecutionGraphQlService graphQlService) {
|
||||
Assert.notNull(graphQlService, "GraphQlService is required");
|
||||
this.graphQlService = graphQlService;
|
||||
this.executionInputConfigurers = new ArrayList<>(executionInputConfigurers);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +57,13 @@ final class GraphQlServiceGraphQlTransport extends AbstractDirectGraphQlTranspor
|
||||
return this.graphQlService;
|
||||
}
|
||||
|
||||
public List<BiFunction<ExecutionInput, ExecutionInput.Builder, ExecutionInput>> getExecutionInputConfigurers() {
|
||||
return this.executionInputConfigurers;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mono<ExecutionGraphQlResponse> executeInternal(ExecutionGraphQlRequest request) {
|
||||
this.executionInputConfigurers.forEach(request::configureExecutionInput);
|
||||
return this.graphQlService.execute(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,12 +21,14 @@ import java.util.Map;
|
||||
|
||||
import graphql.ExecutionResultImpl;
|
||||
import graphql.GraphqlErrorBuilder;
|
||||
import graphql.execution.ExecutionId;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.codec.DecodingException;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.graphql.ExecutionGraphQlRequest;
|
||||
import org.springframework.graphql.ExecutionGraphQlService;
|
||||
import org.springframework.graphql.support.DocumentSource;
|
||||
import org.springframework.http.codec.json.Jackson2JsonDecoder;
|
||||
@@ -63,17 +65,27 @@ public class GraphQlTesterBuilderTests extends GraphQlTesterTestSupport {
|
||||
getGraphQlService().setDataAsJson(DOCUMENT, "{}");
|
||||
|
||||
// Original
|
||||
GraphQlTester.Builder<?> builder = graphQlTesterBuilder().documentSource(documentSource);
|
||||
GraphQlTester tester = builder.build();
|
||||
ExecutionGraphQlServiceTester tester = graphQlTesterBuilder()
|
||||
.documentSource(documentSource)
|
||||
.configureExecutionInput((executionInput, builder) -> builder.operationName("A").build())
|
||||
.build();
|
||||
tester.documentName("name").execute();
|
||||
|
||||
assertThat(getActualRequestDocument()).isEqualTo(DOCUMENT);
|
||||
ExecutionGraphQlRequest request = getGraphQlService().getGraphQlRequest();
|
||||
assertThat(request.toExecutionInput().getOperationName()).isEqualTo("A");
|
||||
assertThat(request.getDocument()).isEqualTo(DOCUMENT);
|
||||
|
||||
// Mutate
|
||||
tester = tester.mutate().build();
|
||||
ExecutionId id = ExecutionId.from("123");
|
||||
tester = tester.mutate()
|
||||
.configureExecutionInput((executionInput, builder) -> builder.executionId(id).build())
|
||||
.build();
|
||||
tester.documentName("name").execute();
|
||||
|
||||
assertThat(getActualRequestDocument()).isEqualTo(DOCUMENT);
|
||||
request = getGraphQlService().getGraphQlRequest();
|
||||
assertThat(request.toExecutionInput().getOperationName()).isEqualTo("A");
|
||||
assertThat(request.toExecutionInput().getExecutionId()).isEqualTo(id);
|
||||
assertThat(request.getDocument()).isEqualTo(DOCUMENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user