Skip to content

How to test fileUpload and subscription with GraphQLTestTemplate #68

Closed
@hantsy

Description

@hantsy

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions