Skip to content

Commit 11abe76

Browse files
committed
Merge remote-tracking branch 'upstream/master' into 377-field-selection-in-data-fetchers
# Conflicts: # src/main/java/graphql/execution/FieldCollector.java
2 parents a75cdea + 7681aa7 commit 11abe76

File tree

82 files changed

+2093
-376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2093
-376
lines changed

README.md

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -641,35 +641,8 @@ This implementation is based on the [js reference implementation](https://github
641641
For example the StarWarSchema and the tests (among a lot of other things) are simply adapted to the Java world.
642642

643643
### Related projects
644-
* [todomvc-relay-java](https://github.com/graphql-java/todomvc-relay-java): Port of the Relay TodoMVC example to a java backend
645644

646-
* [graphql-java-type-generator](https://github.com/graphql-java/graphql-java-type-generator): This library will autogenerate GraphQL types for usage in com.graphql-java:graphql-java Edit
647-
648-
* [graphql-rxjava](https://github.com/nfl/graphql-rxjava): An execution strategy that makes it easier to use rxjava's Observable
649-
650-
* [graphql-java-reactive](https://github.com/bsideup/graphql-java-reactive): An execution strategy which is based on Reactive Streams. Project is evolving.
651-
652-
* [graphql-java-annotations](https://github.com/graphql-java/graphql-java-annotations): Annotations-based syntax for GraphQL schema definition.
653-
654-
* [graphql-java-servlet](https://github.com/graphql-java/graphql-java-servlet): Servlet that automatically exposes a schema dynamically built from GraphQL queries and mutations.
655-
656-
* [graphql-apigen](https://github.com/Distelli/graphql-apigen): Generate Java APIs with GraphQL Schemas
657-
658-
* [graphql-spring-boot](https://github.com/oembedler/graphql-spring-boot): GraphQL and GraphiQL Spring Framework Boot Starters
659-
660-
* [spring-graphql-common](https://github.com/oembedler/spring-graphql-common): Spring Framework GraphQL Library
661-
662-
* [graphql-jpa](https://github.com/jcrygier/graphql-jpa): JPA Implementation of GraphQL (builds on graphql-java)
663-
664-
* [graphql-jpa-spring-boot-starter](https://github.com/timtebeek/graphql-jpa-spring-boot-starter): Spring Boot starter for GraphQL JPA; Expose JPA entities with GraphQL.
665-
666-
* [graphkool](https://github.com/beyondeye/graphkool): GraphQl-java utilities in kotlin
667-
668-
* [schemagen-graphql](https://github.com/bpatters/schemagen-graphql): GraphQL-Java add-on that adds support for Schema Generation & Execution for enterprise level applications.
669-
670-
* [GraphQL-SPQR](https://github.com/leangen/GraphQL-SPQR): Java 8+ API for rapid development of GraphQL services
671-
672-
* [Light Java GraphQL](https://github.com/networknt/light-java-graphql): A lightweight, fast microservices framework with all other cross-cutting concerns addressed that is ready to plug in GraphQL schema.
645+
Please have a look at the [awesome-graphql-java](https://github.com/graphql-java/awesome-graphql-java) list.
673646

674647
### License
675648

src/main/antlr/Graphql.g4

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ operationDefinition:
1818
selectionSet |
1919
operationType name? variableDefinitions? directives? selectionSet;
2020

21-
operationType : MUTATION | QUERY;
21+
operationType : SUBSCRIPTION | MUTATION | QUERY;
2222

2323
variableDefinitions : '(' variableDefinition+ ')';
2424

@@ -59,7 +59,7 @@ typeCondition : 'on' typeName;
5959

6060
// Value
6161

62-
name: NAME | FRAGMENT | QUERY | MUTATION | SCHEMA | SCALAR | TYPE | INTERFACE | IMPLEMENTS | ENUM | UNION | INPUT | EXTEND | DIRECTIVE;
62+
name: NAME | FRAGMENT | QUERY | MUTATION | SUBSCRIPTION | SCHEMA | SCALAR | TYPE | INTERFACE | IMPLEMENTS | ENUM | UNION | INPUT | EXTEND | DIRECTIVE;
6363

6464
value :
6565
IntValue |
@@ -179,6 +179,7 @@ BooleanValue: 'true' | 'false';
179179
FRAGMENT: 'fragment';
180180
QUERY: 'query';
181181
MUTATION: 'mutation';
182+
SUBSCRIPTION: 'subscription';
182183
SCHEMA: 'schema';
183184
SCALAR: 'scalar';
184185
TYPE: 'type';

src/main/java/graphql/Assert.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import java.util.Collection;
44

5+
@Internal
56
public class Assert {
67

7-
88
public static <T> T assertNotNull(T object, String errorMessage) {
99
if (object != null) return object;
1010
throw new AssertException(errorMessage);
@@ -16,17 +16,19 @@ public static <T> Collection<T> assertNotEmpty(Collection<T> c, String errorMess
1616
}
1717

1818
private static final String invalidNameErrorMessage = "Name must be non-null, non-empty and match [_A-Za-z][_0-9A-Za-z]*";
19+
1920
/**
2021
* Validates that the Lexical token name matches the current spec.
21-
* currently non null, non empty,
22+
* currently non null, non empty,
23+
*
2224
* @param name - the name to be validated.
23-
* @return the name if valid, or AssertException if invalid.
25+
* @return the name if valid, or AssertException if invalid.
2426
*/
25-
public static String assertValidName(String name) {
26-
if (name != null && !name.isEmpty() && name.matches("[_A-Za-z][_0-9A-Za-z]*")) {
27-
return name;
28-
}
29-
throw new AssertException(invalidNameErrorMessage);
30-
}
27+
public static String assertValidName(String name) {
28+
if (name != null && !name.isEmpty() && name.matches("[_A-Za-z][_0-9A-Za-z]*")) {
29+
return name;
30+
}
31+
throw new AssertException(invalidNameErrorMessage);
32+
}
3133

3234
}

src/main/java/graphql/AssertException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package graphql;
22

33

4+
@PublicApi
45
public class AssertException extends GraphQLException {
56

67
public AssertException(String message) {

src/main/java/graphql/ExceptionWhileDataFetching.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.util.List;
77

8+
@PublicApi
89
public class ExceptionWhileDataFetching implements GraphQLError {
910

1011
private final Throwable exception;

src/main/java/graphql/ExecutionResult.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.List;
55
import java.util.Map;
66

7+
@PublicApi
78
public interface ExecutionResult {
89

910
<T> T getData();

src/main/java/graphql/ExecutionResultImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.List;
77
import java.util.Map;
88

9+
@Internal
910
public class ExecutionResultImpl implements ExecutionResult {
1011

1112
private final List<GraphQLError> errors = new ArrayList<>();

src/main/java/graphql/GraphQL.java

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package graphql;
22

3-
4-
import graphql.execution.*;
3+
import graphql.execution.Execution;
4+
import graphql.execution.ExecutionId;
5+
import graphql.execution.ExecutionIdProvider;
6+
import graphql.execution.ExecutionStrategy;
7+
import graphql.execution.SimpleExecutionStrategy;
58
import graphql.execution.instrumentation.Instrumentation;
69
import graphql.execution.instrumentation.InstrumentationContext;
710
import graphql.execution.instrumentation.NoOpInstrumentation;
@@ -24,6 +27,7 @@
2427

2528
import static graphql.Assert.assertNotNull;
2629

30+
@PublicApi
2731
public class GraphQL {
2832

2933
private static final Logger log = LoggerFactory.getLogger(GraphQL.class);
@@ -33,6 +37,7 @@ public class GraphQL {
3337
private final GraphQLSchema graphQLSchema;
3438
private final ExecutionStrategy queryStrategy;
3539
private final ExecutionStrategy mutationStrategy;
40+
private final ExecutionStrategy subscriptionStrategy;
3641
private final ExecutionIdProvider idProvider;
3742
private final Instrumentation instrumentation;
3843

@@ -44,12 +49,12 @@ public class GraphQL {
4449
*
4550
* @deprecated use the {@link #newGraphQL(GraphQLSchema)} builder instead. This will be removed in a future version.
4651
*/
52+
@Internal
4753
public GraphQL(GraphQLSchema graphQLSchema) {
4854
//noinspection deprecation
4955
this(graphQLSchema, null, null);
5056
}
5157

52-
5358
/**
5459
* A GraphQL object ready to execute queries
5560
*
@@ -58,6 +63,7 @@ public GraphQL(GraphQLSchema graphQLSchema) {
5863
*
5964
* @deprecated use the {@link #newGraphQL(GraphQLSchema)} builder instead. This will be removed in a future version.
6065
*/
66+
@Internal
6167
public GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy) {
6268
//noinspection deprecation
6369
this(graphQLSchema, queryStrategy, null);
@@ -72,14 +78,31 @@ public GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy) {
7278
*
7379
* @deprecated use the {@link #newGraphQL(GraphQLSchema)} builder instead. This will be removed in a future version.
7480
*/
81+
@Internal
7582
public GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy, ExecutionStrategy mutationStrategy) {
76-
this(graphQLSchema,queryStrategy,mutationStrategy, DEFAULT_EXECUTION_ID_PROVIDER, NoOpInstrumentation.INSTANCE);
83+
this(graphQLSchema, queryStrategy, mutationStrategy, null, DEFAULT_EXECUTION_ID_PROVIDER, NoOpInstrumentation.INSTANCE);
7784
}
7885

79-
private GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy, ExecutionStrategy mutationStrategy, ExecutionIdProvider idProvider, Instrumentation instrumentation) {
86+
/**
87+
* A GraphQL object ready to execute queries
88+
*
89+
* @param graphQLSchema the schema to use
90+
* @param queryStrategy the query execution strategy to use
91+
* @param mutationStrategy the mutation execution strategy to use
92+
* @param subscriptionStrategy the subscription execution strategy to use
93+
*
94+
* @deprecated use the {@link #newGraphQL(GraphQLSchema)} builder instead. This will be removed in a future version.
95+
*/
96+
@Internal
97+
public GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy, ExecutionStrategy mutationStrategy, ExecutionStrategy subscriptionStrategy) {
98+
this(graphQLSchema, queryStrategy, mutationStrategy, subscriptionStrategy, DEFAULT_EXECUTION_ID_PROVIDER, NoOpInstrumentation.INSTANCE);
99+
}
100+
101+
private GraphQL(GraphQLSchema graphQLSchema, ExecutionStrategy queryStrategy, ExecutionStrategy mutationStrategy, ExecutionStrategy subscriptionStrategy, ExecutionIdProvider idProvider, Instrumentation instrumentation) {
80102
this.graphQLSchema = assertNotNull(graphQLSchema,"queryStrategy must be non null");
81103
this.queryStrategy = queryStrategy != null ? queryStrategy : new SimpleExecutionStrategy();
82104
this.mutationStrategy = mutationStrategy != null ? mutationStrategy : new SimpleExecutionStrategy();
105+
this.subscriptionStrategy = subscriptionStrategy != null ? subscriptionStrategy : new SimpleExecutionStrategy();
83106
this.idProvider = assertNotNull(idProvider, "idProvider must be non null");
84107
this.instrumentation = instrumentation;
85108
}
@@ -96,10 +119,12 @@ public static Builder newGraphQL(GraphQLSchema graphQLSchema) {
96119
}
97120

98121

122+
@PublicApi
99123
public static class Builder {
100124
private GraphQLSchema graphQLSchema;
101125
private ExecutionStrategy queryExecutionStrategy = new SimpleExecutionStrategy();
102126
private ExecutionStrategy mutationExecutionStrategy = new SimpleExecutionStrategy();
127+
private ExecutionStrategy subscriptionExecutionStrategy = new SimpleExecutionStrategy();
103128
private ExecutionIdProvider idProvider = DEFAULT_EXECUTION_ID_PROVIDER;
104129
private Instrumentation instrumentation = NoOpInstrumentation.INSTANCE;
105130

@@ -123,6 +148,11 @@ public Builder mutationExecutionStrategy(ExecutionStrategy executionStrategy) {
123148
return this;
124149
}
125150

151+
public Builder subscriptionExecutionStrategy(ExecutionStrategy executionStrategy) {
152+
this.subscriptionExecutionStrategy = assertNotNull(executionStrategy, "Subscription ExecutionStrategy must be non null");
153+
return this;
154+
}
155+
126156
public Builder instrumentation(Instrumentation instrumentation) {
127157
this.instrumentation = assertNotNull(instrumentation, "Instrumentation must be non null");
128158
return this;
@@ -137,7 +167,7 @@ public GraphQL build() {
137167
assertNotNull(graphQLSchema,"queryStrategy must be non null");
138168
assertNotNull(queryExecutionStrategy, "queryStrategy must be non null");
139169
assertNotNull(idProvider, "idProvider must be non null");
140-
return new GraphQL(graphQLSchema, queryExecutionStrategy, mutationExecutionStrategy, idProvider, instrumentation);
170+
return new GraphQL(graphQLSchema, queryExecutionStrategy, mutationExecutionStrategy, subscriptionExecutionStrategy, idProvider, instrumentation);
141171
}
142172
}
143173

@@ -188,7 +218,7 @@ public ExecutionResult execute(String requestString, String operationName, Objec
188218
}
189219
ExecutionId executionId = idProvider.provide(requestString, operationName, context);
190220

191-
Execution execution = new Execution(queryStrategy, mutationStrategy, instrumentation);
221+
Execution execution = new Execution(queryStrategy, mutationStrategy, subscriptionStrategy, instrumentation);
192222
ExecutionResult result = execution.execute(executionId, graphQLSchema, context, document, operationName, arguments);
193223

194224
executionCtx.onEnd(result);

src/main/java/graphql/GraphQLError.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.util.List;
77

8+
@PublicApi
89
public interface GraphQLError {
910

1011
String getMessage();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package graphql;
2+
3+
import java.lang.annotation.Retention;
4+
import java.lang.annotation.RetentionPolicy;
5+
import java.lang.annotation.Target;
6+
7+
import static java.lang.annotation.ElementType.CONSTRUCTOR;
8+
import static java.lang.annotation.ElementType.METHOD;
9+
import static java.lang.annotation.ElementType.TYPE;
10+
11+
@Retention(RetentionPolicy.RUNTIME)
12+
@Target(value = {CONSTRUCTOR, METHOD, TYPE})
13+
public @interface Internal {
14+
}

0 commit comments

Comments
 (0)