Skip to content

Commit 7d8066b

Browse files
committed
Merge branch 'master' into subscription-support
2 parents 4bf61e1 + 2be2ce0 commit 7d8066b

13 files changed

+181
-190
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ build/
66
.idea/
77
target/
88
/out/
9+
.classpath
10+
.project
11+
.settings
12+
bin

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ repositories {
1616
}
1717
1818
dependencies {
19-
compile 'com.graphql-java:graphql-java-servlet:4.5.0'
19+
compile 'com.graphql-java:graphql-java-servlet:4.6.1'
2020
}
2121
```
2222

2323
```xml
2424
<dependency>
2525
<groupId>com.graphql-java</groupId>
2626
<artifactId>graphql-java-servlet</artifactId>
27-
<version>4.5.0</version>
27+
<version>4.6.1</version>
2828
</dependency>
2929
```
3030

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ dependencies {
5959
// GraphQL
6060
compile 'com.graphql-java:graphql-java:6.0'
6161

62-
compileOnly 'com.graphql-java:graphql-java-annotations:0.13.1'
6362
testCompile 'com.graphql-java:graphql-java-annotations:0.13.1'
6463

6564
// JSON

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version = 4.6.1-SNAPSHOT
1+
version = 4.7.1
22
group = com.graphql-java

src/main/java/graphql/servlet/DefaultGraphQLErrorHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ protected List<GraphQLError> filterGraphQLErrors(List<GraphQLError> errors) {
4444
}
4545

4646
protected boolean isClientError(GraphQLError error) {
47-
return !(error instanceof ExceptionWhileDataFetching || error instanceof Throwable);
47+
if (error instanceof ExceptionWhileDataFetching) {
48+
return ((ExceptionWhileDataFetching) error).getException() instanceof GraphQLError;
49+
}
50+
return !(error instanceof Throwable);
4851
}
4952
}

src/main/java/graphql/servlet/GraphQLServlet.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
import java.security.AccessController;
4747
import java.security.PrivilegedAction;
4848
import java.util.ArrayList;
49-
import java.util.Arrays;
5049
import java.util.Collections;
5150
import java.util.HashMap;
5251
import java.util.Iterator;
52+
import java.util.LinkedHashMap;
5353
import java.util.List;
5454
import java.util.Map;
5555
import java.util.Objects;
@@ -78,7 +78,7 @@ public abstract class GraphQLServlet extends HttpServlet implements Servlet, Gra
7878
protected abstract GraphQLRootObjectBuilder getRootObjectBuilder();
7979
protected abstract ExecutionStrategyProvider getExecutionStrategyProvider();
8080
protected abstract Instrumentation getInstrumentation();
81-
protected abstract Map<String, Object> transformVariables(GraphQLSchema schema, String query, Map<String, Object> variables);
81+
8282
protected abstract GraphQLErrorHandler getGraphQLErrorHandler();
8383
protected abstract PreparsedDocumentProvider getPreparsedDocumentProvider();
8484

@@ -356,16 +356,14 @@ private void query(GraphQLRequest request, GraphQLRequestInfo info, ExecutionRes
356356
List<GraphQLServletListener.OperationCallback> operationCallbacks = runListeners(l -> l.onOperation(context, operationName, query, variables));
357357

358358
try {
359-
final ExecutionResult executionResult = newGraphQL(schema).execute(new ExecutionInput(query, operationName, context, rootObject, transformVariables(schema, query, variables)));
360-
final List<GraphQLError> errors = executionResult.getErrors();
361-
final Object data = executionResult.getData();
359+
final ExecutionResult executionResult = newGraphQL(schema).execute(new ExecutionInput(query, operationName, context, rootObject, variables));
362360

363361
resultHandler.accept(executionResult);
364362

365-
if (getGraphQLErrorHandler().errorsPresent(errors)) {
366-
runCallbacks(operationCallbacks, c -> c.onError(context, operationName, query, variables, data, errors));
363+
if (getGraphQLErrorHandler().errorsPresent(executionResult.getErrors())) {
364+
runCallbacks(operationCallbacks, c -> c.onError(context, operationName, query, variables, executionResult));
367365
} else {
368-
runCallbacks(operationCallbacks, c -> c.onSuccess(context, operationName, query, variables, data));
366+
runCallbacks(operationCallbacks, c -> c.onSuccess(context, operationName, query, variables, executionResult));
369367
}
370368

371369
} finally {
@@ -380,13 +378,17 @@ private ExecutionResultHandler serializeResultAsJson(StringHandler responseHandl
380378

381379
private Map<String, Object> createResultFromExecutionResult(ExecutionResult executionResult) {
382380

383-
final Map<String, Object> result = new HashMap<>();
381+
final Map<String, Object> result = new LinkedHashMap<>();
384382
result.put("data", executionResult.getData());
385383

386384
if (getGraphQLErrorHandler().errorsPresent(executionResult.getErrors())) {
387385
result.put("errors", getGraphQLErrorHandler().processErrors(executionResult.getErrors()));
388386
}
389387

388+
if(executionResult.getExtensions() != null){
389+
result.put("extensions", executionResult.getExtensions());
390+
}
391+
390392
return result;
391393
}
392394

src/main/java/graphql/servlet/GraphQLServletListener.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package graphql.servlet;
22

3+
import graphql.ExecutionResult;
34
import graphql.GraphQLError;
45

56
import javax.servlet.http.HttpServletRequest;
@@ -25,8 +26,8 @@ default void onFinally(HttpServletRequest request, HttpServletResponse response)
2526
}
2627

2728
interface OperationCallback {
28-
default void onSuccess(GraphQLContext context, String operationName, String query, Map<String, Object> variables, Object data) {}
29-
default void onError(GraphQLContext context, String operationName, String query, Map<String, Object> variables, Object data, List<GraphQLError> errors) {}
29+
default void onSuccess(GraphQLContext context, String operationName, String query, Map<String, Object> variables, ExecutionResult executionResult) {}
30+
default void onError(GraphQLContext context, String operationName, String query, Map<String, Object> variables, ExecutionResult executionResult) {}
3031
default void onFinally(GraphQLContext context, String operationName, String query, Map<String, Object> variables) {}
3132
}
3233
}

src/main/java/graphql/servlet/GraphQLVariables.java

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/main/java/graphql/servlet/OsgiGraphQLServlet.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import graphql.execution.preparsed.NoOpPreparsedDocumentProvider;
55
import graphql.execution.preparsed.PreparsedDocumentProvider;
66
import graphql.schema.GraphQLObjectType;
7-
import graphql.schema.GraphQLSchema;
87
import graphql.schema.GraphQLType;
98
import org.osgi.service.component.annotations.*;
109

@@ -13,7 +12,6 @@
1312
import java.util.ArrayList;
1413
import java.util.HashSet;
1514
import java.util.List;
16-
import java.util.Map;
1715
import java.util.Optional;
1816
import java.util.Set;
1917

@@ -211,11 +209,6 @@ protected Instrumentation getInstrumentation() {
211209
return instrumentationProvider.getInstrumentation();
212210
}
213211

214-
@Override
215-
protected Map<String, Object> transformVariables(GraphQLSchema schema, String query, Map<String, Object> variables) {
216-
return new GraphQLVariables(schema, query, variables);
217-
}
218-
219212
@Override
220213
protected GraphQLErrorHandler getGraphQLErrorHandler() {
221214
return errorHandler;

src/main/java/graphql/servlet/SimpleGraphQLServlet.java

Lines changed: 107 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,49 @@
1010
import javax.servlet.http.HttpServletRequest;
1111
import javax.servlet.http.HttpServletResponse;
1212
import java.util.List;
13-
import java.util.Map;
1413
import java.util.Optional;
1514

1615
/**
1716
* @author Andrew Potter
1817
*/
1918
public class SimpleGraphQLServlet extends GraphQLServlet {
2019

20+
/**
21+
* @deprecated use {@link #builder(GraphQLSchema)} instead.
22+
*/
23+
@Deprecated
2124
public SimpleGraphQLServlet(GraphQLSchema schema) {
2225
this(schema, new DefaultExecutionStrategyProvider());
2326
}
2427

28+
/**
29+
* @deprecated use {@link #builder(GraphQLSchema)} instead.
30+
*/
31+
@Deprecated
2532
public SimpleGraphQLServlet(GraphQLSchema schema, ExecutionStrategy executionStrategy) {
2633
this(schema, new DefaultExecutionStrategyProvider(executionStrategy));
2734
}
2835

36+
/**
37+
* @deprecated use {@link #builder(GraphQLSchema)} instead.
38+
*/
39+
@Deprecated
2940
public SimpleGraphQLServlet(GraphQLSchema schema, ExecutionStrategyProvider executionStrategyProvider) {
3041
this(schema, executionStrategyProvider, null, null, null, null, null, null, null);
3142
}
3243

44+
/**
45+
* @deprecated use {@link #builder(GraphQLSchema)} instead.
46+
*/
47+
@Deprecated
3348
public SimpleGraphQLServlet(final GraphQLSchema schema, ExecutionStrategyProvider executionStrategyProvider, ObjectMapperConfigurer objectMapperConfigurer, List<GraphQLServletListener> listeners, Instrumentation instrumentation, GraphQLErrorHandler errorHandler, GraphQLContextBuilder contextBuilder, GraphQLRootObjectBuilder rootObjectBuilder, PreparsedDocumentProvider preparsedDocumentProvider) {
3449
this(new DefaultGraphQLSchemaProvider(schema), executionStrategyProvider, objectMapperConfigurer, listeners, instrumentation, errorHandler, contextBuilder, rootObjectBuilder, preparsedDocumentProvider);
3550
}
3651

52+
/**
53+
* @deprecated use {@link #builder(GraphQLSchemaProvider)} instead.
54+
*/
55+
@Deprecated
3756
public SimpleGraphQLServlet(GraphQLSchemaProvider schemaProvider, ExecutionStrategyProvider executionStrategyProvider, ObjectMapperConfigurer objectMapperConfigurer, List<GraphQLServletListener> listeners, Instrumentation instrumentation, GraphQLErrorHandler errorHandler, GraphQLContextBuilder contextBuilder, GraphQLRootObjectBuilder rootObjectBuilder, PreparsedDocumentProvider preparsedDocumentProvider) {
3857
super(objectMapperConfigurer, listeners, null);
3958

@@ -71,6 +90,18 @@ public SimpleGraphQLServlet(GraphQLSchemaProvider schemaProvider, ExecutionStrat
7190
}
7291
}
7392

93+
private SimpleGraphQLServlet(Builder builder) {
94+
super(builder.objectMapperConfigurer, builder.listeners, null);
95+
96+
this.schemaProvider = builder.schemaProvider;
97+
this.executionStrategyProvider = builder.executionStrategyProvider;
98+
this.instrumentation = builder.instrumentation;
99+
this.errorHandler = builder.errorHandler;
100+
this.contextBuilder = builder.contextBuilder;
101+
this.rootObjectBuilder = builder.rootObjectBuilder;
102+
this.preparsedDocumentProvider = builder.preparsedDocumentProvider;
103+
}
104+
74105
private final GraphQLSchemaProvider schemaProvider;
75106
private final ExecutionStrategyProvider executionStrategyProvider;
76107
private final Instrumentation instrumentation;
@@ -79,6 +110,81 @@ public SimpleGraphQLServlet(GraphQLSchemaProvider schemaProvider, ExecutionStrat
79110
private final GraphQLRootObjectBuilder rootObjectBuilder;
80111
private final PreparsedDocumentProvider preparsedDocumentProvider;
81112

113+
public static SimpleGraphQLServlet create(GraphQLSchema schema) {
114+
return new Builder(schema).build();
115+
}
116+
117+
public static SimpleGraphQLServlet create(GraphQLSchemaProvider schemaProvider) {
118+
return new Builder(schemaProvider).build();
119+
}
120+
121+
public static Builder builder(GraphQLSchema schema) {
122+
return new Builder(schema);
123+
}
124+
125+
public static Builder builder(GraphQLSchemaProvider schemaProvider) {
126+
return new Builder(schemaProvider);
127+
}
128+
129+
public static class Builder {
130+
private final GraphQLSchemaProvider schemaProvider;
131+
private ExecutionStrategyProvider executionStrategyProvider = new DefaultExecutionStrategyProvider();
132+
private ObjectMapperConfigurer objectMapperConfigurer;
133+
private List<GraphQLServletListener> listeners;
134+
private Instrumentation instrumentation = NoOpInstrumentation.INSTANCE;
135+
private GraphQLErrorHandler errorHandler = new DefaultGraphQLErrorHandler();
136+
private GraphQLContextBuilder contextBuilder = new DefaultGraphQLContextBuilder();
137+
private GraphQLRootObjectBuilder rootObjectBuilder = new DefaultGraphQLRootObjectBuilder();
138+
private PreparsedDocumentProvider preparsedDocumentProvider = NoOpPreparsedDocumentProvider.INSTANCE;
139+
140+
public Builder(GraphQLSchema schema) {
141+
this(new DefaultGraphQLSchemaProvider(schema));
142+
}
143+
144+
public Builder(GraphQLSchemaProvider schemaProvider) {
145+
this.schemaProvider = schemaProvider;
146+
}
147+
148+
public Builder withExecutionStrategyProvider(ExecutionStrategyProvider provider) {
149+
this.executionStrategyProvider = provider;
150+
return this;
151+
}
152+
153+
public Builder withObjectMapperConfigurer(ObjectMapperConfigurer configurer) {
154+
this.objectMapperConfigurer = configurer;
155+
return this;
156+
}
157+
158+
public Builder withInstrumentation(Instrumentation instrumentation) {
159+
this.instrumentation = instrumentation;
160+
return this;
161+
}
162+
163+
public Builder withGraphQLErrorHandler(GraphQLErrorHandler handler) {
164+
this.errorHandler = handler;
165+
return this;
166+
}
167+
168+
public Builder withGraphQLContextBuilder(GraphQLContextBuilder context) {
169+
this.contextBuilder = context;
170+
return this;
171+
}
172+
173+
public Builder withGraphQLRootObjectBuilder(GraphQLRootObjectBuilder rootObject) {
174+
this.rootObjectBuilder = rootObject;
175+
return this;
176+
}
177+
178+
public Builder withPreparsedDocumentProvider(PreparsedDocumentProvider provider) {
179+
this.preparsedDocumentProvider = provider;
180+
return this;
181+
}
182+
183+
public SimpleGraphQLServlet build() {
184+
return new SimpleGraphQLServlet(this);
185+
}
186+
}
187+
82188
@Override
83189
protected GraphQLSchemaProvider getSchemaProvider() {
84190
return schemaProvider;
@@ -104,11 +210,6 @@ protected Instrumentation getInstrumentation() {
104210
return instrumentation;
105211
}
106212

107-
@Override
108-
protected Map<String, Object> transformVariables(GraphQLSchema schema, String query, Map<String, Object> variables) {
109-
return variables;
110-
}
111-
112213
@Override
113214
protected GraphQLErrorHandler getGraphQLErrorHandler() {
114215
return errorHandler;

0 commit comments

Comments
 (0)