Skip to content

Commit 9895ced

Browse files
author
Theo Zourzouvillys
committed
Use an empty set instead of null.
1 parent 6668d1a commit 9895ced

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/main/java/graphql/schema/GraphQLSchema.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
import java.util.ArrayList;
77
import java.util.Arrays;
8+
import java.util.Collections;
89
import java.util.List;
910
import java.util.Map;
1011
import java.util.Set;
1112

13+
import graphql.Assert;
1214
import graphql.Directives;
1315

1416
public class GraphQLSchema {
@@ -19,14 +21,15 @@ public class GraphQLSchema {
1921
private Set<GraphQLType> dictionary;
2022

2123
public GraphQLSchema(GraphQLObjectType queryType) {
22-
this(queryType, null, null);
24+
this(queryType, null, Collections.<GraphQLType>emptySet());
2325
}
2426

2527
public Set<GraphQLType> getDictionary() {
2628
return dictionary;
2729
}
2830

2931
public GraphQLSchema(GraphQLObjectType queryType, GraphQLObjectType mutationType, Set<GraphQLType> dictionary) {
32+
assertNotNull(dictionary, "dictionary can't be null");
3033
assertNotNull(queryType, "queryType can't be null");
3134
this.queryType = queryType;
3235
this.mutationType = mutationType;
@@ -86,10 +89,11 @@ public Builder mutation(GraphQLObjectType mutationType) {
8689
}
8790

8891
public GraphQLSchema build() {
89-
return build(null);
92+
return build(Collections.<GraphQLType>emptySet());
9093
}
9194

9295
public GraphQLSchema build(Set<GraphQLType> dictionary) {
96+
Assert.assertNotNull(dictionary, "dictionary can't be null");
9397
GraphQLSchema graphQLSchema = new GraphQLSchema(queryType, mutationType, dictionary);
9498
new SchemaUtil().replaceTypeReferences(graphQLSchema);
9599
return graphQLSchema;

src/test/groovy/graphql/schema/SchemaUtilTest.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package graphql.schema
33
import graphql.introspection.Introspection
44
import spock.lang.Specification
55

6+
import java.util.Collections;
7+
68
import static graphql.Scalars.GraphQLBoolean
79
import static graphql.Scalars.GraphQLString
810
import static graphql.StarWarsSchema.*
@@ -11,7 +13,7 @@ class SchemaUtilTest extends Specification {
1113

1214
def "collectAllTypes"() {
1315
when:
14-
Map<String, GraphQLType> types = new SchemaUtil().allTypes(starWarsSchema, null)
16+
Map<String, GraphQLType> types = new SchemaUtil().allTypes(starWarsSchema, Collections.emptySet())
1517
then:
1618
types == [(droidType.name) : droidType,
1719
(humanType.name) : humanType,

0 commit comments

Comments
 (0)