Skip to content

Commit d01816c

Browse files
committed
nonNull assertions for schema objects
1 parent 5956895 commit d01816c

23 files changed

+116
-54
lines changed

src/main/java/graphql/introspection/Introspection.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public Object get(DataFetchingEnvironment environment) {
7676
.build())
7777
.field(newFieldDefinition()
7878
.name("type")
79-
.type(new GraphQLNonNull(new GraphQLTypeReference("__TYPE")))
79+
.type(new GraphQLNonNull(new GraphQLTypeReference("__Type")))
8080
.build())
8181
.field(newFieldDefinition()
8282
.name("defaultValue")
@@ -115,7 +115,7 @@ public Object get(DataFetchingEnvironment environment) {
115115
.build())
116116
.field(newFieldDefinition()
117117
.name("type")
118-
.type(new GraphQLNonNull(new GraphQLTypeReference("__TYPE")))
118+
.type(new GraphQLNonNull(new GraphQLTypeReference("__Type")))
119119
.build())
120120
.field(newFieldDefinition()
121121
.name("isDeprecated")
@@ -289,6 +289,7 @@ public Object get(DataFetchingEnvironment environment) {
289289
.build();
290290

291291
public static GraphQLObjectType __Directive = newObject()
292+
.name("__Directive")
292293
.field(newFieldDefinition()
293294
.name("name")
294295
.type(GraphQLString)
@@ -423,6 +424,7 @@ public Object get(DataFetchingEnvironment environment) {
423424
// make sure all TypeReferences are resolved
424425
GraphQLSchema.newSchema()
425426
.query(GraphQLObjectType.newObject()
427+
.name("dummySchema")
426428
.field(SchemaMetaFieldDef)
427429
.field(TypeMetaFieldDef)
428430
.field(TypeNameMetaFieldDef)

src/main/java/graphql/schema/GraphQLArgument.java

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

33

4+
import static graphql.Assert.assertNotNull;
5+
46
public class GraphQLArgument {
57

68
private final String name;
79
private final String description;
810
private GraphQLInputType type;
911
private final Object defaultValue;
1012

11-
public GraphQLArgument(String name, String description, GraphQLInputType graphQLInputType, Object defaultValue) {
13+
public GraphQLArgument(String name, String description, GraphQLInputType type, Object defaultValue) {
14+
assertNotNull(name, "name can't be null");
15+
assertNotNull(type, "type can't be null");
1216
this.name = name;
1317
this.description = description;
14-
this.type = graphQLInputType;
18+
this.type = type;
1519
this.defaultValue = defaultValue;
1620
}
1721

src/main/java/graphql/schema/GraphQLDirective.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.util.ArrayList;
55
import java.util.List;
66

7+
import static graphql.Assert.assertNotNull;
8+
79
public class GraphQLDirective {
810

911
private final String name;
@@ -14,6 +16,8 @@ public class GraphQLDirective {
1416
private final boolean onField;
1517

1618
public GraphQLDirective(String name, String description, List<GraphQLArgument> arguments, boolean onOperation, boolean onFragment, boolean onField) {
19+
assertNotNull(name, "name can't be null");
20+
assertNotNull(arguments, "arguments can't be null");
1721
this.name = name;
1822
this.description = description;
1923
this.arguments.addAll(arguments);

src/main/java/graphql/schema/GraphQLEnumType.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.util.List;
1010
import java.util.Map;
1111

12+
import static graphql.Assert.assertNotNull;
13+
1214
public class GraphQLEnumType implements GraphQLType, GraphQLInputType, GraphQLOutputType, GraphQLUnmodifiedType {
1315

1416
private final String name;
@@ -44,6 +46,7 @@ public List<GraphQLEnumValueDefinition> getValues() {
4446

4547

4648
public GraphQLEnumType(String name, String description, List<GraphQLEnumValueDefinition> values) {
49+
assertNotNull(name, "name can't be null");
4750
this.name = name;
4851
this.description = description;
4952
buildMap(values);

src/main/java/graphql/schema/GraphQLEnumValueDefinition.java

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

33

4+
import static graphql.Assert.assertNotNull;
5+
46
public class GraphQLEnumValueDefinition {
57

68
private final String name;
@@ -9,6 +11,7 @@ public class GraphQLEnumValueDefinition {
911
private final String deprecationReason;
1012

1113
public GraphQLEnumValueDefinition(String name, String description, Object value, String deprecationReason) {
14+
assertNotNull(name, "name can't be null");
1215
this.name = name;
1316
this.description = description;
1417
this.value = value;

src/main/java/graphql/schema/GraphQLFieldDefinition.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.util.List;
66
import java.util.Map;
77

8+
import static graphql.Assert.assertNotNull;
9+
810
public class GraphQLFieldDefinition {
911

1012
private final String name;
@@ -16,13 +18,15 @@ public class GraphQLFieldDefinition {
1618

1719

1820
public GraphQLFieldDefinition(String name, String description, GraphQLOutputType type, DataFetcher dataFetcher, List<GraphQLArgument> arguments, String deprecationReason) {
21+
assertNotNull(name, "name can't be null");
22+
assertNotNull(dataFetcher, "dataFetcher can't be null");
23+
assertNotNull(type, "type can't be null");
24+
assertNotNull(arguments, "arguments can't be null");
1925
this.name = name;
2026
this.description = description;
2127
this.type = type;
2228
this.dataFetcher = dataFetcher;
23-
if (arguments != null) {
24-
this.arguments.addAll(arguments);
25-
}
29+
this.arguments.addAll(arguments);
2630
this.deprecationReason = deprecationReason;
2731
}
2832

src/main/java/graphql/schema/GraphQLInputObjectField.java

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

33

4+
import static graphql.Assert.assertNotNull;
45

56
public class GraphQLInputObjectField {
67

@@ -14,6 +15,8 @@ public GraphQLInputObjectField(String name, GraphQLInputType type) {
1415
}
1516

1617
public GraphQLInputObjectField(String name, String description, GraphQLInputType type, Object defaultValue) {
18+
assertNotNull(name, "name can't be null");
19+
assertNotNull(type, "type can't be null");
1720
this.name = name;
1821
this.type = type;
1922
this.defaultValue = defaultValue;

src/main/java/graphql/schema/GraphQLInputObjectType.java

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

9+
import static graphql.Assert.assertNotNull;
10+
911
public class GraphQLInputObjectType implements GraphQLType, GraphQLInputType, GraphQLUnmodifiedType, GraphQLNullableType {
1012

1113
private final String name;
@@ -15,6 +17,8 @@ public class GraphQLInputObjectType implements GraphQLType, GraphQLInputType, Gr
1517
private final Map<String, GraphQLInputObjectField> fieldMap = new LinkedHashMap<>();
1618

1719
public GraphQLInputObjectType(String name, String description, List<GraphQLInputObjectField> fields) {
20+
assertNotNull(name, "name can't be null");
21+
assertNotNull(fields, "fields can't be null");
1822
this.name = name;
1923
this.description = description;
2024
buildMap(fields);

src/main/java/graphql/schema/GraphQLInterfaceType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@
66
import java.util.List;
77
import java.util.Map;
88

9-
public class GraphQLInterfaceType implements GraphQLType, GraphQLOutputType, GraphQLFieldsContainer, GraphQLCompositeType,GraphQLUnmodifiedType,GraphQLNullableType {
9+
import static graphql.Assert.assertNotNull;
10+
11+
public class GraphQLInterfaceType implements GraphQLType, GraphQLOutputType, GraphQLFieldsContainer, GraphQLCompositeType, GraphQLUnmodifiedType, GraphQLNullableType {
1012

1113
private final String name;
1214
private final String description;
1315
private final Map<String, GraphQLFieldDefinition> fieldDefinitionsByName = new LinkedHashMap<>();
1416
private final TypeResolver typeResolver;
1517

1618
public GraphQLInterfaceType(String name, String description, List<GraphQLFieldDefinition> fieldDefinitions, TypeResolver typeResolver) {
19+
assertNotNull(name, "name can't null");
20+
assertNotNull(typeResolver, "typeResolver can't null");
21+
assertNotNull(fieldDefinitions, "fieldDefinitions can't null");
1722
this.name = name;
1823
this.description = description;
1924
buildDefinitionMap(fieldDefinitions);

src/main/java/graphql/schema/GraphQLList.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33

44
import java.util.Map;
55

6+
import static graphql.Assert.assertNotNull;
7+
68
public class GraphQLList implements GraphQLType, GraphQLInputType, GraphQLOutputType, GraphQLModifiedType, GraphQLNullableType {
79

8-
private GraphQLType wrappedType;
10+
private GraphQLType wrappedType;
911

1012
public GraphQLList(GraphQLType wrappedType) {
13+
assertNotNull(wrappedType, "wrappedType can't be null");
1114
this.wrappedType = wrappedType;
1215
}
1316

0 commit comments

Comments
 (0)