Skip to content

Commit 6ad214b

Browse files
committed
Add tests based on the spec and refactor GraphQLServlet.
1 parent 3588a59 commit 6ad214b

File tree

11 files changed

+626
-107
lines changed

11 files changed

+626
-107
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ dependencies {
3737
testRuntime "cglib:cglib-nodep:3.2.4"
3838
testRuntime "org.objenesis:objenesis:2.5.1"
3939
testCompile 'org.slf4j:slf4j-simple:1.7.24'
40+
testCompile 'org.springframework:spring-test:4.3.7.RELEASE' // MockHttpServletRequest, MockHttpServletResponse
41+
testRuntime 'org.springframework:spring-web:4.3.7.RELEASE'
4042

4143
// Remove boilerplate
4244
compile 'org.projectlombok:lombok:1.16.8'
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.servlet;
16+
17+
import com.fasterxml.jackson.annotation.JsonIgnore;
18+
import graphql.ErrorType;
19+
import graphql.GraphQLError;
20+
import graphql.language.SourceLocation;
21+
22+
import java.util.List;
23+
24+
/**
25+
* @author Andrew Potter
26+
*/
27+
public class GenericGraphQLError implements GraphQLError {
28+
29+
private final String message;
30+
31+
public GenericGraphQLError(String message) {
32+
this.message = message;
33+
}
34+
35+
@Override
36+
public String getMessage() {
37+
return message;
38+
}
39+
40+
@Override
41+
@JsonIgnore
42+
public List<SourceLocation> getLocations() {
43+
return null;
44+
}
45+
46+
@Override
47+
@JsonIgnore
48+
public ErrorType getErrorType() {
49+
return null;
50+
}
51+
}

src/main/java/graphql/servlet/GraphQLContext.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
import javax.security.auth.Subject;
2626
import javax.servlet.http.HttpServletRequest;
2727
import javax.servlet.http.HttpServletResponse;
28+
import javax.servlet.http.Part;
29+
import java.util.Collection;
2830
import java.util.HashMap;
31+
import java.util.List;
2932
import java.util.Map;
3033
import java.util.Optional;
3134

@@ -39,5 +42,5 @@ public class GraphQLContext {
3942
private Optional<Subject> subject = Optional.empty();
4043

4144
@Getter @Setter
42-
private Optional<FileItemIterator> files = Optional.empty();
45+
private Optional<Collection<Part>> parts = Optional.empty();
4346
}

src/main/java/graphql/servlet/GraphQLOperationListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.Map;
2121

2222
public interface GraphQLOperationListener {
23-
void beforeGraphQLOperation(GraphQLContext context, String operationName, String query, Map<String, Object> variables);
24-
void onSuccessfulGraphQLOperation(GraphQLContext context, String operationName, String query, Map<String, Object> variables, Object data);
25-
void onFailedGraphQLOperation(GraphQLContext context, String operationName, String query, Map<String, Object> variables, List<GraphQLError> errors);
23+
default void beforeGraphQLOperation(GraphQLContext context, String operationName, String query, Map<String, Object> variables) {}
24+
default void onSuccessfulGraphQLOperation(GraphQLContext context, String operationName, String query, Map<String, Object> variables, Object data) {}
25+
default void onFailedGraphQLOperation(GraphQLContext context, String operationName, String query, Map<String, Object> variables, Object data, List<GraphQLError> errors) {}
2626
}

0 commit comments

Comments
 (0)