2626
2727import static java .util .Objects .nonNull ;
2828
29+ /**
30+ * Helper class to test GraphQL queries and mutations.
31+ */
2932public class GraphQLTestTemplate {
3033
3134 private final ResourceLoader resourceLoader ;
@@ -88,6 +91,7 @@ public void addHeader(final String name, final String value) {
8891 *
8992 * @param name Name (key) of HTTP header to add.
9093 * @param value Value(s) of HTTP header to add.
94+ * @return self
9195 */
9296 public GraphQLTestTemplate withAdditionalHeader (final String name , final String ... value ) {
9397 headers .addAll (name , Arrays .asList (value ));
@@ -98,6 +102,7 @@ public GraphQLTestTemplate withAdditionalHeader(final String name, final String.
98102 * Add multiple HTTP header that will be sent with each request this sends.
99103 *
100104 * @param additionalHeaders additional headers to add
105+ * @return self
101106 */
102107 public GraphQLTestTemplate withAdditionalHeaders (final MultiValueMap <String , String > additionalHeaders ) {
103108 headers .addAll (additionalHeaders );
@@ -166,6 +171,7 @@ public void setHeaders(HttpHeaders newHeaders) {
166171 * Replace any associated HTTP headers with the provided headers.
167172 *
168173 * @param newHeaders Headers to use.
174+ * @return self
169175 */
170176 public GraphQLTestTemplate withHeaders (final HttpHeaders newHeaders ) {
171177 return withClearHeaders ().withAdditionalHeaders (newHeaders );
@@ -190,34 +196,80 @@ public GraphQLTestTemplate withClearHeaders() {
190196 }
191197
192198 /**
199+ * Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL server.
200+ *
193201 * @deprecated Use {@link #postForResource(String)} instead
194202 *
195203 * @param graphqlResource path to the classpath resource containing the GraphQL query
196- * @return GraphQLResponse containing the result of query execution
204+ * @return {@link GraphQLResponse} containing the result of query execution
197205 * @throws IOException if the resource cannot be loaded from the classpath
198206 */
207+ @ Deprecated
199208 public GraphQLResponse perform (String graphqlResource ) throws IOException {
200209 return postForResource (graphqlResource );
201210 }
202211
212+ /**
213+ * Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL server.
214+ *
215+ * @param graphqlResource path to the classpath resource containing the GraphQL query
216+ * @param variables the input variables for the GraphQL query
217+ * @return {@link GraphQLResponse} containing the result of query execution
218+ * @throws IOException if the resource cannot be loaded from the classpath
219+ */
203220 public GraphQLResponse perform (String graphqlResource , ObjectNode variables ) throws IOException {
204221 return perform (graphqlResource , null , variables );
205222 }
206223
224+ /**
225+ * Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL server.
226+ *
227+ * @param graphqlResource path to the classpath resource containing the GraphQL query
228+ * @param operationName the name of the GraphQL operation to be executed
229+ * @return {@link GraphQLResponse} containing the result of query execution
230+ * @throws IOException if the resource cannot be loaded from the classpath
231+ */
207232 public GraphQLResponse perform (String graphqlResource , String operationName ) throws IOException {
208233 return perform (graphqlResource , operationName , null );
209234 }
210235
236+ /**
237+ * Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL server.
238+ *
239+ * @param graphqlResource path to the classpath resource containing the GraphQL query
240+ * @param operation the name of the GraphQL operation to be executed
241+ * @param variables the input variables for the GraphQL query
242+ * @return {@link GraphQLResponse} containing the result of query execution
243+ * @throws IOException if the resource cannot be loaded from the classpath
244+ */
211245 public GraphQLResponse perform (String graphqlResource , String operation , ObjectNode variables ) throws IOException {
212246 String graphql = loadQuery (graphqlResource );
213247 String payload = createJsonQuery (graphql , operation , variables );
214248 return post (payload );
215249 }
216250
251+ /**
252+ * Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL server.
253+ *
254+ * @param graphqlResource path to the classpath resource containing the GraphQL query
255+ * @param variables the input variables for the GraphQL query
256+ * @param fragmentResources an ordered list of classpath resources containing GraphQL fragment definitions.
257+ * @return {@link GraphQLResponse} containing the result of query execution
258+ * @throws IOException if the resource cannot be loaded from the classpath
259+ */
217260 public GraphQLResponse perform (String graphqlResource , ObjectNode variables , List <String > fragmentResources ) throws IOException {
218261 return perform (graphqlResource , null , variables , fragmentResources );
219262 }
220263
264+ /**
265+ * Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL server.
266+ *
267+ * @param graphqlResource path to the classpath resource containing the GraphQL query
268+ * @param variables the input variables for the GraphQL query
269+ * @param fragmentResources an ordered list of classpath resources containing GraphQL fragment definitions.
270+ * @return {@link GraphQLResponse} containing the result of query execution
271+ * @throws IOException if the resource cannot be loaded from the classpath
272+ */
221273 public GraphQLResponse perform (String graphqlResource , String operationName , ObjectNode variables , List <String > fragmentResources ) throws IOException {
222274 StringBuilder sb = new StringBuilder ();
223275 for (String fragmentResource : fragmentResources ) {
@@ -229,23 +281,23 @@ public GraphQLResponse perform(String graphqlResource, String operationName, Obj
229281 }
230282
231283 /**
232- * Loads a GraphQL query from the given classpath resource and sends it to the GraphQL server.
284+ * Loads a GraphQL query or mutation from the given classpath resource and sends it to the GraphQL server.
233285 *
234286 * @param graphqlResource path to the classpath resource containing the GraphQL query
235- * @return GraphQLResponse containing the result of query execution
287+ * @return {@link GraphQLResponse} containing the result of query execution
236288 * @throws IOException if the resource cannot be loaded from the classpath
237289 */
238290 public GraphQLResponse postForResource (String graphqlResource ) throws IOException {
239291 return perform (graphqlResource , (String ) null , null );
240292 }
241293
242294 /**
243- * Loads a GraphQL query from the given classpath resource, appending any graphql fragment
295+ * Loads a GraphQL query or mutation from the given classpath resource, appending any graphql fragment
244296 * resources provided and sends it to the GraphQL server.
245297 *
246298 * @param graphqlResource path to the classpath resource containing the GraphQL query
247- * @param fragmentResources an ordered list of classpaths containing GraphQL fragment definitions.
248- * @return GraphQLResponse containing the result of query execution
299+ * @param fragmentResources an ordered list of classpath resources containing GraphQL fragment definitions.
300+ * @return {@link GraphQLResponse} containing the result of query execution
249301 * @throws IOException if the resource cannot be loaded from the classpath
250302 */
251303 public GraphQLResponse postForResource (String graphqlResource , List <String > fragmentResources ) throws IOException {
0 commit comments