public interface WebGraphQlTester extends GraphQlTester
via WebTestClient
or
via WebGraphQlHandler
. See the below for
examples with different scenarios.
GraphQL requests to Spring MVC without an HTTP server:
@SpringBootTest @AutoConfigureMockMvc @AutoConfigureGraphQlTester public class MyTests { @Autowired private WebGraphQlTester graphQlTester; }
GraphQL requests to Spring WebFlux without an HTTP server:
@SpringBootTest @AutoConfigureWebTestClient @AutoConfigureGraphQlTester public class MyTests { @Autowired private WebGraphQlTester graphQlTester; }
GraphQL requests to a running server:
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @AutoConfigureWebTestClient @AutoConfigureGraphQlTester public class MyTests { @Autowired private WebGraphQlTester graphQlTester; }
GraphQL requests handled directly through a WebGraphQlHandler
:
@SpringBootTest public class MyTests { private WebGraphQlTester graphQlTester; @BeforeEach public void setUp(@Autowired WebGraphQLHandler handler) { this.graphQlTester = GraphQlTester.create(handler); } }
Modifier and Type | Interface and Description |
---|---|
static interface |
WebGraphQlTester.Builder
A builder to create a
WebGraphQlTester instance. |
static interface |
WebGraphQlTester.WebRequestSpec
Extends
GraphQlTester.RequestSpec with further input options
applicable to Web requests. |
GraphQlTester.EntitySpec<D,S extends GraphQlTester.EntitySpec<D,S>>, GraphQlTester.ErrorSpec, GraphQlTester.ExecuteSpec, GraphQlTester.ListEntitySpec<E>, GraphQlTester.PathSpec, GraphQlTester.RequestSpec<T extends GraphQlTester.RequestSpec<T>>, GraphQlTester.ResponseSpec, GraphQlTester.SubscriptionSpec, GraphQlTester.TraverseSpec
Modifier and Type | Method and Description |
---|---|
static WebGraphQlTester.Builder |
builder(WebGraphQlHandler handler)
Return a builder with options to initialize a
WebGraphQlHandler . |
static WebGraphQlTester.Builder |
builder(WebTestClient client)
Return a builder with options to initialize a
WebGraphQlTester . |
static WebGraphQlTester |
create(WebGraphQlHandler handler)
Create a
WebGraphQlTester that performs GraphQL requests through
the given WebGraphQlHandler . |
static WebGraphQlTester |
create(WebTestClient client)
Create a
WebGraphQlTester that performs GraphQL requests as an
HTTP client through the given WebTestClient . |
WebGraphQlTester.WebRequestSpec |
query(String query)
Prepare to perform a GraphQL request with the given operation which may
be a query, mutation, or a subscription.
|
builder, create
WebGraphQlTester.WebRequestSpec query(String query)
The returned spec for Web request input also allows adding HTTP headers.
query
in interface GraphQlTester
query
- the operation to be performedstatic WebGraphQlTester create(WebTestClient client)
WebGraphQlTester
that performs GraphQL requests as an
HTTP client through the given WebTestClient
. Depending on how the
WebTestClient
is set up, tests may be with or without a server.
See setup examples in class-level Javadoc.client
- the web client to perform requests withWebGraphQlTester
static WebGraphQlTester create(WebGraphQlHandler handler)
WebGraphQlTester
that performs GraphQL requests through
the given WebGraphQlHandler
.handler
- the handler to execute requests withWebGraphQlTester
static WebGraphQlTester.Builder builder(WebTestClient client)
WebGraphQlTester
.client
- the client to execute requests withstatic WebGraphQlTester.Builder builder(WebGraphQlHandler handler)
WebGraphQlHandler
.handler
- the handler to execute requests with