Skip to content

Commit f11267f

Browse files
committed
Merge branch 'master' into default-values
2 parents 15a742b + 0a18992 commit f11267f

103 files changed

Lines changed: 1783 additions & 544 deletions

File tree

Some content is hidden

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

‎src/main/java/graphql/Assert.java‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
package graphql;
22

33
import java.util.Collection;
4+
import java.util.function.Supplier;
45

56
import static java.lang.String.format;
67

78
@SuppressWarnings("TypeParameterUnusedInFormals")
89
@Internal
910
public class Assert {
1011

11-
public static <T> T assertNotNull(T object, String format, Object... args) {
12+
public static <T> T assertNotNull(T object, Supplier<String> msg) {
1213
if (object != null) {
1314
return object;
1415
}
15-
throw new AssertException(format(format, args));
16+
throw new AssertException(msg.get());
1617
}
1718

18-
public static <T> T assertNotNullWithNPE(T object, String format, Object... args) {
19+
public static <T> T assertNotNullWithNPE(T object, Supplier<String> msg) {
1920
if (object != null) {
2021
return object;
2122
}
22-
throw new NullPointerException(format(format, args));
23+
throw new NullPointerException(msg.get());
2324
}
2425

2526
public static <T> T assertNotNull(T object) {
@@ -29,11 +30,11 @@ public static <T> T assertNotNull(T object) {
2930
throw new AssertException("Object required to be not null");
3031
}
3132

32-
public static <T> void assertNull(T object, String format, Object... args) {
33+
public static <T> void assertNull(T object, Supplier<String> msg) {
3334
if (object == null) {
3435
return;
3536
}
36-
throw new AssertException(format(format, args));
37+
throw new AssertException(msg.get());
3738
}
3839

3940
public static <T> void assertNull(T object) {
@@ -62,18 +63,18 @@ public static <T> Collection<T> assertNotEmpty(Collection<T> collection) {
6263
return collection;
6364
}
6465

65-
public static <T> Collection<T> assertNotEmpty(Collection<T> collection, String format, Object... args) {
66+
public static <T> Collection<T> assertNotEmpty(Collection<T> collection, Supplier<String> msg) {
6667
if (collection == null || collection.isEmpty()) {
67-
throw new AssertException(format(format, args));
68+
throw new AssertException(msg.get());
6869
}
6970
return collection;
7071
}
7172

72-
public static void assertTrue(boolean condition, String format, Object... args) {
73+
public static void assertTrue(boolean condition, Supplier<String> msg) {
7374
if (condition) {
7475
return;
7576
}
76-
throw new AssertException(format(format, args));
77+
throw new AssertException(msg.get());
7778
}
7879

7980
public static void assertTrue(boolean condition) {
@@ -83,11 +84,18 @@ public static void assertTrue(boolean condition) {
8384
throw new AssertException("condition expected to be true");
8485
}
8586

86-
public static void assertFalse(boolean condition, String format, Object... args) {
87+
public static void assertFalse(boolean condition, Supplier<String> msg) {
8788
if (!condition) {
8889
return;
8990
}
90-
throw new AssertException(format(format, args));
91+
throw new AssertException(msg.get());
92+
}
93+
94+
public static void assertFalse(boolean condition) {
95+
if (!condition) {
96+
return;
97+
}
98+
throw new AssertException("condition expected to be false");
9199
}
92100

93101
private static final String invalidNameErrorMessage = "Name must be non-null, non-empty and match [_A-Za-z][_0-9A-Za-z]* - was '%s'";
@@ -97,7 +105,6 @@ public static void assertFalse(boolean condition, String format, Object... args)
97105
* currently non null, non empty,
98106
*
99107
* @param name - the name to be validated.
100-
*
101108
* @return the name if valid, or AssertException if invalid.
102109
*/
103110
public static String assertValidName(String name) {

‎src/main/java/graphql/Directives.java‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import static graphql.introspection.Introspection.DirectiveLocation.FIELD_DEFINITION;
1111
import static graphql.introspection.Introspection.DirectiveLocation.FRAGMENT_SPREAD;
1212
import static graphql.introspection.Introspection.DirectiveLocation.INLINE_FRAGMENT;
13+
import static graphql.introspection.Introspection.DirectiveLocation.SCALAR;
1314
import static graphql.schema.GraphQLArgument.newArgument;
1415
import static graphql.schema.GraphQLNonNull.nonNull;
1516

@@ -64,11 +65,23 @@ public class Directives {
6465
.description("Marks the field or enum value as deprecated")
6566
.argument(newArgument()
6667
.name("reason")
67-
.type(nonNull(GraphQLString))
68+
.type(GraphQLString)
6869
.defaultValue("No longer supported")
6970
.description("The reason for the deprecation"))
7071
.validLocations(FIELD_DEFINITION, ENUM_VALUE)
7172
.build();
7273

74+
/**
75+
* The "specifiedBy" directive allows to provide a specification URL for a Scalar
76+
*/
77+
public static final GraphQLDirective SpecifiedByDirective = GraphQLDirective.newDirective()
78+
.name("specifiedBy")
79+
.description("Exposes a URL that specifies the behaviour of this scalar.")
80+
.argument(newArgument()
81+
.name("url")
82+
.type(nonNull(GraphQLString))
83+
.description("The URL that specifies the behaviour of this scalar."))
84+
.validLocations(SCALAR)
85+
.build();
7386

7487
}

‎src/main/java/graphql/ExecutionInput.java‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ExecutionInput {
2121
private final String query;
2222
private final String operationName;
2323
private final Object context;
24+
private final Object localContext;
2425
private final Object root;
2526
private final Map<String, Object> variables;
2627
private final DataLoaderRegistry dataLoaderRegistry;
@@ -30,8 +31,8 @@ public class ExecutionInput {
3031

3132

3233
@Internal
33-
private ExecutionInput(String query, String operationName, Object context, Object root, Map<String, Object> variables, DataLoaderRegistry dataLoaderRegistry, CacheControl cacheControl, ExecutionId executionId, Locale locale) {
34-
this.query = assertNotNull(query, "query can't be null");
34+
private ExecutionInput(String query, String operationName, Object context, Object root, Map<String, Object> variables, DataLoaderRegistry dataLoaderRegistry, CacheControl cacheControl, ExecutionId executionId, Locale locale, Object localContext) {
35+
this.query = assertNotNull(query, () -> "query can't be null");
3536
this.operationName = operationName;
3637
this.context = context;
3738
this.root = root;
@@ -40,6 +41,7 @@ private ExecutionInput(String query, String operationName, Object context, Objec
4041
this.cacheControl = cacheControl;
4142
this.executionId = executionId;
4243
this.locale = locale;
44+
this.localContext = localContext;
4345
}
4446

4547
/**
@@ -62,6 +64,12 @@ public String getOperationName() {
6264
public Object getContext() {
6365
return context;
6466
}
67+
/**
68+
* @return the local context object to pass to all top level (i.e. query, mutation, subscription) data fetchers
69+
*/
70+
public Object getLocalContext() {
71+
return localContext;
72+
}
6573

6674
/**
6775
* @return the root object to start the query execution on
@@ -119,6 +127,7 @@ public ExecutionInput transform(Consumer<Builder> builderConsumer) {
119127
.query(this.query)
120128
.operationName(this.operationName)
121129
.context(this.context)
130+
.localContext(this.localContext)
122131
.root(this.root)
123132
.dataLoaderRegistry(this.dataLoaderRegistry)
124133
.cacheControl(this.cacheControl)
@@ -167,6 +176,7 @@ public static class Builder {
167176
private String query;
168177
private String operationName;
169178
private Object context = GraphQLContext.newContext().build();
179+
private Object localContext;
170180
private Object root;
171181
private Map<String, Object> variables = Collections.emptyMap();
172182
//
@@ -179,7 +189,7 @@ public static class Builder {
179189
private ExecutionId executionId;
180190

181191
public Builder query(String query) {
182-
this.query = assertNotNull(query, "query can't be null");
192+
this.query = assertNotNull(query, () -> "query can't be null");
183193
return this;
184194
}
185195

@@ -212,6 +222,15 @@ public Builder locale(Locale locale) {
212222
return this;
213223
}
214224

225+
/**
226+
* Sets initial localContext in root data fetchers
227+
* @return this builder
228+
*/
229+
public Builder localContext(Object localContext) {
230+
this.localContext = localContext;
231+
return this;
232+
}
233+
215234
/**
216235
* By default you will get a {@link GraphQLContext} object but you can set your own.
217236
*
@@ -240,7 +259,7 @@ public Builder root(Object root) {
240259
}
241260

242261
public Builder variables(Map<String, Object> variables) {
243-
this.variables = assertNotNull(variables, "variables map can't be null");
262+
this.variables = assertNotNull(variables, () -> "variables map can't be null");
244263
return this;
245264
}
246265

@@ -263,7 +282,7 @@ public Builder cacheControl(CacheControl cacheControl) {
263282
}
264283

265284
public ExecutionInput build() {
266-
return new ExecutionInput(query, operationName, context, root, variables, dataLoaderRegistry, cacheControl, executionId, locale);
285+
return new ExecutionInput(query, operationName, context, root, variables, dataLoaderRegistry, cacheControl, executionId, locale, localContext);
267286
}
268287
}
269288
}

0 commit comments

Comments
 (0)