Skip to content

Commit 3e92f04

Browse files
committed
Limit public api of graphql response
1 parent b9d053e commit 3e92f04

File tree

5 files changed

+11
-14
lines changed

5 files changed

+11
-14
lines changed

.github/workflows/pull-request.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: "Pull request"
22
on:
3-
push:
4-
branches-ignore:
5-
- master
63
pull_request:
74
types: [opened, synchronize, reopened]
85

graphql-webclient/src/main/java/graphql/kickstart/spring/webclient/boot/GraphQLResponse.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
import java.util.Collections;
1010
import java.util.List;
1111
import java.util.Optional;
12-
import lombok.Data;
12+
import lombok.EqualsAndHashCode;
13+
import lombok.Getter;
1314

14-
@Data
15+
@EqualsAndHashCode
1516
public class GraphQLResponse {
1617

1718
public static final String ERRORS_FIELD = "errors";
1819

1920
private final JsonNode data;
21+
@Getter
2022
private final List<GraphQLError> errors;
2123
private final String rawResponse;
2224
private final ObjectMapper objectMapper;
@@ -60,7 +62,7 @@ public <T> T get(String fieldName, Class<T> type) {
6062
return null;
6163
}
6264

63-
public <T> T getFirstObject(Class<T> type) {
65+
public <T> T getFirst(Class<T> type) {
6466
return getFirstDataEntry().map(it -> objectMapper.convertValue(it, type)).orElse(null);
6567
}
6668

graphql-webclient/src/main/java/graphql/kickstart/spring/webclient/boot/GraphQLWebClientImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public <T> Mono<T> post(String resource, Map<String, Object> variables, Class<T>
2626
return post(resource, variables)
2727
.flatMap(it -> {
2828
it.validateNoErrors();
29-
return Mono.justOrEmpty(it.getFirstObject(returnType));
29+
return Mono.justOrEmpty(it.getFirst(returnType));
3030
});
3131
}
3232

graphql-webclient/src/test/java/graphql/kickstart/spring/webclient/boot/GraphQLResponseTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,18 @@ void getFieldName_dataFieldExists_returnsValue() {
6060
@Test
6161
void getFirstObject_dataIsNull_returnsNull() {
6262
GraphQLResponse response = constructResponse("{ \"data\": null }");
63-
assertNull(response.getFirstObject(String.class));
63+
assertNull(response.getFirst(String.class));
6464
}
6565

6666
@Test
6767
void getFirstObject_notDataFieldExists_returnsNull() {
6868
GraphQLResponse response = constructResponse("{ \"data\": { \"field\": null } }");
69-
assertNull(response.getFirstObject(String.class));
69+
assertNull(response.getFirst(String.class));
7070
}
7171

7272
@Test
7373
void getList_dataIsNull_returnsEmptyList() {
7474
GraphQLResponse response = constructResponse("{ \"data\": null }");
75-
assertNull(response.getData());
7675
assertTrue(response.getList("test", String.class).isEmpty());
7776
}
7877

graphql-webclient/src/test/java/graphql/kickstart/spring/webclient/boot/GraphQLWebClientTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static org.junit.jupiter.api.Assertions.assertThrows;
66
import static org.springframework.test.util.AssertionErrors.assertTrue;
77

8-
import com.fasterxml.jackson.databind.JsonNode;
98
import com.fasterxml.jackson.databind.ObjectMapper;
109
import graphql.kickstart.spring.webclient.testapp.Simple;
1110
import java.util.List;
@@ -79,8 +78,8 @@ void simpleTypeAsRequestSucceeds() {
7978
assertNotNull(response, "response should not be null");
8079
GraphQLResponse object = response.block();
8180
assertNotNull(object);
82-
JsonNode simple = object.getData().get("simple");
83-
assertEquals("my-id", simple.get("id").asText(), "response id should equal 'my-id'");
81+
Simple simple = object.get("simple", Simple.class);
82+
assertEquals("my-id", simple.getId(), "response id should equal 'my-id'");
8483
}
8584

8685
@Test
@@ -116,7 +115,7 @@ void headerIsAdded() {
116115
GraphQLResponse object = response.block();
117116
assertNotNull(object);
118117
assertEquals("my-custom-header-value",
119-
object.getData().get("header").asText(), "response should equal 'my-custom-header-value'");
118+
object.get("header", String.class), "response should equal 'my-custom-header-value'");
120119
}
121120

122121
}

0 commit comments

Comments
 (0)