Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit b8d8d6f

Browse files
feat(#212): query, variables and responses as resources for tabs
1 parent 324e641 commit b8d8d6f

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

playground-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/playground/boot/PlaygroundTab.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.oembedler.moon.playground.boot;
22

3+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
34
import lombok.Data;
5+
import org.springframework.core.io.Resource;
46

57
import java.util.List;
68
import java.util.Map;
@@ -14,24 +16,27 @@ public class PlaygroundTab {
1416
private String endpoint;
1517

1618
/**
17-
* The GraphQL query (operation) to be initially displayed on the tab.
19+
* The GraphQL query (operation) to be initially displayed on the tab. It should be a graphql resource.
1820
*/
19-
private String query;
21+
@JsonSerialize(using = ResourceSerializer.class)
22+
private Resource query;
2023

2124
/**
2225
* The name of the tab.
2326
*/
2427
private String name;
2528

2629
/**
27-
* The query variables. It should be a serialized JSON.
30+
* The query variables. It should be a JSON resource.
2831
*/
29-
private String variables;
32+
@JsonSerialize(using = ResourceSerializer.class)
33+
private Resource variables;
3034

3135
/**
32-
* The list of responses to be displayed under "responses". Should be a list of serialized JSONs.
36+
* The list of responses to be displayed under "responses". It should be a list of JSON resources.
3337
*/
34-
private List<String> responses;
38+
@JsonSerialize(contentUsing = ResourceSerializer.class)
39+
private List<Resource> responses;
3540

3641
/**
3742
* HTTP headers. Key-value pairs expected.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.oembedler.moon.playground.boot;
2+
3+
import com.fasterxml.jackson.core.JsonGenerator;
4+
import com.fasterxml.jackson.databind.JsonSerializer;
5+
import com.fasterxml.jackson.databind.SerializerProvider;
6+
import org.apache.tomcat.util.http.fileupload.util.Streams;
7+
import org.springframework.boot.jackson.JsonComponent;
8+
import org.springframework.core.io.Resource;
9+
10+
import java.io.IOException;
11+
import java.nio.charset.StandardCharsets;
12+
13+
@JsonComponent
14+
public class ResourceSerializer extends JsonSerializer<Resource> {
15+
@Override
16+
public void serialize(final Resource value, final JsonGenerator gen, final SerializerProvider serializers)
17+
throws IOException {
18+
final String content = Streams.asString(value.getInputStream(), StandardCharsets.UTF_8.name());
19+
gen.writeString(content);
20+
}
21+
}

0 commit comments

Comments
 (0)