diff --git a/README.md b/README.md
index f30341daf4..01343eaa88 100644
--- a/README.md
+++ b/README.md
@@ -88,8 +88,7 @@ public class HelloWorld {
.field(newFieldDefinition()
.type(GraphQLString)
.name("hello")
- .staticValue("world")
- .build())
+ .staticValue("world"))
.build();
GraphQLSchema schema = GraphQLSchema.newSchema()
@@ -160,13 +159,11 @@ GraphQLObjectType simpsonCharacter = newObject()
.field(newFieldDefinition()
.name("name")
.description("The name of the character.")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("mainCharacter")
.description("One of the main Simpson characters?")
- .type(GraphQLBoolean)
- .build())
+ .type(GraphQLBoolean))
.build();
```
@@ -181,8 +178,7 @@ GraphQLInterfaceType comicCharacter = newInterface()
.field(newFieldDefinition()
.name("name")
.description("The name of the character.")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.build();
```
@@ -234,8 +230,7 @@ GraphQLInputObjectType inputObjectType = newInputObject()
.name("inputObjectType")
.field(newInputObjectField()
.name("field")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.build()
```
@@ -289,8 +284,7 @@ GraphQLObjectType person = newObject()
.name("Person")
.field(newFieldDefinition()
.name("friends")
- .type(new GraphQLList(new GraphQLTypeReference("Person")))
- .build())
+ .type(new GraphQLList(new GraphQLTypeReference("Person"))))
.build();
```
@@ -325,8 +319,7 @@ GraphQLObjectType objectType = newObject()
.field(newFieldDefinition()
.name("someComplicatedValue")
.type(GraphQLString)
- .dataFetcher(calculateComplicatedValue)
- .build())
+ .dataFetcher(calculateComplicatedValue))
.build();
```
@@ -355,6 +348,19 @@ It's recommended to use a `ExecutorService` to speed up execution.
Alternatively, schemas with nested lists may benefit from using a BatchedExecutionStrategy and creating batched DataFetchers with get() methods annotated @Batched.
+#### JDK8 Lambdas
+This project is built using JDK6. But if you're using JDK8 and above then you can also use lambdas.
+```java
+GraphQLObjectType queryType = newObject()
+ .name("helloWorldQuery")
+ .field(field -> field.type(GraphQLString)
+ .name("hello")
+ .argument(argument -> argument.name("arg")
+ .type(GraphQLBoolean))
+ .dataFetcher(env -> "hello"))
+ .build();
+```
+
#### Logging
Logging is done with [SLF4J](http://www.slf4j.org/). Please have a look at the [Manual](http://www.slf4j.org/manual.html) for details.
diff --git a/src/main/java/graphql/Directives.java b/src/main/java/graphql/Directives.java
index 277ea6b752..329221ff35 100644
--- a/src/main/java/graphql/Directives.java
+++ b/src/main/java/graphql/Directives.java
@@ -16,8 +16,7 @@ public class Directives {
.argument(newArgument()
.name("if")
.type(new GraphQLNonNull(GraphQLBoolean))
- .description("Included when true.")
- .build())
+ .description("Included when true."))
.validLocations(FRAGMENT_SPREAD, INLINE_FRAGMENT, FIELD)
.build();
@@ -27,8 +26,7 @@ public class Directives {
.argument(newArgument()
.name("if")
.type(new GraphQLNonNull(GraphQLBoolean))
- .description("Skipped when true.")
- .build())
+ .description("Skipped when true."))
.validLocations(FRAGMENT_SPREAD, INLINE_FRAGMENT, FIELD)
.build();
diff --git a/src/main/java/graphql/introspection/Introspection.java b/src/main/java/graphql/introspection/Introspection.java
index c47efba850..771cb124c8 100644
--- a/src/main/java/graphql/introspection/Introspection.java
+++ b/src/main/java/graphql/introspection/Introspection.java
@@ -68,16 +68,13 @@ public Object get(DataFetchingEnvironment environment) {
.name("__InputValue")
.field(newFieldDefinition()
.name("name")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
.field(newFieldDefinition()
.name("description")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("type")
- .type(new GraphQLNonNull(new GraphQLTypeReference("__Type")))
- .build())
+ .type(new GraphQLNonNull(new GraphQLTypeReference("__Type"))))
.field(newFieldDefinition()
.name("defaultValue")
.type(GraphQLString)
@@ -93,8 +90,7 @@ public Object get(DataFetchingEnvironment environment) {
}
return null;
}
- })
- .build())
+ }))
.build();
@@ -102,12 +98,10 @@ public Object get(DataFetchingEnvironment environment) {
.name("__Field")
.field(newFieldDefinition()
.name("name")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
.field(newFieldDefinition()
.name("description")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("args")
.type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(__InputValue))))
@@ -117,12 +111,10 @@ public Object get(DataFetchingEnvironment environment) {
Object type = environment.getSource();
return ((GraphQLFieldDefinition) type).getArguments();
}
- })
- .build())
+ }))
.field(newFieldDefinition()
.name("type")
- .type(new GraphQLNonNull(new GraphQLTypeReference("__Type")))
- .build())
+ .type(new GraphQLNonNull(new GraphQLTypeReference("__Type"))))
.field(newFieldDefinition()
.name("isDeprecated")
.type(new GraphQLNonNull(GraphQLBoolean))
@@ -132,12 +124,10 @@ public Object get(DataFetchingEnvironment environment) {
Object type = environment.getSource();
return ((GraphQLFieldDefinition) type).isDeprecated();
}
- })
- .build())
+ }))
.field(newFieldDefinition()
.name("deprecationReason")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.build();
@@ -145,12 +135,10 @@ public Object get(DataFetchingEnvironment environment) {
.name("__EnumValue")
.field(newFieldDefinition()
.name("name")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
.field(newFieldDefinition()
.name("description")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("isDeprecated")
.type(new GraphQLNonNull(GraphQLBoolean))
@@ -160,12 +148,10 @@ public Object get(DataFetchingEnvironment environment) {
GraphQLEnumValueDefinition enumValue = (GraphQLEnumValueDefinition) environment.getSource();
return enumValue.isDeprecated();
}
- })
- .build())
+ }))
.field(newFieldDefinition()
.name("deprecationReason")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.build();
public static DataFetcher fieldsFetcher = new DataFetcher() {
@@ -261,56 +247,45 @@ public Object get(DataFetchingEnvironment environment) {
.field(newFieldDefinition()
.name("kind")
.type(new GraphQLNonNull(__TypeKind))
- .dataFetcher(kindDataFetcher)
- .build())
+ .dataFetcher(kindDataFetcher))
.field(newFieldDefinition()
.name("name")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("description")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("fields")
.type(new GraphQLList(new GraphQLNonNull(__Field)))
.argument(newArgument()
.name("includeDeprecated")
.type(GraphQLBoolean)
- .defaultValue(false)
- .build())
- .dataFetcher(fieldsFetcher)
- .build())
+ .defaultValue(false))
+ .dataFetcher(fieldsFetcher))
.field(newFieldDefinition()
.name("interfaces")
.type(new GraphQLList(new GraphQLNonNull(new GraphQLTypeReference("__Type"))))
- .dataFetcher(interfacesFetcher)
- .build())
+ .dataFetcher(interfacesFetcher))
.field(newFieldDefinition()
.name("possibleTypes")
.type(new GraphQLList(new GraphQLNonNull(new GraphQLTypeReference("__Type"))))
- .dataFetcher(possibleTypesFetcher)
- .build())
+ .dataFetcher(possibleTypesFetcher))
.field(newFieldDefinition()
.name("enumValues")
.type(new GraphQLList(new GraphQLNonNull(__EnumValue)))
.argument(newArgument()
.name("includeDeprecated")
.type(GraphQLBoolean)
- .defaultValue(false)
- .build())
- .dataFetcher(enumValuesTypesFetcher)
- .build())
+ .defaultValue(false))
+ .dataFetcher(enumValuesTypesFetcher))
.field(newFieldDefinition()
.name("inputFields")
.type(new GraphQLList(new GraphQLNonNull(__InputValue)))
- .dataFetcher(inputFieldsFetcher)
- .build())
+ .dataFetcher(inputFieldsFetcher))
.field(newFieldDefinition()
.name("ofType")
.type(new GraphQLTypeReference("__Type"))
- .dataFetcher(OfTypeFetcher)
- .build())
+ .dataFetcher(OfTypeFetcher))
.build();
public enum DirectiveLocation {
@@ -337,16 +312,13 @@ public enum DirectiveLocation {
.name("__Directive")
.field(newFieldDefinition()
.name("name")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("description")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("locations")
- .type(new GraphQLList(new GraphQLNonNull(__DirectiveLocation)))
- .build())
+ .type(new GraphQLList(new GraphQLNonNull(__DirectiveLocation))))
.field(newFieldDefinition()
.name("args")
.type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(__InputValue))))
@@ -356,23 +328,19 @@ public Object get(DataFetchingEnvironment environment) {
GraphQLDirective directive = (GraphQLDirective) environment.getSource();
return directive.getArguments();
}
- })
- .build())
+ }))
.field(newFieldDefinition()
.name("onOperation")
.type(GraphQLBoolean)
- .deprecate("Use `locations`.")
- .build())
+ .deprecate("Use `locations`."))
.field(newFieldDefinition()
.name("onFragment")
.type(GraphQLBoolean)
- .deprecate("Use `locations`.")
- .build())
+ .deprecate("Use `locations`."))
.field(newFieldDefinition()
.name("onField")
.type(GraphQLBoolean)
- .deprecate("Use `locations`.")
- .build())
+ .deprecate("Use `locations`."))
.build();
public static GraphQLObjectType __Schema = newObject()
@@ -390,8 +358,7 @@ public Object get(DataFetchingEnvironment environment) {
GraphQLSchema schema = (GraphQLSchema) environment.getSource();
return schema.getAllTypesAsList();
}
- })
- .build())
+ }))
.field(newFieldDefinition()
.name("queryType")
.description("The type that query operations will be rooted at.")
@@ -402,8 +369,7 @@ public Object get(DataFetchingEnvironment environment) {
GraphQLSchema schema = (GraphQLSchema) environment.getSource();
return schema.getQueryType();
}
- })
- .build())
+ }))
.field(newFieldDefinition()
.name("mutationType")
.description("If this server supports mutation, the type that mutation operations will be rooted at.")
@@ -414,8 +380,7 @@ public Object get(DataFetchingEnvironment environment) {
GraphQLSchema schema = (GraphQLSchema) environment.getSource();
return schema.getMutationType();
}
- })
- .build())
+ }))
.field(newFieldDefinition()
.name("directives")
.description("'A list of all directives supported by this server.")
@@ -425,8 +390,7 @@ public Object get(DataFetchingEnvironment environment) {
public Object get(DataFetchingEnvironment environment) {
return environment.getGraphQLSchema().getDirectives();
}
- })
- .build())
+ }))
.field(newFieldDefinition()
.name("subscriptionType")
.description("'If this server support subscription, the type that subscription operations will be rooted at.")
@@ -437,8 +401,7 @@ public Object get(DataFetchingEnvironment environment) {
// Not yet supported
return null;
}
- })
- .build())
+ }))
.build();
@@ -451,8 +414,7 @@ public Object get(DataFetchingEnvironment environment) {
public Object get(DataFetchingEnvironment environment) {
return environment.getGraphQLSchema();
}
- })
- .build();
+ }).build();
public static GraphQLFieldDefinition TypeMetaFieldDef = newFieldDefinition()
.name("__type")
@@ -460,16 +422,14 @@ public Object get(DataFetchingEnvironment environment) {
.description("Request the type information of a single type.")
.argument(newArgument()
.name("name")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
.dataFetcher(new DataFetcher() {
@Override
public Object get(DataFetchingEnvironment environment) {
String name = environment.getArgument("name");
return environment.getGraphQLSchema().getType(name);
}
- })
- .build();
+ }).build();
public static GraphQLFieldDefinition TypeNameMetaFieldDef = newFieldDefinition()
.name("__typename")
diff --git a/src/main/java/graphql/relay/Relay.java b/src/main/java/graphql/relay/Relay.java
index ccc1a1bf10..c69673404e 100644
--- a/src/main/java/graphql/relay/Relay.java
+++ b/src/main/java/graphql/relay/Relay.java
@@ -23,23 +23,19 @@ public class Relay {
.field(newFieldDefinition()
.name("hasNextPage")
.type(new GraphQLNonNull(GraphQLBoolean))
- .description("When paginating forwards, are there more items?")
- .build())
+ .description("When paginating forwards, are there more items?"))
.field(newFieldDefinition()
.name("hasPreviousPage")
.type(new GraphQLNonNull(GraphQLBoolean))
- .description("When paginating backwards, are there more items?")
- .build())
+ .description("When paginating backwards, are there more items?"))
.field(newFieldDefinition()
.name("startCursor")
.type(GraphQLString)
- .description("When paginating backwards, the cursor to continue.")
- .build())
+ .description("When paginating backwards, the cursor to continue."))
.field(newFieldDefinition()
.name("endCursor")
.type(GraphQLString)
- .description("When paginating forwards, the cursor to continue.")
- .build())
+ .description("When paginating forwards, the cursor to continue."))
.build();
public GraphQLInterfaceType nodeInterface(TypeResolver typeResolver) {
@@ -50,8 +46,7 @@ public GraphQLInterfaceType nodeInterface(TypeResolver typeResolver) {
.field(newFieldDefinition()
.name("id")
.description("The ID of an object")
- .type(new GraphQLNonNull(GraphQLID))
- .build())
+ .type(new GraphQLNonNull(GraphQLID)))
.build();
return node;
}
@@ -65,8 +60,7 @@ public GraphQLFieldDefinition nodeField(GraphQLInterfaceType nodeInterface, Data
.argument(newArgument()
.name("id")
.description("The ID of an object")
- .type(new GraphQLNonNull(GraphQLID))
- .build())
+ .type(new GraphQLNonNull(GraphQLID)))
.build();
return fieldDefinition;
}
@@ -129,13 +123,11 @@ public GraphQLObjectType edgeType(String name, GraphQLOutputType nodeType, Graph
.field(newFieldDefinition()
.name("node")
.type(nodeType)
- .description("The item at the end of the edge")
- .build())
+ .description("The item at the end of the edge"))
.field(newFieldDefinition()
.name("cursor")
.type(new GraphQLNonNull(GraphQLString))
- .description("")
- .build())
+ .description(""))
.fields(edgeFields)
.build();
return edgeType;
@@ -148,12 +140,10 @@ public GraphQLObjectType connectionType(String name, GraphQLObjectType edgeType,
.description("A connection to a list of items.")
.field(newFieldDefinition()
.name("edges")
- .type(new GraphQLList(edgeType))
- .build())
+ .type(new GraphQLList(edgeType)))
.field(newFieldDefinition()
.name("pageInfo")
- .type(new GraphQLNonNull(pageInfoType))
- .build())
+ .type(new GraphQLNonNull(pageInfoType)))
.fields(connectionFields)
.build();
return connectionType;
@@ -168,16 +158,14 @@ public GraphQLFieldDefinition mutationWithClientMutationId(String name, String f
.name(name + "Input")
.field(newInputObjectField()
.name("clientMutationId")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
.fields(inputFields)
.build();
GraphQLObjectType outputType = newObject()
.name(name + "Payload")
.field(newFieldDefinition()
.name("clientMutationId")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
.fields(outputFields)
.build();
@@ -186,8 +174,7 @@ public GraphQLFieldDefinition mutationWithClientMutationId(String name, String f
.type(outputType)
.argument(newArgument()
.name("input")
- .type(new GraphQLNonNull(inputObjectType))
- .build())
+ .type(new GraphQLNonNull(inputObjectType)))
.dataFetcher(dataFetcher)
.build();
}
diff --git a/src/main/java/graphql/schema/BuilderFunction.java b/src/main/java/graphql/schema/BuilderFunction.java
new file mode 100644
index 0000000000..66b4d4a2e9
--- /dev/null
+++ b/src/main/java/graphql/schema/BuilderFunction.java
@@ -0,0 +1,21 @@
+package graphql.schema;
+
+/**
+ * Provides supplier functionality for those using java 8 without breaking
+ * the contract of jdk 6. Used in a function-esque lambda pattern to
+ * build graphql types. e.g:
+ *
+ * {@code
+ * GraphQLObjectType.Builder obj = GraphQLObjectType.newObject();
+ * obj.field(field -> field
+ * .name("fieldName")
+ * .argument(arg -> arg
+ * .name("argumentName")));
+ * }
+ *
+ *
+ * @param type of result supplied
+ */
+public interface BuilderFunction {
+ T apply(T t);
+}
diff --git a/src/main/java/graphql/schema/GraphQLDirective.java b/src/main/java/graphql/schema/GraphQLDirective.java
index b9f36d93e4..c4733a3913 100644
--- a/src/main/java/graphql/schema/GraphQLDirective.java
+++ b/src/main/java/graphql/schema/GraphQLDirective.java
@@ -117,6 +117,36 @@ public Builder argument(GraphQLArgument fieldArgument) {
return this;
}
+ /**
+ * Take an argument builder in a function definition and apply. Can be used in a jdk8 lambda
+ * e.g.:
+ *
+ * {@code
+ * argument(a -> a.name("argumentName"))
+ * }
+ *
+ *
+ * @param builderFunction a supplier for the builder impl
+ * @return this
+ */
+ public Builder argument(BuilderFunction builderFunction) {
+ GraphQLArgument.Builder builder = GraphQLArgument.newArgument();
+ builder = builderFunction.apply(builder);
+ return argument(builder);
+ }
+
+ /**
+ * Same effect as the argument(GraphQLArgument). Builder.build() is called
+ * from within
+ *
+ * @param builder an un-built/incomplete GraphQLArgument
+ * @return this
+ */
+ public Builder argument(GraphQLArgument.Builder builder) {
+ this.arguments.add(builder.build());
+ return this;
+ }
+
/**
* @deprecated Use {@code graphql.schema.GraphQLDirective.Builder#validLocations(DirectiveLocation...)}
* @param onOperation onOperation
diff --git a/src/main/java/graphql/schema/GraphQLFieldDefinition.java b/src/main/java/graphql/schema/GraphQLFieldDefinition.java
index c2cee5d205..edc6ce1cf3 100644
--- a/src/main/java/graphql/schema/GraphQLFieldDefinition.java
+++ b/src/main/java/graphql/schema/GraphQLFieldDefinition.java
@@ -96,6 +96,18 @@ public Builder description(String description) {
return this;
}
+ public Builder type(GraphQLObjectType.Builder builder) {
+ return type(builder.build());
+ }
+
+ public Builder type(GraphQLInterfaceType.Builder builder) {
+ return type(builder.build());
+ }
+
+ public Builder type(GraphQLUnionType.Builder builder) {
+ return type(builder.build());
+ }
+
public Builder type(GraphQLOutputType type) {
this.type = type;
return this;
@@ -131,6 +143,36 @@ public Builder argument(GraphQLArgument argument) {
return this;
}
+ /**
+ * Take an argument builder in a function definition and apply. Can be used in a jdk8 lambda
+ * e.g.:
+ *
+ * {@code
+ * argument(a -> a.name("argumentName"))
+ * }
+ *
+ *
+ * @param builderFunction a supplier for the builder impl
+ * @return this
+ */
+ public Builder argument(BuilderFunction builderFunction) {
+ GraphQLArgument.Builder builder = GraphQLArgument.newArgument();
+ builder = builderFunction.apply(builder);
+ return argument(builder);
+ }
+
+ /**
+ * Same effect as the argument(GraphQLArgument). Builder.build() is called
+ * from within
+ *
+ * @param builder an un-built/incomplete GraphQLArgument
+ * @return this
+ */
+ public Builder argument(GraphQLArgument.Builder builder) {
+ this.arguments.add(builder.build());
+ return this;
+ }
+
public Builder argument(List arguments) {
this.arguments.addAll(arguments);
return this;
diff --git a/src/main/java/graphql/schema/GraphQLInputObjectField.java b/src/main/java/graphql/schema/GraphQLInputObjectField.java
index c53b360860..53486d2783 100644
--- a/src/main/java/graphql/schema/GraphQLInputObjectField.java
+++ b/src/main/java/graphql/schema/GraphQLInputObjectField.java
@@ -60,6 +60,10 @@ public Builder description(String description) {
return this;
}
+ public Builder type(GraphQLInputObjectType.Builder type) {
+ return type(type.build());
+ }
+
public Builder type(GraphQLInputType type) {
this.type = type;
return this;
diff --git a/src/main/java/graphql/schema/GraphQLInputObjectType.java b/src/main/java/graphql/schema/GraphQLInputObjectType.java
index 96cfd694cd..39457769c4 100644
--- a/src/main/java/graphql/schema/GraphQLInputObjectType.java
+++ b/src/main/java/graphql/schema/GraphQLInputObjectType.java
@@ -75,6 +75,37 @@ public Builder field(GraphQLInputObjectField field) {
return this;
}
+ /**
+ * Take a field builder in a function definition and apply. Can be used in a jdk8 lambda
+ * e.g.:
+ *
+ * {@code
+ * field(f -> f.name("fieldName"))
+ * }
+ *
+ *
+ * @param builderFunction a supplier for the builder impl
+ * @return this
+ */
+ public Builder field(BuilderFunction builderFunction) {
+ assertNotNull(builderFunction, "builderFunction should not be null");
+ GraphQLInputObjectField.Builder builder = GraphQLInputObjectField.newInputObjectField();
+ builder = builderFunction.apply(builder);
+ return field(builder);
+ }
+
+ /**
+ * Same effect as the field(GraphQLFieldDefinition). Builder.build() is called
+ * from within
+ *
+ * @param builder an un-built/incomplete GraphQLFieldDefinition
+ * @return this
+ */
+ public Builder field(GraphQLInputObjectField.Builder builder) {
+ this.fields.add(builder.build());
+ return this;
+ }
+
public Builder fields(List fields) {
for (GraphQLInputObjectField field : fields) {
field(field);
diff --git a/src/main/java/graphql/schema/GraphQLInterfaceType.java b/src/main/java/graphql/schema/GraphQLInterfaceType.java
index d3a432da92..a982301e56 100644
--- a/src/main/java/graphql/schema/GraphQLInterfaceType.java
+++ b/src/main/java/graphql/schema/GraphQLInterfaceType.java
@@ -93,6 +93,37 @@ public Builder field(GraphQLFieldDefinition fieldDefinition) {
return this;
}
+ /**
+ * Take a field builder in a function definition and apply. Can be used in a jdk8 lambda
+ * e.g.:
+ *
+ * {@code
+ * field(f -> f.name("fieldName"))
+ * }
+ *
+ *
+ * @param builderFunction a supplier for the builder impl
+ * @return this
+ */
+ public Builder field(BuilderFunction builderFunction) {
+ assertNotNull(builderFunction, "builderFunction can't be null");
+ GraphQLFieldDefinition.Builder builder = GraphQLFieldDefinition.newFieldDefinition();
+ builder = builderFunction.apply(builder);
+ return field(builder);
+ }
+
+ /**
+ * Same effect as the field(GraphQLFieldDefinition). Builder.build() is called
+ * from within
+ *
+ * @param builder an un-built/incomplete GraphQLFieldDefinition
+ * @return this
+ */
+ public Builder field(GraphQLFieldDefinition.Builder builder) {
+ this.fields.add(builder.build());
+ return this;
+ }
+
public Builder fields(List fieldDefinitions) {
assertNotNull(fieldDefinitions, "fieldDefinitions can't be null");
fields.addAll(fieldDefinitions);
diff --git a/src/main/java/graphql/schema/GraphQLObjectType.java b/src/main/java/graphql/schema/GraphQLObjectType.java
index 04e19b4672..41d8aa99d2 100644
--- a/src/main/java/graphql/schema/GraphQLObjectType.java
+++ b/src/main/java/graphql/schema/GraphQLObjectType.java
@@ -97,6 +97,37 @@ public Builder field(GraphQLFieldDefinition fieldDefinition) {
return this;
}
+ /**
+ * Take a field builder in a function definition and apply. Can be used in a jdk8 lambda
+ * e.g.:
+ *
+ * {@code
+ * field(f -> f.name("fieldName"))
+ * }
+ *
+ *
+ * @param builderFunction a supplier for the builder impl
+ * @return this
+ */
+ public Builder field(BuilderFunction builderFunction) {
+ assertNotNull(builderFunction, "builderFunction can't be null");
+ GraphQLFieldDefinition.Builder builder = GraphQLFieldDefinition.newFieldDefinition();
+ builder = builderFunction.apply(builder);
+ return field(builder.build());
+ }
+
+ /**
+ * Same effect as the field(GraphQLFieldDefinition). Builder.build() is called
+ * from within
+ *
+ * @param builder an un-built/incomplete GraphQLFieldDefinition
+ * @return this
+ */
+ public Builder field(GraphQLFieldDefinition.Builder builder) {
+ this.fieldDefinitions.add(builder.build());
+ return this;
+ }
+
public Builder fields(List fieldDefinitions) {
assertNotNull(fieldDefinitions, "fieldDefinitions can't be null");
this.fieldDefinitions.addAll(fieldDefinitions);
diff --git a/src/main/java/graphql/schema/GraphQLSchema.java b/src/main/java/graphql/schema/GraphQLSchema.java
index c38e3d2311..4858490f69 100644
--- a/src/main/java/graphql/schema/GraphQLSchema.java
+++ b/src/main/java/graphql/schema/GraphQLSchema.java
@@ -73,11 +73,19 @@ public static class Builder {
private GraphQLObjectType queryType;
private GraphQLObjectType mutationType;
+ public Builder query(GraphQLObjectType.Builder builder) {
+ return query(builder.build());
+ }
+
public Builder query(GraphQLObjectType queryType) {
this.queryType = queryType;
return this;
}
+ public Builder mutation(GraphQLObjectType.Builder builder) {
+ return mutation(builder.build());
+ }
+
public Builder mutation(GraphQLObjectType mutationType) {
this.mutationType = mutationType;
return this;
diff --git a/src/test/groovy/graphql/GarfieldSchema.java b/src/test/groovy/graphql/GarfieldSchema.java
index 389d425a32..7f50153089 100644
--- a/src/test/groovy/graphql/GarfieldSchema.java
+++ b/src/test/groovy/graphql/GarfieldSchema.java
@@ -105,8 +105,7 @@ public List getFriends() {
.name("Named")
.field(newFieldDefinition()
.name("name")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.typeResolver(new TypeResolver() {
@Override
public GraphQLObjectType getType(Object object) {
@@ -128,12 +127,10 @@ public GraphQLObjectType getType(Object object) {
.name("Dog")
.field(newFieldDefinition()
.name("name")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("barks")
- .type(GraphQLBoolean)
- .build())
+ .type(GraphQLBoolean))
.withInterface(NamedType)
.build();
@@ -141,12 +138,10 @@ public GraphQLObjectType getType(Object object) {
.name("Cat")
.field(newFieldDefinition()
.name("name")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("meows")
- .type(GraphQLBoolean)
- .build())
+ .type(GraphQLBoolean))
.withInterface(NamedType)
.build();
@@ -172,16 +167,13 @@ public GraphQLObjectType getType(Object object) {
.name("Person")
.field(newFieldDefinition()
.name("name")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("pets")
- .type(new GraphQLList(PetType))
- .build())
+ .type(new GraphQLList(PetType)))
.field(newFieldDefinition()
.name("friends")
- .type(new GraphQLList(NamedType))
- .build())
+ .type(new GraphQLList(NamedType)))
.withInterface(NamedType)
.build();
diff --git a/src/test/groovy/graphql/GraphQLTest.groovy b/src/test/groovy/graphql/GraphQLTest.groovy
index 9e8c4af449..32d35e496c 100644
--- a/src/test/groovy/graphql/GraphQLTest.groovy
+++ b/src/test/groovy/graphql/GraphQLTest.groovy
@@ -19,11 +19,10 @@ class GraphQLTest extends Specification {
def "simple query"() {
given:
- GraphQLFieldDefinition fieldDefinition = newFieldDefinition()
+ GraphQLFieldDefinition.Builder fieldDefinition = newFieldDefinition()
.name("hello")
.type(GraphQLString)
.staticValue("world")
- .build()
GraphQLSchema schema = newSchema().query(
newObject()
.name("RootQueryType")
@@ -46,19 +45,17 @@ class GraphQLTest extends Specification {
.field(
newFieldDefinition()
.name("id")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(
newFieldDefinition()
.name("name")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.build()
- GraphQLFieldDefinition simpsonField = newFieldDefinition()
+ GraphQLFieldDefinition.Builder simpsonField = newFieldDefinition()
.name("simpson")
.type(heroType)
- .staticValue([id: '123', name: 'homer']).build()
+ .staticValue([id: '123', name: 'homer'])
GraphQLSchema graphQLSchema = newSchema().query(
newObject()
@@ -76,12 +73,11 @@ class GraphQLTest extends Specification {
def "query with validation errors"() {
given:
- GraphQLFieldDefinition fieldDefinition = newFieldDefinition()
+ GraphQLFieldDefinition.Builder fieldDefinition = newFieldDefinition()
.name("hello")
.type(GraphQLString)
- .argument(newArgument().name("arg").type(GraphQLString).build())
+ .argument(newArgument().name("arg").type(GraphQLString))
.staticValue("world")
- .build()
GraphQLSchema schema = newSchema().query(
newObject()
.name("RootQueryType")
@@ -140,9 +136,7 @@ class GraphQLTest extends Specification {
.type(GraphQLString)
.argument(newArgument()
.name("arg")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
- .build())
+ .type(new GraphQLNonNull(GraphQLString))))
.build()
).build()
diff --git a/src/test/groovy/graphql/HelloWorld.java b/src/test/groovy/graphql/HelloWorld.java
index 021f94a5a0..10672f2c29 100644
--- a/src/test/groovy/graphql/HelloWorld.java
+++ b/src/test/groovy/graphql/HelloWorld.java
@@ -20,8 +20,7 @@ public static void main(String[] args) {
.field(newFieldDefinition()
.type(GraphQLString)
.name("hello")
- .staticValue("world")
- .build())
+ .staticValue("world"))
.build();
GraphQLSchema schema = GraphQLSchema.newSchema()
@@ -38,8 +37,7 @@ public void helloWorldTest() {
.field(newFieldDefinition()
.type(GraphQLString)
.name("hello")
- .staticValue("world")
- .build())
+ .staticValue("world"))
.build();
GraphQLSchema schema = GraphQLSchema.newSchema()
diff --git a/src/test/groovy/graphql/MutationSchema.java b/src/test/groovy/graphql/MutationSchema.java
index 6dc1c89fd8..fddbab01c4 100644
--- a/src/test/groovy/graphql/MutationSchema.java
+++ b/src/test/groovy/graphql/MutationSchema.java
@@ -55,16 +55,14 @@ public NumberHolder failToChangeTheNumber(int newNumber) {
.name("NumberHolder")
.field(newFieldDefinition()
.name("theNumber")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.build();
public static GraphQLObjectType queryType = GraphQLObjectType.newObject()
.name("queryType")
.field(newFieldDefinition()
.name("numberHolder")
- .type(numberHolderType)
- .build())
+ .type(numberHolderType))
.build();
public static GraphQLObjectType mutationType = GraphQLObjectType.newObject()
@@ -74,8 +72,7 @@ public NumberHolder failToChangeTheNumber(int newNumber) {
.type(numberHolderType)
.argument(newArgument()
.name("newNumber")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.dataFetcher(new DataFetcher() {
@Override
public Object get(DataFetchingEnvironment environment) {
@@ -83,15 +80,13 @@ public Object get(DataFetchingEnvironment environment) {
Root root = (Root) environment.getSource();
return root.changeNumber(newNumber);
}
- })
- .build())
+ }))
.field(newFieldDefinition()
.name("failToChangeTheNumber")
.type(numberHolderType)
.argument(newArgument()
.name("newNumber")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.dataFetcher(new DataFetcher() {
@Override
public Object get(DataFetchingEnvironment environment) {
@@ -99,8 +94,7 @@ public Object get(DataFetchingEnvironment environment) {
Root root = (Root) environment.getSource();
return root.failToChangeTheNumber(newNumber);
}
- })
- .build())
+ }))
.build();
public static GraphQLSchema schema = newSchema()
diff --git a/src/test/groovy/graphql/NestedInputSchema.java b/src/test/groovy/graphql/NestedInputSchema.java
index e142436a5d..7c9209dd49 100644
--- a/src/test/groovy/graphql/NestedInputSchema.java
+++ b/src/test/groovy/graphql/NestedInputSchema.java
@@ -59,13 +59,10 @@ public Object get(DataFetchingEnvironment environment) {
.argument(GraphQLArgument.newArgument()
.name("intialValue")
.type(GraphQLInt)
- .defaultValue(5)
- .build())
+ .defaultValue(5))
.argument(GraphQLArgument.newArgument()
.name("filter")
- .type(filterType())
- .build())
- .build())
+ .type(filterType())))
.build();
}
@@ -74,12 +71,10 @@ public static GraphQLInputObjectType filterType() {
.name("Filter")
.field(GraphQLInputObjectField.newInputObjectField()
.name("even")
- .type(GraphQLBoolean)
- .build())
+ .type(GraphQLBoolean))
.field(GraphQLInputObjectField.newInputObjectField()
.name("range")
- .type(rangeType())
- .build())
+ .type(rangeType()))
.build();
}
@@ -88,12 +83,10 @@ public static GraphQLInputObjectType rangeType() {
.name("Range")
.field(GraphQLInputObjectField.newInputObjectField()
.name("lowerBound")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.field(GraphQLInputObjectField.newInputObjectField()
.name("upperBound")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.build();
}
}
diff --git a/src/test/groovy/graphql/RelaySchema.java b/src/test/groovy/graphql/RelaySchema.java
index 49f543780e..a837c6d5f4 100644
--- a/src/test/groovy/graphql/RelaySchema.java
+++ b/src/test/groovy/graphql/RelaySchema.java
@@ -18,9 +18,7 @@ public class RelaySchema {
.field(newFieldDefinition()
.name("id")
.type(GraphQLString)
- .fetchField()
- .build())
-
+ .fetchField())
.build();
public static GraphQLInterfaceType NodeInterface = relay.nodeInterface(new TypeResolver() {
@@ -41,12 +39,10 @@ public GraphQLObjectType getType(Object object) {
.field(newFieldDefinition()
.name("id")
.type(GraphQLString)
- .fetchField()
- .build())
+ .fetchField())
.field(newFieldDefinition()
.name("stuffs")
- .type(StuffConnectionType)
- .build())
+ .type(StuffConnectionType))
.build();
@@ -65,16 +61,14 @@ public Object get(DataFetchingEnvironment environment) {
.argument(newArgument()
.name("id")
.description("id of the thing")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
.dataFetcher(new DataFetcher() {
@Override
public Object get(DataFetchingEnvironment environment) {
//TODO: implement
return null;
}
- })
- .build())
+ }))
.build();
diff --git a/src/test/groovy/graphql/ScalarsQuerySchema.java b/src/test/groovy/graphql/ScalarsQuerySchema.java
index 136a9ffcca..2baef8b19d 100644
--- a/src/test/groovy/graphql/ScalarsQuerySchema.java
+++ b/src/test/groovy/graphql/ScalarsQuerySchema.java
@@ -25,18 +25,15 @@ public Object get(DataFetchingEnvironment environment) {
.field(newFieldDefinition()
.name("bigInteger")
.type(Scalars.GraphQLBigInteger)
- .staticValue(BigInteger.valueOf(9999))
- .build())
+ .staticValue(BigInteger.valueOf(9999)))
.field(newFieldDefinition()
.name("bigDecimal")
.type(Scalars.GraphQLBigDecimal)
- .staticValue(BigDecimal.valueOf(1234.0))
- .build())
+ .staticValue(BigDecimal.valueOf(1234.0)))
.field(newFieldDefinition()
.name("floatNaN")
.type(Scalars.GraphQLFloat)
- .staticValue(Double.NaN)
- .build())
+ .staticValue(Double.NaN))
@@ -47,38 +44,30 @@ public Object get(DataFetchingEnvironment environment) {
.type(Scalars.GraphQLBigInteger)
.argument(newArgument()
.name("input")
- .type(new GraphQLNonNull(Scalars.GraphQLBigInteger))
- .build())
- .dataFetcher(inputDF)
- .build())
+ .type(new GraphQLNonNull(Scalars.GraphQLBigInteger)))
+ .dataFetcher(inputDF))
.field(newFieldDefinition()
.name("bigDecimalInput")
.type(Scalars.GraphQLBigDecimal)
.argument(newArgument()
.name("input")
- .type(new GraphQLNonNull(Scalars.GraphQLBigDecimal))
- .build())
- .dataFetcher(inputDF)
- .build())
+ .type(new GraphQLNonNull(Scalars.GraphQLBigDecimal)))
+ .dataFetcher(inputDF))
.field(newFieldDefinition()
.name("floatNaNInput")
.type(Scalars.GraphQLFloat)
.argument(newArgument()
.name("input")
- .type(new GraphQLNonNull(Scalars.GraphQLFloat))
- .build())
- .dataFetcher(inputDF)
- .build())
+ .type(new GraphQLNonNull(Scalars.GraphQLFloat)))
+ .dataFetcher(inputDF))
.field(newFieldDefinition()
.name("stringInput")
.type(Scalars.GraphQLString)
.argument(newArgument()
.name("input")
- .type(new GraphQLNonNull(Scalars.GraphQLString))
- .build())
- .dataFetcher(inputDF)
- .build())
-
+ .type(new GraphQLNonNull(Scalars.GraphQLString)))
+ .dataFetcher(inputDF))
+
@@ -90,64 +79,50 @@ public Object get(DataFetchingEnvironment environment) {
.type(Scalars.GraphQLBigInteger)
.argument(newArgument()
.name("input")
- .type(Scalars.GraphQLString)
- .build())
- .dataFetcher(inputDF)
- .build())
+ .type(Scalars.GraphQLString))
+ .dataFetcher(inputDF))
.field(newFieldDefinition()
.name("bigDecimalString")
.type(Scalars.GraphQLBigDecimal)
.argument(newArgument()
.name("input")
- .type(Scalars.GraphQLString)
- .build())
- .dataFetcher(inputDF)
- .build())
+ .type(Scalars.GraphQLString))
+ .dataFetcher(inputDF))
.field(newFieldDefinition()
.name("floatString")
.type(Scalars.GraphQLFloat)
.argument(newArgument()
.name("input")
- .type(Scalars.GraphQLString)
- .build())
- .dataFetcher(inputDF)
- .build())
+ .type(Scalars.GraphQLString))
+ .dataFetcher(inputDF))
.field(newFieldDefinition()
.name("longString")
.type(Scalars.GraphQLLong)
.argument(newArgument()
.name("input")
- .type(Scalars.GraphQLString)
- .build())
- .dataFetcher(inputDF)
- .build())
+ .type(Scalars.GraphQLString))
+ .dataFetcher(inputDF))
.field(newFieldDefinition()
.name("intString")
.type(Scalars.GraphQLInt)
.argument(newArgument()
.name("input")
- .type(Scalars.GraphQLString)
- .build())
- .dataFetcher(inputDF)
- .build())
+ .type(Scalars.GraphQLString))
+ .dataFetcher(inputDF))
.field(newFieldDefinition()
.name("shortString")
.type(Scalars.GraphQLShort)
.argument(newArgument()
.name("input")
- .type(Scalars.GraphQLString)
- .build())
- .dataFetcher(inputDF)
- .build())
+ .type(Scalars.GraphQLString))
+ .dataFetcher(inputDF))
.field(newFieldDefinition()
.name("byteString")
.type(Scalars.GraphQLByte)
.argument(newArgument()
.name("input")
- .type(Scalars.GraphQLString)
- .build())
- .dataFetcher(inputDF)
- .build())
+ .type(Scalars.GraphQLString))
+ .dataFetcher(inputDF))
.build();
diff --git a/src/test/groovy/graphql/StarWarsSchema.java b/src/test/groovy/graphql/StarWarsSchema.java
index 79c9c3c318..3bd1e9a75b 100644
--- a/src/test/groovy/graphql/StarWarsSchema.java
+++ b/src/test/groovy/graphql/StarWarsSchema.java
@@ -28,23 +28,19 @@ public class StarWarsSchema {
.field(newFieldDefinition()
.name("id")
.description("The id of the character.")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
.field(newFieldDefinition()
.name("name")
.description("The name of the character.")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("friends")
.description("The friends of the character, or an empty list if they have none.")
- .type(new GraphQLList(new GraphQLTypeReference("Character")))
- .build())
+ .type(new GraphQLList(new GraphQLTypeReference("Character"))))
.field(newFieldDefinition()
.name("appearsIn")
.description("Which movies they appear in.")
- .type(new GraphQLList(episodeEnum))
- .build())
+ .type(new GraphQLList(episodeEnum)))
.typeResolver(StarWarsData.getCharacterTypeResolver())
.build();
@@ -55,29 +51,24 @@ public class StarWarsSchema {
.field(newFieldDefinition()
.name("id")
.description("The id of the human.")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
.field(newFieldDefinition()
.name("name")
.description("The name of the human.")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("friends")
.description("The friends of the human, or an empty list if they have none.")
.type(new GraphQLList(characterInterface))
- .dataFetcher(StarWarsData.getFriendsDataFetcher())
- .build())
+ .dataFetcher(StarWarsData.getFriendsDataFetcher()))
.field(newFieldDefinition()
.name("appearsIn")
.description("Which movies they appear in.")
- .type(new GraphQLList(episodeEnum))
- .build())
+ .type(new GraphQLList(episodeEnum)))
.field(newFieldDefinition()
.name("homePlanet")
.description("The home planet of the human, or null if unknown.")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.build();
public static GraphQLObjectType droidType = newObject()
@@ -87,29 +78,24 @@ public class StarWarsSchema {
.field(newFieldDefinition()
.name("id")
.description("The id of the droid.")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
.field(newFieldDefinition()
.name("name")
.description("The name of the droid.")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("friends")
.description("The friends of the droid, or an empty list if they have none.")
.type(new GraphQLList(characterInterface))
- .dataFetcher(StarWarsData.getFriendsDataFetcher())
- .build())
+ .dataFetcher(StarWarsData.getFriendsDataFetcher()))
.field(newFieldDefinition()
.name("appearsIn")
.description("Which movies they appear in.")
- .type(new GraphQLList(episodeEnum))
- .build())
+ .type(new GraphQLList(episodeEnum)))
.field(newFieldDefinition()
.name("primaryFunction")
.description("The primary function of the droid.")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.build();
@@ -121,30 +107,24 @@ public class StarWarsSchema {
.argument(newArgument()
.name("episode")
.description("If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode.")
- .type(episodeEnum)
- .build())
- .dataFetcher(new StaticDataFetcher(StarWarsData.getArtoo()))
- .build())
+ .type(episodeEnum))
+ .dataFetcher(new StaticDataFetcher(StarWarsData.getArtoo())))
.field(newFieldDefinition()
.name("human")
.type(humanType)
.argument(newArgument()
.name("id")
.description("id of the human")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
- .dataFetcher(StarWarsData.getHumanDataFetcher())
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
+ .dataFetcher(StarWarsData.getHumanDataFetcher()))
.field(newFieldDefinition()
.name("droid")
.type(droidType)
.argument(newArgument()
.name("id")
.description("id of the droid")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
- .dataFetcher(StarWarsData.getDroidDataFetcher())
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
+ .dataFetcher(StarWarsData.getDroidDataFetcher()))
.build();
diff --git a/src/test/groovy/graphql/TestUtil.groovy b/src/test/groovy/graphql/TestUtil.groovy
index 8b17ca76e5..399e15e979 100644
--- a/src/test/groovy/graphql/TestUtil.groovy
+++ b/src/test/groovy/graphql/TestUtil.groovy
@@ -3,15 +3,15 @@ package graphql
import graphql.schema.*
import static graphql.Scalars.GraphQLString
-
+import static graphql.schema.GraphQLArgument.newArgument
class TestUtil {
static GraphQLSchema schemaWithInputType(GraphQLInputType inputType) {
- GraphQLArgument fieldArgument = new GraphQLArgument("arg", inputType)
- GraphQLFieldDefinition name = GraphQLFieldDefinition.newFieldDefinition()
- .name("name").type(GraphQLString).argument(fieldArgument).build()
+ GraphQLArgument.Builder fieldArgument = newArgument().name("arg").type(inputType)
+ GraphQLFieldDefinition.Builder name = GraphQLFieldDefinition.newFieldDefinition()
+ .name("name").type(GraphQLString).argument(fieldArgument)
GraphQLObjectType queryType = GraphQLObjectType.newObject().name("query").field(name).build()
new GraphQLSchema(queryType)
}
diff --git a/src/test/groovy/graphql/execution/ValuesResolverTest.groovy b/src/test/groovy/graphql/execution/ValuesResolverTest.groovy
index a1c8662765..b97f1628f9 100644
--- a/src/test/groovy/graphql/execution/ValuesResolverTest.groovy
+++ b/src/test/groovy/graphql/execution/ValuesResolverTest.groovy
@@ -43,11 +43,9 @@ class ValuesResolverTest extends Specification {
def nameField = newInputObjectField()
.name("name")
.type(GraphQLString)
- .build()
def idField = newInputObjectField()
.name("id")
.type(GraphQLInt)
- .build()
def inputType = newInputObject()
.name("Person")
.field(nameField)
@@ -103,23 +101,19 @@ class ValuesResolverTest extends Specification {
.name("SubType")
.field(newInputObjectField()
.name("subKey")
- .type(GraphQLBoolean)
- .build())
+ .type(GraphQLBoolean))
.build()
def inputObjectType = newInputObject()
.name("inputObject")
.field(newInputObjectField()
.name("intKey")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.field(newInputObjectField()
.name("stringKey")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newInputObjectField()
.name("subObject")
- .type(subObjectType)
- .build())
+ .type(subObjectType))
.build()
def fieldArgument = new GraphQLArgument("arg", inputObjectType)
@@ -214,13 +208,11 @@ class ValuesResolverTest extends Specification {
.name("InputObject")
.field(newInputObjectField()
.name("intKey")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.field(newInputObjectField()
.name("stringKey")
.type(GraphQLString)
- .defaultValue("defaultString")
- .build())
+ .defaultValue("defaultString"))
.build()
def inputValue = [intKey: 10]
@@ -242,12 +234,10 @@ class ValuesResolverTest extends Specification {
.name("InputObject")
.field(newInputObjectField()
.name("intKey")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.field(newInputObjectField()
.name("requiredField")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
.build()
def inputValue = [intKey: 10]
diff --git a/src/test/groovy/graphql/execution/batched/FunWithStringsSchemaFactory.java b/src/test/groovy/graphql/execution/batched/FunWithStringsSchemaFactory.java
index e0ac768782..de5be5811c 100644
--- a/src/test/groovy/graphql/execution/batched/FunWithStringsSchemaFactory.java
+++ b/src/test/groovy/graphql/execution/batched/FunWithStringsSchemaFactory.java
@@ -231,30 +231,25 @@ GraphQLSchema createSchema() {
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("value")
.type(Scalars.GraphQLString)
- .dataFetcher(stringObjectValueFetcher)
- .build())
+ .dataFetcher(stringObjectValueFetcher))
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("nonNullValue")
.type(new GraphQLNonNull(Scalars.GraphQLString))
- .dataFetcher(stringObjectValueFetcher)
- .build())
+ .dataFetcher(stringObjectValueFetcher))
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("veryNonNullValue")
.type(new GraphQLNonNull(new GraphQLNonNull(Scalars.GraphQLString)))
- .dataFetcher(stringObjectValueFetcher)
- .build())
+ .dataFetcher(stringObjectValueFetcher))
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("shatter")
.type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(new GraphQLTypeReference("StringObject")))))
- .dataFetcher(shatterFetcher)
- .build())
+ .dataFetcher(shatterFetcher))
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("wordsAndLetters")
.type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull( new GraphQLNonNull(new GraphQLTypeReference("StringObject"))))))))
- .dataFetcher(wordsAndLettersFetcher)
- .build())
+ .dataFetcher(wordsAndLettersFetcher))
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("split")
@@ -262,10 +257,8 @@ GraphQLSchema createSchema() {
.type(new GraphQLList(new GraphQLTypeReference("StringObject")))
.argument(GraphQLArgument.newArgument()
.name("regex")
- .type(Scalars.GraphQLString)
- .build())
- .dataFetcher(splitFetcher)
- .build())
+ .type(Scalars.GraphQLString))
+ .dataFetcher(splitFetcher))
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("splitNotNull")
@@ -273,10 +266,8 @@ GraphQLSchema createSchema() {
.type(new GraphQLList(new GraphQLNonNull(new GraphQLTypeReference("StringObject"))))
.argument(GraphQLArgument.newArgument()
.name("regex")
- .type(Scalars.GraphQLString)
- .build())
- .dataFetcher(splitFetcher)
- .build())
+ .type(Scalars.GraphQLString))
+ .dataFetcher(splitFetcher))
.field(GraphQLFieldDefinition.newFieldDefinition()
@@ -284,10 +275,8 @@ GraphQLSchema createSchema() {
.type(new GraphQLTypeReference("StringObject"))
.argument(GraphQLArgument.newArgument()
.name("text")
- .type(Scalars.GraphQLString)
- .build())
- .dataFetcher(appendFetcher)
- .build())
+ .type(Scalars.GraphQLString))
+ .dataFetcher(appendFetcher))
.build();
@@ -306,13 +295,11 @@ GraphQLSchema createSchema() {
.type(stringObjectType)
.argument(GraphQLArgument.newArgument()
.name("value")
- .type(Scalars.GraphQLString)
- .build())
+ .type(Scalars.GraphQLString))
.dataFetcher(new DataFetcher() {
@Override
public Object get(DataFetchingEnvironment env) {return env.getArgument("value");}
- })
- .build())
+ }))
.name("EnumQuery")
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("nullEnum")
@@ -320,8 +307,7 @@ GraphQLSchema createSchema() {
.dataFetcher(new DataFetcher() {
@Override
public Object get(DataFetchingEnvironment env) {return null;}
- })
- .build())
+ }))
.build();
return GraphQLSchema.newSchema()
.query(queryType)
diff --git a/src/test/groovy/graphql/schema/GraphQLInputObjectTypeTest.groovy b/src/test/groovy/graphql/schema/GraphQLInputObjectTypeTest.groovy
index cc3170fddb..8c56ca0454 100644
--- a/src/test/groovy/graphql/schema/GraphQLInputObjectTypeTest.groovy
+++ b/src/test/groovy/graphql/schema/GraphQLInputObjectTypeTest.groovy
@@ -15,8 +15,8 @@ class GraphQLInputObjectTypeTest extends Specification {
def "duplicate field definition fails"() {
when:
newInputObject().name("TestInputObjectType")
- .field(newInputObjectField().name("NAME").type(GraphQLString).build())
- .field(newInputObjectField().name("NAME").type(GraphQLString).build())
+ .field(newInputObjectField().name("NAME").type(GraphQLString))
+ .field(newInputObjectField().name("NAME").type(GraphQLString))
.build();
then:
thrown(AssertException)
diff --git a/src/test/groovy/graphql/schema/GraphQLInterfaceTypeTest.groovy b/src/test/groovy/graphql/schema/GraphQLInterfaceTypeTest.groovy
index ffdd0ec1bd..8f76a27ddc 100644
--- a/src/test/groovy/graphql/schema/GraphQLInterfaceTypeTest.groovy
+++ b/src/test/groovy/graphql/schema/GraphQLInterfaceTypeTest.groovy
@@ -16,8 +16,8 @@ class GraphQLInterfaceTest extends Specification {
when:
newInterface().name("TestInterfaceType")
.typeResolver(new TypeResolverProxy())
- .field(newFieldDefinition().name("NAME").type(GraphQLString).build())
- .field(newFieldDefinition().name("NAME").type(GraphQLString).build())
+ .field(newFieldDefinition().name("NAME").type(GraphQLString))
+ .field(newFieldDefinition().name("NAME").type(GraphQLString))
.build();
then:
thrown(AssertException)
diff --git a/src/test/groovy/graphql/schema/GraphQLObjectTypeTest.groovy b/src/test/groovy/graphql/schema/GraphQLObjectTypeTest.groovy
index 01fae8a613..1b27d16d2a 100644
--- a/src/test/groovy/graphql/schema/GraphQLObjectTypeTest.groovy
+++ b/src/test/groovy/graphql/schema/GraphQLObjectTypeTest.groovy
@@ -15,8 +15,8 @@ class GraphQLObjectTypeTest extends Specification {
def "duplicate field definition fails"() {
when:
newObject().name("TestObjectType")
- .field(newFieldDefinition().name("NAME").type(GraphQLString).build())
- .field(newFieldDefinition().name("NAME").type(GraphQLString).build())
+ .field(newFieldDefinition().name("NAME").type(GraphQLString))
+ .field(newFieldDefinition().name("NAME").type(GraphQLString))
.build();
then:
thrown(AssertException)
diff --git a/src/test/groovy/graphql/validation/TraversalContextTest.groovy b/src/test/groovy/graphql/validation/TraversalContextTest.groovy
index 566e146c70..1db434778d 100644
--- a/src/test/groovy/graphql/validation/TraversalContextTest.groovy
+++ b/src/test/groovy/graphql/validation/TraversalContextTest.groovy
@@ -205,7 +205,7 @@ class TraversalContextTest extends Specification {
def "object field saves input type"() {
given:
- def inputObjectField = GraphQLInputObjectField.newInputObjectField().name("field").type(GraphQLString).build()
+ def inputObjectField = GraphQLInputObjectField.newInputObjectField().name("field").type(GraphQLString)
GraphQLInputObjectType inputObjectType = GraphQLInputObjectType.newInputObject().name("inputObjectType").field(inputObjectField).build()
traversalContext.inputTypeStack.add(inputObjectType);
ObjectField objectField = new ObjectField("field", new StringValue("value"))
diff --git a/src/test/groovy/graphql/validation/ValidationUtilTest.groovy b/src/test/groovy/graphql/validation/ValidationUtilTest.groovy
index 63533a147f..8dd8ec4d54 100644
--- a/src/test/groovy/graphql/validation/ValidationUtilTest.groovy
+++ b/src/test/groovy/graphql/validation/ValidationUtilTest.groovy
@@ -118,8 +118,7 @@ class ValidationUtilTest extends Specification {
.name("inputObjectType")
.field(GraphQLInputObjectField.newInputObjectField()
.name("hello")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.build()
def objectValue = new ObjectValue()
objectValue.getObjectFields().add(new ObjectField("hello", new StringValue("world")))
@@ -134,8 +133,7 @@ class ValidationUtilTest extends Specification {
.name("inputObjectType")
.field(GraphQLInputObjectField.newInputObjectField()
.name("hello")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.build()
def objectValue = new ObjectValue()
objectValue.getObjectFields().add(new ObjectField("hello", new BooleanValue(false)))
@@ -150,8 +148,7 @@ class ValidationUtilTest extends Specification {
.name("inputObjectType")
.field(GraphQLInputObjectField.newInputObjectField()
.name("hello")
- .type(new GraphQLNonNull(GraphQLString))
- .build())
+ .type(new GraphQLNonNull(GraphQLString)))
.build()
def objectValue = new ObjectValue()
diff --git a/src/test/groovy/graphql/validation/rules/Harness.java b/src/test/groovy/graphql/validation/rules/Harness.java
index 3a9b4a6a9a..309aa4ba9e 100644
--- a/src/test/groovy/graphql/validation/rules/Harness.java
+++ b/src/test/groovy/graphql/validation/rules/Harness.java
@@ -26,8 +26,7 @@ public GraphQLObjectType getType(Object object) {
.name("Being")
.field(newFieldDefinition()
.name("name")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.typeResolver(dummyTypeResolve)
.build();
@@ -35,8 +34,7 @@ public GraphQLObjectType getType(Object object) {
.name("Pet")
.field(newFieldDefinition()
.name("name")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.typeResolver(dummyTypeResolve)
.build();
@@ -51,49 +49,38 @@ public GraphQLObjectType getType(Object object) {
.name("Dog")
.field(newFieldDefinition()
.name("name")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("nickName")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("barkVolume")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.field(newFieldDefinition()
.name("barks")
- .type(GraphQLBoolean)
- .build())
+ .type(GraphQLBoolean))
.field(newFieldDefinition()
.name("doesKnowCommand")
.type(GraphQLBoolean)
.argument(newArgument()
.name("dogCommand")
- .type(DogCommand)
- .build())
- .build())
+ .type(DogCommand)))
.field(newFieldDefinition()
.name("isHousetrained")
.type(GraphQLBoolean)
.argument(newArgument()
.name("atOtherHomes")
.type(GraphQLBoolean)
- .defaultValue(true)
- .build())
- .build())
+ .defaultValue(true)))
.field(newFieldDefinition()
.name("isAtLocation")
.type(GraphQLBoolean)
.argument(newArgument()
.name("x")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.argument(newArgument()
.name("y")
- .type(GraphQLInt)
- .build())
- .build())
+ .type(GraphQLInt)))
.withInterface(Being)
.withInterface(Pet)
.build();
@@ -111,24 +98,19 @@ public GraphQLObjectType getType(Object object) {
.name("Cat")
.field(newFieldDefinition()
.name("name")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("nickName")
- .type(GraphQLString)
- .build())
+ .type(GraphQLString))
.field(newFieldDefinition()
.name("meows")
- .type(GraphQLBoolean)
- .build())
+ .type(GraphQLBoolean))
.field(newFieldDefinition()
.name("meowVolume")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.field(newFieldDefinition()
.name("furColor")
- .type(FurColor)
- .build())
+ .type(FurColor))
.withInterfaces(Being, Pet)
.build();
@@ -147,8 +129,7 @@ public GraphQLObjectType getType(Object object) {
.name("Intelligent")
.field(newFieldDefinition()
.name("iq")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.typeResolver(dummyTypeResolve)
.build();
@@ -159,21 +140,16 @@ public GraphQLObjectType getType(Object object) {
.type(GraphQLString)
.argument(newArgument()
.name("surname")
- .type(GraphQLBoolean)
- .build())
- .build())
+ .type(GraphQLBoolean)))
.field(newFieldDefinition()
.name("pets")
- .type(new GraphQLList(Pet))
- .build())
+ .type(new GraphQLList(Pet)))
.field(newFieldDefinition()
.name("relatives")
- .type(new GraphQLList(new GraphQLTypeReference("Human")))
- .build())
+ .type(new GraphQLList(new GraphQLTypeReference("Human"))))
.field(newFieldDefinition()
.name("iq")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.withInterfaces(Being, Intelligent)
.build();
@@ -181,12 +157,10 @@ public GraphQLObjectType getType(Object object) {
.name("Alien")
.field(newFieldDefinition()
.name("numEyes")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.field(newFieldDefinition()
.name("iq")
- .type(GraphQLInt)
- .build())
+ .type(GraphQLInt))
.withInterfaces(Being, Intelligent)
.build();
@@ -229,33 +203,26 @@ public GraphQLObjectType getType(Object object) {
.name("QueryRoot")
.field(newFieldDefinition()
.name("alien")
- .type(Alien)
- .build())
+ .type(Alien))
.field(newFieldDefinition()
.name("dog")
- .type(Dog)
- .build())
+ .type(Dog))
.field(newFieldDefinition()
.name("cat")
- .type(Cat)
- .build())
+ .type(Cat))
.field(newFieldDefinition()
.name("pet")
- .type(Pet)
- .build())
+ .type(Pet))
.field(newFieldDefinition()
.name("catOrDog")
- .type(CatOrDog)
- .build())
+ .type(CatOrDog))
.field(newFieldDefinition()
.name("dogOrHuman")
- .type(DogOrHuman)
- .build())
+ .type(DogOrHuman))
.field(newFieldDefinition()
.name("humanOrAlien")
- .type(HumanOrAlien)
- .build())
+ .type(HumanOrAlien))
.build();
public static GraphQLSchema Schema = newSchema()
diff --git a/src/test/groovy/graphql/validation/rules/OverlappingFieldsCanBeMergedTest.groovy b/src/test/groovy/graphql/validation/rules/OverlappingFieldsCanBeMergedTest.groovy
index 763409b4aa..5f7d8d1ac3 100644
--- a/src/test/groovy/graphql/validation/rules/OverlappingFieldsCanBeMergedTest.groovy
+++ b/src/test/groovy/graphql/validation/rules/OverlappingFieldsCanBeMergedTest.groovy
@@ -28,8 +28,8 @@ class OverlappingFieldsCanBeMergedTest extends Specification {
if (schema == null) {
def objectType = newObject()
.name("Test")
- .field(newFieldDefinition().name("name").type(GraphQLString).build())
- .field(newFieldDefinition().name("nickname").type(GraphQLString).build())
+ .field(newFieldDefinition().name("name").type(GraphQLString))
+ .field(newFieldDefinition().name("nickname").type(GraphQLString))
.build();
schema = GraphQLSchema.newSchema().query(objectType).build()
}
@@ -76,18 +76,18 @@ class OverlappingFieldsCanBeMergedTest extends Specification {
GraphQLSchema unionSchema() {
def StringBox = newObject().name("StringBox")
- .field(newFieldDefinition().name("scalar").type(GraphQLString).build())
+ .field(newFieldDefinition().name("scalar").type(GraphQLString))
.build()
def IntBox = newObject().name("IntBox")
- .field(newFieldDefinition().name("scalar").type(GraphQLInt).build())
+ .field(newFieldDefinition().name("scalar").type(GraphQLInt))
.build()
def NonNullStringBox1 = newObject().name("NonNullStringBox1")
- .field(newFieldDefinition().name("scalar").type(new GraphQLNonNull(GraphQLString)).build())
+ .field(newFieldDefinition().name("scalar").type(new GraphQLNonNull(GraphQLString)))
.build()
def NonNullStringBox2 = newObject().name("NonNullStringBox2")
- .field(newFieldDefinition().name("scalar").type(new GraphQLNonNull(GraphQLString)).build())
+ .field(newFieldDefinition().name("scalar").type(new GraphQLNonNull(GraphQLString)))
.build()
def BoxUnion = newUnionType()
@@ -102,7 +102,7 @@ class OverlappingFieldsCanBeMergedTest extends Specification {
.build()
def QueryRoot = newObject()
.name("QueryRoot")
- .field(newFieldDefinition().name("boxUnion").type(BoxUnion).build()).build()
+ .field(newFieldDefinition().name("boxUnion").type(BoxUnion)).build()
return GraphQLSchema.newSchema().query(QueryRoot).build()
}
diff --git a/src/test/groovy/graphql/validation/rules/ProvidedNonNullArgumentsTest.groovy b/src/test/groovy/graphql/validation/rules/ProvidedNonNullArgumentsTest.groovy
index 964a72419c..79674c4481 100644
--- a/src/test/groovy/graphql/validation/rules/ProvidedNonNullArgumentsTest.groovy
+++ b/src/test/groovy/graphql/validation/rules/ProvidedNonNullArgumentsTest.groovy
@@ -23,7 +23,7 @@ class ProvidedNonNullArgumentsTest extends Specification {
def "not provided field argument"() {
given:
- def fieldArg = GraphQLArgument.newArgument().name("arg").type(new GraphQLNonNull(GraphQLString)).build()
+ def fieldArg = GraphQLArgument.newArgument().name("arg").type(new GraphQLNonNull(GraphQLString))
def fieldDef = GraphQLFieldDefinition.newFieldDefinition()
.name("field")
.type(GraphQLString)
@@ -43,7 +43,7 @@ class ProvidedNonNullArgumentsTest extends Specification {
def "all field arguments are provided"() {
given:
- def fieldArg = GraphQLArgument.newArgument().name("arg").type(new GraphQLNonNull(GraphQLString)).build()
+ def fieldArg = GraphQLArgument.newArgument().name("arg").type(new GraphQLNonNull(GraphQLString))
def fieldDef = GraphQLFieldDefinition.newFieldDefinition()
.name("field")
.type(GraphQLString)
@@ -62,7 +62,7 @@ class ProvidedNonNullArgumentsTest extends Specification {
def "not provided directive argument"() {
given:
- def directiveArg = GraphQLArgument.newArgument().name("arg").type(new GraphQLNonNull(GraphQLString)).build()
+ def directiveArg = GraphQLArgument.newArgument().name("arg").type(new GraphQLNonNull(GraphQLString))
def graphQLDirective = GraphQLDirective.newDirective()
.name("directive")
.argument(directiveArg)
@@ -81,7 +81,7 @@ class ProvidedNonNullArgumentsTest extends Specification {
def "all directive arguments are provided"() {
given:
- def directiveArg = GraphQLArgument.newArgument().name("arg").type(new GraphQLNonNull(GraphQLString)).build()
+ def directiveArg = GraphQLArgument.newArgument().name("arg").type(new GraphQLNonNull(GraphQLString))
def graphQLDirective = GraphQLDirective.newDirective()
.name("directive")
.argument(directiveArg)