How to write integration test using graphqlTestTemplate for a mutation with one input and a file of Upload type

72 views Asked by At

here is my mutation

saveDoc(docInput: DocInput!, fileUpload: Upload!): Doc

below is what i am trying

 String query = "saveDoc.graphql";
 ObjectNode variables = mapper.createObjectNode();
 variables.put("input", SpringJacksonResourceReader.read("test_data/documentinput.json",ObjectNode.class));

variables.put("file",resourceLoader.getResource("classpath:test_data/xyz.pdf")
                .getContentAsByteArray());
GraphQLResponse response = graphQLTestTemplate.perform(query,variables);

and i am getting below error

Variable 'file' has an invalid value: Expected type jakarta.servlet.http.Part but was java.lang.String"

1

There are 1 answers

0
Brian Clozel On

Spring GraphQL does not support file uploads by default. Instead, you should probably create a regular web controller for uploading files out of band and referring to them in the GraphQL API.

There is a dedicated section about file upload in the Spring for GraphQL reference documentation.