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

Commit d62b46d

Browse files
committed
Fix bugs
1 parent 11a80c1 commit d62b46d

File tree

6 files changed

+601
-551
lines changed

6 files changed

+601
-551
lines changed

example-request-scoped-dataloader/src/main/java/graphql/servlet/examples/dataloader/requestscope/CustomerResolver.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ public class CustomerResolver implements GraphQLResolver<Customer> {
1212

1313
public CompletableFuture<String> getName(Customer customer, DataFetchingEnvironment dfe) {
1414
final DataLoader<Integer, String> dataloader = ((GraphQLContext) dfe.getContext())
15-
.getDataLoaderRegistry().get()
16-
.getDataLoader("customerDataLoader");
17-
18-
return dataloader.load(customer.getCustomerId());
15+
.getDataLoaderRegistry()
16+
.map(it -> it.getDataLoader("customerDataLoader"))
17+
.map(it -> it.load(customer.getCustomerId()))
18+
.orElse(null);
1919
}
2020

2121
}

example-spring-common/src/main/java/graphql/kickstart/spring/web/boot/sample/schema/TodoSchema.java

Lines changed: 125 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -39,122 +39,133 @@
3939
@GraphQLSchema
4040
public class TodoSchema {
4141

42-
@GraphQLSchemaQuery
43-
private RootObjectType root;
44-
45-
private UserObjectType theOnlyUser = new UserObjectType();
46-
private List<TodoObjectType> todos = new ArrayList<>();
47-
48-
private TodoSimpleListConnection simpleConnectionTodo;
49-
private int nextTodoId = 0;
50-
51-
52-
public TodoSchema() {
53-
addTodo("Do Something");
54-
addTodo("Other todo");
55-
56-
simpleConnectionTodo = new TodoSimpleListConnection(todos);
57-
}
58-
59-
public String addTodo(String text) {
60-
TodoObjectType newTodo = new TodoObjectType();
61-
newTodo.setId(Integer.toString(nextTodoId++));
62-
newTodo.setText(text);
63-
todos.add(newTodo);
64-
return newTodo.getId(newTodo);
65-
}
66-
67-
public void removeTodo(String id) {
68-
TodoObjectType del = todos.stream().filter(todo -> todo.getId(todo).equals(id)).findFirst().get();
69-
todos.remove(del);
70-
}
71-
72-
public void renameTodo(String id, String text) {
73-
TodoObjectType matchedTodo = todos.stream().filter(todo -> todo.getId(todo).equals(id)).findFirst().get();
74-
matchedTodo.setText(text);
75-
}
76-
77-
public List<String> removeCompletedTodos() {
78-
List<String> toDelete = todos.stream()
79-
.filter(TodoObjectType::isComplete)
80-
.map(todoObjectType -> todoObjectType.getId(todoObjectType))
81-
.collect(Collectors.toList());
82-
todos.removeIf(todo -> toDelete.contains(todo.getId(todo)));
83-
return toDelete;
84-
}
85-
86-
public List<String> markAllTodos(boolean complete) {
87-
List<String> changed = new ArrayList<>();
88-
todos.stream().filter(todo -> complete != todo.isComplete()).forEach(todo -> {
89-
changed.add(todo.getId(todo));
90-
todo.setComplete(complete);
91-
});
92-
93-
return changed;
94-
}
95-
96-
public void changeTodoStatus(String id, boolean complete) {
97-
TodoObjectType todo = getTodo(id);
98-
todo.setComplete(complete);
99-
}
100-
101-
public TodoObjectType getTodo(String id) {
102-
return todos.stream().filter(todo -> todo.getId(todo).equals(id)).findFirst().get();
103-
}
104-
105-
public List<TodoObjectType> getTodos(List<String> ids) {
106-
return todos.stream().filter(todo -> ids.contains(todo.getId(todo))).collect(Collectors.toList());
107-
}
108-
109-
public UserObjectType getTheOnlyUser() {
110-
return theOnlyUser;
111-
}
112-
113-
114-
public TodoSimpleListConnection getSimpleConnectionTodo() {
115-
return simpleConnectionTodo;
116-
}
117-
118-
public static class AddTodoIn {
119-
private String text;
120-
121-
public String getText() {
122-
return text;
123-
}
124-
125-
public void setText(String text) {
126-
this.text = text;
127-
}
128-
}
129-
130-
// --- mutations
131-
132-
@GraphQLMutation
133-
@GraphQLDescription("Mutation to add new todo item")
134-
public
135-
@GraphQLOut("todoEdge")
136-
TodoObjectType.TodoEdgeObjectType addTodoMutation(@GraphQLIn("addTodoInput") AddTodoIn addTodoInput) {
137-
138-
TodoObjectType.TodoEdgeObjectType todoEdgeObjectType = new TodoObjectType.TodoEdgeObjectType();
139-
todoEdgeObjectType.setCursor("test-cursor");
140-
todoEdgeObjectType.setNode(new TodoObjectType());
141-
todoEdgeObjectType.getNode().setId("id-12345");
142-
todoEdgeObjectType.getNode().setText("simple text");
143-
todoEdgeObjectType.getNode().setComplete(false);
144-
145-
return todoEdgeObjectType;
146-
}
147-
148-
@GraphQLMutation
149-
public
150-
@GraphQLOut("filename")
151-
String uploadFile(GraphQLServletContext graphQLContext) {
152-
return graphQLContext.getParts().values().stream().flatMap(Collection::stream).map(Part::getName).collect(Collectors.joining(", "));
42+
@GraphQLSchemaQuery
43+
private RootObjectType root;
44+
45+
private UserObjectType theOnlyUser = new UserObjectType();
46+
private List<TodoObjectType> todos = new ArrayList<>();
47+
48+
private TodoSimpleListConnection simpleConnectionTodo;
49+
private int nextTodoId = 0;
50+
51+
52+
public TodoSchema() {
53+
addTodo("Do Something");
54+
addTodo("Other todo");
55+
56+
simpleConnectionTodo = new TodoSimpleListConnection(todos);
57+
}
58+
59+
public String addTodo(String text) {
60+
TodoObjectType newTodo = new TodoObjectType();
61+
newTodo.setId(Integer.toString(nextTodoId++));
62+
newTodo.setText(text);
63+
todos.add(newTodo);
64+
return newTodo.getId(newTodo);
65+
}
66+
67+
public void removeTodo(String id) {
68+
todos.stream()
69+
.filter(todo -> todo.getId(todo).equals(id))
70+
.findFirst()
71+
.ifPresent(it -> todos.remove(it));
72+
}
73+
74+
public void renameTodo(String id, String text) {
75+
todos.stream()
76+
.filter(todo -> todo.getId(todo).equals(id))
77+
.findFirst()
78+
.ifPresent(it -> it.setText(text));
79+
}
80+
81+
public List<String> removeCompletedTodos() {
82+
List<String> toDelete = todos.stream()
83+
.filter(TodoObjectType::isComplete)
84+
.map(todoObjectType -> todoObjectType.getId(todoObjectType))
85+
.collect(Collectors.toList());
86+
todos.removeIf(todo -> toDelete.contains(todo.getId(todo)));
87+
return toDelete;
88+
}
89+
90+
public List<String> markAllTodos(boolean complete) {
91+
List<String> changed = new ArrayList<>();
92+
todos.stream().filter(todo -> complete != todo.isComplete()).forEach(todo -> {
93+
changed.add(todo.getId(todo));
94+
todo.setComplete(complete);
95+
});
96+
97+
return changed;
98+
}
99+
100+
public void changeTodoStatus(String id, boolean complete) {
101+
TodoObjectType todo = getTodo(id);
102+
todo.setComplete(complete);
103+
}
104+
105+
public TodoObjectType getTodo(String id) {
106+
return todos.stream()
107+
.filter(todo -> todo.getId(todo).equals(id))
108+
.findFirst()
109+
.orElseThrow(() -> throw IllegalStateException("No todo found with id " + id));
110+
}
111+
112+
public List<TodoObjectType> getTodos(List<String> ids) {
113+
return todos.stream().filter(todo -> ids.contains(todo.getId(todo)))
114+
.collect(Collectors.toList());
115+
}
116+
117+
public UserObjectType getTheOnlyUser() {
118+
return theOnlyUser;
119+
}
120+
121+
122+
public TodoSimpleListConnection getSimpleConnectionTodo() {
123+
return simpleConnectionTodo;
124+
}
125+
126+
public static class AddTodoIn {
127+
128+
private String text;
129+
130+
public String getText() {
131+
return text;
153132
}
154133

155-
@GraphQLMutation
156-
public String updateTodoMutation(@GraphQLIn("updateTodoInput") String newText) {
157-
return "Simple output string";
134+
public void setText(String text) {
135+
this.text = text;
158136
}
137+
}
138+
139+
// --- mutations
140+
141+
@GraphQLMutation
142+
@GraphQLDescription("Mutation to add new todo item")
143+
public
144+
@GraphQLOut("todoEdge")
145+
TodoObjectType.TodoEdgeObjectType addTodoMutation(
146+
@GraphQLIn("addTodoInput") AddTodoIn addTodoInput) {
147+
148+
TodoObjectType.TodoEdgeObjectType todoEdgeObjectType = new TodoObjectType.TodoEdgeObjectType();
149+
todoEdgeObjectType.setCursor("test-cursor");
150+
todoEdgeObjectType.setNode(new TodoObjectType());
151+
todoEdgeObjectType.getNode().setId("id-12345");
152+
todoEdgeObjectType.getNode().setText("simple text");
153+
todoEdgeObjectType.getNode().setComplete(false);
154+
155+
return todoEdgeObjectType;
156+
}
157+
158+
@GraphQLMutation
159+
public
160+
@GraphQLOut("filename")
161+
String uploadFile(GraphQLServletContext graphQLContext) {
162+
return graphQLContext.getParts().values().stream().flatMap(Collection::stream)
163+
.map(Part::getName).collect(Collectors.joining(", "));
164+
}
165+
166+
@GraphQLMutation
167+
public String updateTodoMutation(@GraphQLIn("updateTodoInput") String newText) {
168+
return "Simple output string";
169+
}
159170

160171
}

graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/spring/web/boot/GraphQLWebAutoConfiguration.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import java.util.LinkedHashMap;
5555
import java.util.List;
5656
import java.util.Map;
57+
import java.util.Map.Entry;
5758
import java.util.Optional;
5859
import javax.annotation.PostConstruct;
5960
import javax.servlet.MultipartConfigElement;
@@ -181,7 +182,12 @@ public ExecutionStrategyProvider executionStrategyProvider() {
181182
return new DefaultExecutionStrategyProvider(new AsyncExecutionStrategy(), null,
182183
new SubscriptionExecutionStrategy());
183184
} else if (executionStrategies.entrySet().size() == 1) {
184-
return new DefaultExecutionStrategyProvider(executionStrategies.entrySet().stream().findFirst().get().getValue());
185+
return new DefaultExecutionStrategyProvider(
186+
executionStrategies.entrySet().stream()
187+
.findFirst()
188+
.map(Entry::getValue)
189+
.orElseThrow(IllegalStateException::new)
190+
);
185191
} else {
186192

187193
if (!executionStrategies.containsKey(QUERY_EXECUTION_STRATEGY)) {

graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestError.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static java.util.Objects.nonNull;
44

55
import com.fasterxml.jackson.annotation.JsonTypeInfo;
6+
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
67
import graphql.ErrorClassification;
78
import graphql.ErrorType;
89
import graphql.GraphQLError;
@@ -27,12 +28,12 @@
2728
public class GraphQLTestError implements GraphQLError {
2829

2930
private String message;
30-
@JsonTypeInfo(defaultImpl = JacksonFriendlySourceLocation.class, use = JsonTypeInfo.Id.CLASS)
31+
@JsonTypeInfo(defaultImpl = JacksonFriendlySourceLocation.class, use = Id.NAME)
3132
private List<SourceLocation> locations;
32-
@JsonTypeInfo(defaultImpl = ErrorType.class, use = JsonTypeInfo.Id.CLASS)
33-
private ErrorClassification errorType;
34-
private List<Object> path;
35-
private Map<String, Object> extensions;
33+
@JsonTypeInfo(defaultImpl = ErrorType.class, use = Id.NAME)
34+
private transient ErrorClassification errorType;
35+
private transient List<Object> path;
36+
private transient Map<String, Object> extensions;
3637

3738
@Override
3839
public String toString() {
@@ -58,7 +59,7 @@ public String toString() {
5859
.map(Object::toString)
5960
.map(this::toNumericIndexIfPossible)
6061
.collect(Collectors.joining("/"))
61-
.replaceAll("/\\[", "[")
62+
.replace("/\\[", "[")
6263
);
6364
}
6465
return sb.toString();

0 commit comments

Comments
 (0)