Skip to content

Commit a683b9e

Browse files
committed
Consolidates all the modified wrappers to use the static constructor for readability
1 parent 6984d3b commit a683b9e

28 files changed

+156
-134
lines changed

docs/schema.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,11 @@ For example:
438438
.. code-block:: java
439439
440440
GraphQLObjectType person = newObject()
441-
.name("Person")
442-
.field(newFieldDefinition()
443-
.name("friends")
444-
.type(new GraphQLList(new GraphQLTypeReference("Person"))))
445-
.build();
441+
.name("Person")
442+
.field(newFieldDefinition()
443+
.name("friends")
444+
.type(GraphQLList.list(GraphQLTypeReference.typeRef("Person"))))
445+
.build();
446446
447447
When the schema is declared via SDL, no special handling of recursive types is needed.
448448

src/main/java/graphql/Directives.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
import graphql.schema.GraphQLDirective;
5-
import graphql.schema.GraphQLNonNull;
65

76
import static graphql.Scalars.GraphQLBoolean;
87
import static graphql.Scalars.GraphQLString;
@@ -11,6 +10,7 @@
1110
import static graphql.introspection.Introspection.DirectiveLocation.FRAGMENT_SPREAD;
1211
import static graphql.introspection.Introspection.DirectiveLocation.INLINE_FRAGMENT;
1312
import static graphql.schema.GraphQLArgument.newArgument;
13+
import static graphql.schema.GraphQLNonNull.nonNull;
1414

1515
/**
1616
* The query directives that are under stood by graphql-java
@@ -22,7 +22,7 @@ public class Directives {
2222
.description("Directs the executor to include this field or fragment only when the `if` argument is true")
2323
.argument(newArgument()
2424
.name("if")
25-
.type(new GraphQLNonNull(GraphQLBoolean))
25+
.type(nonNull(GraphQLBoolean))
2626
.description("Included when true."))
2727
.validLocations(FRAGMENT_SPREAD, INLINE_FRAGMENT, FIELD)
2828
.build();
@@ -32,7 +32,7 @@ public class Directives {
3232
.description("Directs the executor to skip this field or fragment when the `if`'argument is true.")
3333
.argument(newArgument()
3434
.name("if")
35-
.type(new GraphQLNonNull(GraphQLBoolean))
35+
.type(nonNull(GraphQLBoolean))
3636
.description("Skipped when true."))
3737
.validLocations(FRAGMENT_SPREAD, INLINE_FRAGMENT, FIELD)
3838
.build();
@@ -46,7 +46,7 @@ public class Directives {
4646
.description("Directs the SDL type generation to create a data fetcher that uses this `from` argument as the property name")
4747
.argument(newArgument()
4848
.name("from")
49-
.type(new GraphQLNonNull(GraphQLString))
49+
.type(nonNull(GraphQLString))
5050
.description("The `name` used to fetch values from the underlying object"))
5151
.validLocations(FIELD_DEFINITION)
5252
.build();

src/main/java/graphql/execution/TypeFromAST.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
import graphql.language.NonNullType;
77
import graphql.language.Type;
88
import graphql.language.TypeName;
9-
import graphql.schema.GraphQLList;
10-
import graphql.schema.GraphQLNonNull;
119
import graphql.schema.GraphQLSchema;
1210
import graphql.schema.GraphQLType;
1311

12+
import static graphql.schema.GraphQLList.list;
13+
import static graphql.schema.GraphQLNonNull.nonNull;
14+
1415
@Internal
1516
public class TypeFromAST {
1617

@@ -19,10 +20,10 @@ public static GraphQLType getTypeFromAST(GraphQLSchema schema, Type type) {
1920
GraphQLType innerType;
2021
if (type instanceof ListType) {
2122
innerType = getTypeFromAST(schema, ((ListType) type).getType());
22-
return innerType != null ? new GraphQLList(innerType) : null;
23+
return innerType != null ? list(innerType) : null;
2324
} else if (type instanceof NonNullType) {
2425
innerType = getTypeFromAST(schema, ((NonNullType) type).getType());
25-
return innerType != null ? new GraphQLNonNull(innerType) : null;
26+
return innerType != null ? nonNull(innerType) : null;
2627
}
2728

2829
return schema.getType(((TypeName) type).getName());

src/main/java/graphql/relay/Relay.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import static graphql.schema.GraphQLInputObjectField.newInputObjectField;
2727
import static graphql.schema.GraphQLInputObjectType.newInputObject;
2828
import static graphql.schema.GraphQLInterfaceType.newInterface;
29+
import static graphql.schema.GraphQLList.*;
30+
import static graphql.schema.GraphQLNonNull.nonNull;
2931
import static graphql.schema.GraphQLObjectType.newObject;
3032

3133
/**
@@ -44,11 +46,11 @@ public class Relay {
4446
.description("Information about pagination in a connection.")
4547
.field(newFieldDefinition()
4648
.name("hasNextPage")
47-
.type(new GraphQLNonNull(GraphQLBoolean))
49+
.type(nonNull(GraphQLBoolean))
4850
.description("When paginating forwards, are there more items?"))
4951
.field(newFieldDefinition()
5052
.name("hasPreviousPage")
51-
.type(new GraphQLNonNull(GraphQLBoolean))
53+
.type(nonNull(GraphQLBoolean))
5254
.description("When paginating backwards, are there more items?"))
5355
.field(newFieldDefinition()
5456
.name("startCursor")
@@ -68,7 +70,7 @@ public GraphQLInterfaceType nodeInterface(TypeResolver typeResolver) {
6870
.field(newFieldDefinition()
6971
.name("id")
7072
.description("The ID of an object")
71-
.type(new GraphQLNonNull(GraphQLID)))
73+
.type(nonNull(GraphQLID)))
7274
.build();
7375
}
7476

@@ -81,7 +83,7 @@ public GraphQLFieldDefinition nodeField(GraphQLInterfaceType nodeInterface, Data
8183
.argument(newArgument()
8284
.name("id")
8385
.description("The ID of an object")
84-
.type(new GraphQLNonNull(GraphQLID)))
86+
.type(nonNull(GraphQLID)))
8587
.build();
8688
}
8789

@@ -150,7 +152,7 @@ public GraphQLObjectType edgeType(String name, GraphQLOutputType nodeType, Graph
150152
.description("The item at the end of the edge"))
151153
.field(newFieldDefinition()
152154
.name("cursor")
153-
.type(new GraphQLNonNull(GraphQLString))
155+
.type(nonNull(GraphQLString))
154156
.description("cursor marks a unique position or index into the connection"))
155157
.fields(edgeFields)
156158
.build();
@@ -163,11 +165,11 @@ public GraphQLObjectType connectionType(String name, GraphQLObjectType edgeType,
163165
.field(newFieldDefinition()
164166
.name("edges")
165167
.description("a list of edges")
166-
.type(new GraphQLList(edgeType)))
168+
.type(list(edgeType)))
167169
.field(newFieldDefinition()
168170
.name("pageInfo")
169171
.description("details about this specific page")
170-
.type(new GraphQLNonNull(pageInfoType)))
172+
.type(nonNull(pageInfoType)))
171173
.fields(connectionFields)
172174
.build();
173175
}
@@ -213,7 +215,7 @@ public GraphQLFieldDefinition mutation(String name, String fieldName,
213215
.type(outputType)
214216
.argument(newArgument()
215217
.name("input")
216-
.type(new GraphQLNonNull(inputObjectType)))
218+
.type(nonNull(inputObjectType)))
217219
.dataFetcher(dataFetcher)
218220
.build();
219221
}

src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
import static graphql.Assert.assertShouldNeverHappen;
4545
import static graphql.Assert.assertTrue;
46+
import static graphql.schema.GraphQLList.*;
4647
import static java.util.Collections.emptyList;
4748
import static java.util.stream.Collectors.joining;
4849
import static java.util.stream.Collectors.toMap;
@@ -168,7 +169,7 @@ public GraphQLInputType buildDirectiveInputType(Value value) {
168169
}
169170
if (value instanceof ArrayValue) {
170171
ArrayValue arrayValue = (ArrayValue) value;
171-
return new GraphQLList(buildDirectiveInputType(getArrayValueWrappedType(arrayValue)));
172+
return list(buildDirectiveInputType(getArrayValueWrappedType(arrayValue)));
172173
}
173174
return assertShouldNeverHappen("Directive values of type '%s' are not supported yet", value.getClass().getSimpleName());
174175
}

src/main/java/graphql/schema/idl/TypeInfo.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import graphql.language.NonNullType;
77
import graphql.language.Type;
88
import graphql.language.TypeName;
9-
import graphql.schema.GraphQLList;
10-
import graphql.schema.GraphQLNonNull;
119
import graphql.schema.GraphQLType;
1210

1311
import java.util.Objects;
1412
import java.util.Stack;
1513

14+
import static graphql.schema.GraphQLList.list;
15+
import static graphql.schema.GraphQLNonNull.nonNull;
16+
1617
/**
1718
* This helper gives you access to the type info given a type definition
1819
*/
@@ -83,10 +84,10 @@ public <T extends GraphQLType> T decorate(GraphQLType objectType) {
8384
while (!wrappingStack.isEmpty()) {
8485
Class<?> clazz = wrappingStack.pop();
8586
if (clazz.equals(NonNullType.class)) {
86-
out = new GraphQLNonNull(out);
87+
out = nonNull(out);
8788
}
8889
if (clazz.equals(ListType.class)) {
89-
out = new GraphQLList(out);
90+
out = list(out);
9091
}
9192
}
9293
// we handle both input and output graphql types

src/main/java/graphql/validation/rules/VariablesTypesMatcher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import graphql.schema.GraphQLNonNull;
88
import graphql.schema.GraphQLType;
99

10+
import static graphql.schema.GraphQLNonNull.*;
11+
1012
@Internal
1113
public class VariablesTypesMatcher {
1214

@@ -17,7 +19,7 @@ public boolean doesVariableTypesMatch(GraphQLType variableType, Value variableDe
1719
public GraphQLType effectiveType(GraphQLType variableType, Value defaultValue) {
1820
if (defaultValue == null) return variableType;
1921
if (variableType instanceof GraphQLNonNull) return variableType;
20-
return new GraphQLNonNull(variableType);
22+
return nonNull(variableType);
2123
}
2224

2325
private boolean checkType(GraphQLType actualType, GraphQLType expectedType) {

src/test/groovy/graphql/GarfieldSchema.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
import graphql.schema.GraphQLInterfaceType;
5-
import graphql.schema.GraphQLList;
65
import graphql.schema.GraphQLObjectType;
76
import graphql.schema.GraphQLSchema;
87
import graphql.schema.GraphQLUnionType;
@@ -17,6 +16,7 @@
1716
import static graphql.Scalars.GraphQLString;
1817
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
1918
import static graphql.schema.GraphQLInterfaceType.newInterface;
19+
import static graphql.schema.GraphQLList.list;
2020
import static graphql.schema.GraphQLObjectType.newObject;
2121
import static graphql.schema.GraphQLUnionType.newUnionType;
2222

@@ -172,10 +172,10 @@ public GraphQLObjectType getType(TypeResolutionEnvironment env) {
172172
.type(GraphQLString))
173173
.field(newFieldDefinition()
174174
.name("pets")
175-
.type(new GraphQLList(PetType)))
175+
.type(list(PetType)))
176176
.field(newFieldDefinition()
177177
.name("friends")
178-
.type(new GraphQLList(NamedType)))
178+
.type(list(NamedType)))
179179
.withInterface(NamedType)
180180
.build();
181181

src/test/groovy/graphql/GraphQLTest.groovy

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import static graphql.schema.GraphQLArgument.newArgument
3838
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition
3939
import static graphql.schema.GraphQLInputObjectField.newInputObjectField
4040
import static graphql.schema.GraphQLInputObjectType.newInputObject
41+
import static graphql.schema.GraphQLList.list
4142
import static graphql.schema.GraphQLObjectType.newObject
4243
import static graphql.schema.GraphQLSchema.newSchema
4344
import static graphql.schema.GraphQLTypeReference.typeRef
@@ -168,7 +169,7 @@ class GraphQLTest extends Specification {
168169
.type(GraphQLString)
169170
.argument(newArgument()
170171
.name("arg")
171-
.type(new GraphQLNonNull(GraphQLString))))
172+
.type(GraphQLNonNull.nonNull(GraphQLString))))
172173
.build()
173174
).build()
174175

@@ -193,7 +194,7 @@ class GraphQLTest extends Specification {
193194
.name("QueryType")
194195
.field(newFieldDefinition()
195196
.name("set")
196-
.type(new GraphQLList(GraphQLString))
197+
.type(list(GraphQLString))
197198
.dataFetcher({ set })))
198199
.build()
199200

@@ -435,7 +436,7 @@ class GraphQLTest extends Specification {
435436
given:
436437
def dataFetcher = Mock(DataFetcher)
437438
def inputObject = newInputObject().name("bar")
438-
.field(newInputObjectField().name("list").type(new GraphQLList(GraphQLString)).build())
439+
.field(newInputObjectField().name("list").type(list(GraphQLString)).build())
439440
.build()
440441
GraphQLSchema schema = newSchema().query(
441442
newObject()
@@ -466,7 +467,7 @@ class GraphQLTest extends Specification {
466467
given:
467468
def dataFetcher = Mock(DataFetcher)
468469
def inputObject = newInputObject().name("bar")
469-
.field(newInputObjectField().name("list").type(new GraphQLList(GraphQLString)).build())
470+
.field(newInputObjectField().name("list").type(list(GraphQLString)).build())
470471
.build()
471472
GraphQLSchema schema = newSchema().query(
472473
newObject()
@@ -498,7 +499,7 @@ class GraphQLTest extends Specification {
498499
given:
499500
def dataFetcher = Mock(DataFetcher)
500501
def inputObject = newInputObject().name("bar")
501-
.field(newInputObjectField().name("list").type(new GraphQLList(GraphQLString)).build())
502+
.field(newInputObjectField().name("list").type(list(GraphQLString)).build())
502503
.build()
503504
GraphQLSchema schema = newSchema().query(
504505
newObject()

src/test/groovy/graphql/RelaySchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class RelaySchema {
5757
.argument(newArgument()
5858
.name("id")
5959
.description("id of the thing")
60-
.type(new GraphQLNonNull(GraphQLString)))
60+
.type(GraphQLNonNull.nonNull(GraphQLString)))
6161
.dataFetcher(environment -> {
6262
//TODO: implement
6363
return null;

0 commit comments

Comments
 (0)