public class GraphQLTestTemplate
extends java.lang.Object
| Constructor and Description |
|---|
GraphQLTestTemplate(org.springframework.core.io.ResourceLoader resourceLoader,
org.springframework.boot.test.web.client.TestRestTemplate restTemplate,
java.lang.String graphqlMapping,
com.fasterxml.jackson.databind.ObjectMapper objectMapper) |
| Modifier and Type | Method and Description |
|---|---|
GraphQLResponse |
perform(java.lang.String graphqlResource,
com.fasterxml.jackson.databind.node.ObjectNode variables)
Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL
server.
|
GraphQLResponse |
perform(java.lang.String graphqlResource,
com.fasterxml.jackson.databind.node.ObjectNode variables,
java.util.List<java.lang.String> fragmentResources)
Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL
server.
|
GraphQLResponse |
perform(java.lang.String graphqlResource,
java.lang.String operationName)
Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL
server.
|
GraphQLResponse |
perform(java.lang.String graphqlResource,
java.lang.String operation,
com.fasterxml.jackson.databind.node.ObjectNode variables)
Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL
server.
|
GraphQLResponse |
perform(java.lang.String graphqlResource,
java.lang.String operationName,
com.fasterxml.jackson.databind.node.ObjectNode variables,
java.util.List<java.lang.String> fragmentResources)
Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL
server.
|
GraphQLResponse |
post(java.lang.String payload)
Performs a GraphQL request with the provided payload.
|
GraphQLResponse |
postFiles(java.lang.String graphqlResource,
com.fasterxml.jackson.databind.node.ObjectNode variables,
java.util.List<org.springframework.core.io.ClassPathResource> files)
Handle the multipart files upload request to GraphQL servlet
|
GraphQLResponse |
postFiles(java.lang.String graphqlResource,
com.fasterxml.jackson.databind.node.ObjectNode variables,
java.util.List<org.springframework.core.io.ClassPathResource> files,
java.util.function.IntFunction<java.lang.String> pathFunc)
Handle the multipart files upload request to GraphQL servlet
|
GraphQLResponse |
postForResource(java.lang.String graphqlResource)
Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL
server.
|
GraphQLResponse |
postForResource(java.lang.String graphqlResource,
java.util.List<java.lang.String> fragmentResources)
Loads a GraphQL query or mutation from the given classpath resource, appending any graphql
fragment resources provided and sends it to the GraphQL server.
|
GraphQLResponse |
postForString(java.lang.String graphql)
Performs a GraphQL request using the provided GraphQL query string.
|
GraphQLResponse |
postForString(java.lang.String graphql,
java.util.Map<java.lang.String,?> variables)
Performs a GraphQL request using the provided GraphQL query string and variables.
|
GraphQLResponse |
postForString(java.lang.String graphql,
com.fasterxml.jackson.databind.node.ObjectNode variables)
Performs a GraphQL request using the provided GraphQL query string and variables.
|
GraphQLResponse |
postForString(java.lang.String graphql,
java.lang.String operation)
Performs a GraphQL request using the provided GraphQL query string and operation name.
|
GraphQLResponse |
postForString(java.lang.String graphql,
java.lang.String operation,
java.util.Map<java.lang.String,?> variables)
Performs a GraphQL request using the provided GraphQL query string, operation name, and
variables.
|
GraphQLResponse |
postForString(java.lang.String graphql,
java.lang.String operation,
com.fasterxml.jackson.databind.node.ObjectNode variables)
Performs a GraphQL request using the provided GraphQL query string, operation name, and
variables.
|
GraphQLResponse |
postMultipart(java.lang.String query,
java.lang.String variables) |
GraphQLTestTemplate |
withAdditionalHeader(java.lang.String name,
java.lang.String... value)
Add an HTTP header that will be sent with each request this sends.
|
GraphQLTestTemplate |
withAdditionalHeaders(org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> additionalHeaders)
Add multiple HTTP header that will be sent with each request this sends.
|
GraphQLTestTemplate |
withBasicAuth(@NonNull java.lang.String encodedCredentials)
Adds basic authentication to the authorization header.
|
GraphQLTestTemplate |
withBasicAuth(@NonNull java.lang.String username,
@NonNull java.lang.String password)
Adds basic authentication to the authorization header.
|
GraphQLTestTemplate |
withBasicAuth(@NonNull java.lang.String username,
@NonNull java.lang.String password,
java.nio.charset.Charset charset)
Adds basic authentication to the authorization header.
|
GraphQLTestTemplate |
withBearerAuth(@NonNull java.lang.String token)
Adds a bearer token to the authorization header.
|
GraphQLTestTemplate |
withClearHeaders()
Clear all associated HTTP headers.
|
GraphQLTestTemplate |
withHeaders(org.springframework.http.HttpHeaders newHeaders)
Replace any associated HTTP headers with the provided headers.
|
public GraphQLTestTemplate(org.springframework.core.io.ResourceLoader resourceLoader,
org.springframework.boot.test.web.client.TestRestTemplate restTemplate,
@Value(value="${graphql.servlet.mapping:/graphql}")
java.lang.String graphqlMapping,
com.fasterxml.jackson.databind.ObjectMapper objectMapper)
public GraphQLTestTemplate withAdditionalHeader(java.lang.String name, java.lang.String... value)
name - Name (key) of HTTP header to add.value - Value(s) of HTTP header to add.public GraphQLTestTemplate withAdditionalHeaders(org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> additionalHeaders)
additionalHeaders - additional headers to addpublic GraphQLTestTemplate withBearerAuth(@NonNull @NonNull java.lang.String token)
token - the bearer tokenpublic GraphQLTestTemplate withBasicAuth(@NonNull @NonNull java.lang.String username, @NonNull @NonNull java.lang.String password, @Nullable java.nio.charset.Charset charset)
username - the usernamepassword - the passwordcharset - the charset used by the credentialspublic GraphQLTestTemplate withBasicAuth(@NonNull @NonNull java.lang.String username, @NonNull @NonNull java.lang.String password)
username - the usernamepassword - the passwordpublic GraphQLTestTemplate withBasicAuth(@NonNull @NonNull java.lang.String encodedCredentials)
encodedCredentials - the encoded credentialspublic GraphQLTestTemplate withHeaders(org.springframework.http.HttpHeaders newHeaders)
newHeaders - Headers to use.public GraphQLTestTemplate withClearHeaders()
public GraphQLResponse perform(java.lang.String graphqlResource, com.fasterxml.jackson.databind.node.ObjectNode variables) throws java.io.IOException
graphqlResource - path to the classpath resource containing the GraphQL queryvariables - the input variables for the GraphQL queryGraphQLResponse containing the result of query executionjava.io.IOException - if the resource cannot be loaded from the classpathpublic GraphQLResponse perform(java.lang.String graphqlResource, java.lang.String operationName) throws java.io.IOException
graphqlResource - path to the classpath resource containing the GraphQL queryoperationName - the name of the GraphQL operation to be executedGraphQLResponse containing the result of query executionjava.io.IOException - if the resource cannot be loaded from the classpathpublic GraphQLResponse perform(java.lang.String graphqlResource, java.lang.String operation, com.fasterxml.jackson.databind.node.ObjectNode variables) throws java.io.IOException
graphqlResource - path to the classpath resource containing the GraphQL queryoperation - the name of the GraphQL operation to be executedvariables - the input variables for the GraphQL queryGraphQLResponse containing the result of query executionjava.io.IOException - if the resource cannot be loaded from the classpathpublic GraphQLResponse perform(java.lang.String graphqlResource, com.fasterxml.jackson.databind.node.ObjectNode variables, java.util.List<java.lang.String> fragmentResources) throws java.io.IOException
graphqlResource - path to the classpath resource containing the GraphQL queryvariables - the input variables for the GraphQL queryfragmentResources - an ordered list of classpath resources containing GraphQL fragment
definitions.GraphQLResponse containing the result of query executionjava.io.IOException - if the resource cannot be loaded from the classpathpublic GraphQLResponse perform(java.lang.String graphqlResource, java.lang.String operationName, com.fasterxml.jackson.databind.node.ObjectNode variables, java.util.List<java.lang.String> fragmentResources) throws java.io.IOException
graphqlResource - path to the classpath resource containing the GraphQL queryvariables - the input variables for the GraphQL queryfragmentResources - an ordered list of classpath resources containing GraphQL fragment
definitions.GraphQLResponse containing the result of query executionjava.io.IOException - if the resource cannot be loaded from the classpathpublic GraphQLResponse postForResource(java.lang.String graphqlResource) throws java.io.IOException
graphqlResource - path to the classpath resource containing the GraphQL queryGraphQLResponse containing the result of query executionjava.io.IOException - if the resource cannot be loaded from the classpathpublic GraphQLResponse postForResource(java.lang.String graphqlResource, java.util.List<java.lang.String> fragmentResources) throws java.io.IOException
graphqlResource - path to the classpath resource containing the GraphQL queryfragmentResources - an ordered list of classpath resources containing GraphQL fragment
definitions.GraphQLResponse containing the result of query executionjava.io.IOException - if the resource cannot be loaded from the classpathpublic GraphQLResponse postMultipart(java.lang.String query, java.lang.String variables)
public GraphQLResponse postFiles(java.lang.String graphqlResource, com.fasterxml.jackson.databind.node.ObjectNode variables, java.util.List<org.springframework.core.io.ClassPathResource> files) throws java.io.IOException
In contrast with usual the GraphQL request with body as json payload (consist of query, operationName and variables), multipart file upload request will use multipart/form-data body with the following structure:
Example uploading two files:
* Please note that we can't embed binary data into json. Clients library supporting graphql file upload will set variable.files to null for every element inside the array, but each file will be a part of multipart request. GraphQL Servlet will use map part to walk through variables.files and validate the request in combination with other binary file parts
----------------------------dummyid
Content-Disposition: form-data; name="operations"
{ "query": "mutation($files:[Upload]!) {uploadFiles(files:$files)}", "operationName": "uploadFiles", "variables": { "files": [null, null] } }
----------------------------dummyid
Content-Disposition: form-data; name="map"
map: { "1":["variables.files.0"], "2":["variables.files.1"] }
----------------------------dummyid
Content-Disposition: form-data; name="1"; filename="file1.pdf"
Content-Type: application/octet-stream
--file 1 binary code--
----------------------------dummyid
Content-Disposition: form-data; name="2"; filename="file2.pdf"
Content-Type: application/octet-stream
2: --file 2 binary code--
graphqlResource - path to the classpath resource containing the GraphQL queryvariables - the input variables for the GraphQL queryfiles - ClassPathResource instance for each file that will be uploaded to GraphQL server.
When Spring RestTemplate processes the request, it will automatically produce a valid part
representing given file inside multipart request (including size, submittedFileName, etc.)GraphQLResponse containing the result of query executionjava.io.IOException - if the resource cannot be loaded from the classpathpublic GraphQLResponse postFiles(java.lang.String graphqlResource, com.fasterxml.jackson.databind.node.ObjectNode variables, java.util.List<org.springframework.core.io.ClassPathResource> files, java.util.function.IntFunction<java.lang.String> pathFunc) throws java.io.IOException
graphqlResource - path to the classpath resource containing the GraphQL queryvariables - the input variables for the GraphQL queryfiles - ClassPathResource instance for each file that will be uploaded to GraphQL server.
When Spring RestTemplate processes the request, it will automatically produce a valid part
representing given file inside multipart request (including size, submittedFileName, etc.)pathFunc - function to generate the path to file inside variables. For example:
GraphQLResponse containing the result of query executionjava.io.IOException - if the resource cannot be loaded from the classpathpublic GraphQLResponse postForString(java.lang.String graphql) throws java.io.IOException
graphql - the GraphQL queryGraphQLResponse containing the result of the query executionjava.io.IOException - if the request json cannot be created because of issues with one of the
provided argumentspublic GraphQLResponse postForString(java.lang.String graphql, java.lang.String operation) throws java.io.IOException
graphql - the GraphQL queryoperation - the name of the GraphQL operation to be executedGraphQLResponse containing the result of the query executionjava.io.IOException - if the request json cannot be created because of issues with one of the
provided argumentspublic GraphQLResponse postForString(java.lang.String graphql, java.util.Map<java.lang.String,?> variables) throws java.io.IOException
graphql - the GraphQL queryvariables - the input variables for the GraphQL queryGraphQLResponse containing the result of the query executionjava.io.IOException - if the request json cannot be created because of issues with one of the
provided argumentspublic GraphQLResponse postForString(java.lang.String graphql, java.lang.String operation, java.util.Map<java.lang.String,?> variables) throws java.io.IOException
graphql - the GraphQL queryoperation - the name of the GraphQL operation to be executedvariables - the input variables for the GraphQL queryGraphQLResponse containing the result of the query executionjava.io.IOException - if the request json cannot be created because of issues with one of the
provided argumentspublic GraphQLResponse postForString(java.lang.String graphql, com.fasterxml.jackson.databind.node.ObjectNode variables) throws java.io.IOException
graphql - the GraphQL queryvariables - the input variables for the GraphQL queryGraphQLResponse containing the result of the query executionjava.io.IOException - if the request json cannot be created because of issues with one of the
provided argumentspublic GraphQLResponse postForString(java.lang.String graphql, java.lang.String operation, com.fasterxml.jackson.databind.node.ObjectNode variables) throws java.io.IOException
graphql - the GraphQL queryoperation - the name of the GraphQL operation to be executedvariables - the input variables for the GraphQL queryGraphQLResponse containing the result of the query executionjava.io.IOException - if the request json cannot be created because of issues with one of the
provided argumentspublic GraphQLResponse post(java.lang.String payload)
payload - the GraphQL payloadGraphQLResponse containing the result of query execution