graphql-java-kickstart/samples

How to test fileUpload and subscription with GraphQLTestTemplate

hantsy opened this issue · 3 comments

The GraphQLTestTemplate is great to test general query and mutation, but when I tried to test file upload, not sure how to add a Part object to the request.

The postMultipart accept a json string, there is a serialization error when running the following test.

    @SneakyThrows
    @Test
    public void uploadFile() {
        var part = """
                 {
                      "query": "mutation upload($file:Upload!){
                           upload(file:file)
                      }"
                 }
                """;
        var variables = Map.of("file", new MockPart("test", "test.txt", "test content".getBytes()));
        GraphQLResponse response = testTemplate.postMultipart(part, objectMapper.writeValueAsString(variables));
        assertNotNull(response);
        assertThat(response.isOk()).isTrue();
        assertThat(response.get("$.data.upload", Boolean.class)).isTrue();
    }

BTW, how to subscribe the subscription event via GraphQLTestTemplate?

Hi @hantsy , I'm closing this issue because the graphql-java-kickstart/graphql-spring-boot has been archived and it is no longer maintained. We encourage you to start using Spring for GraphQL instead.

Thanks for opening this issue

hantsy commented

@federicorispo But there is no official fileUpload support in the Spring for GraphQL project.

@hantsy I know that the spring-graphql team decided to not support the fileUpload operation to avoid having unnecesary complexity. However, the spring-graphql project is better maintained and followed by a large community than the graphql-spring-boot one and a lot of developers decided to migrate to spring-graphql for these reasons.

The only missing piece in spring-graphql is the fileUpload that it can be mitigated using this dependency written by @nkonev

<dependency>
  <groupId>name.nkonev.multipart-spring-graphql</groupId>
  <artifactId>multipart-spring-graphql</artifactId>
</dependency>

or exposing the upload operation via REST API that, in my opinion, gives more flexibility.