Skip to content

Commit be0e7f3

Browse files
author
IamCornholio
committed
Add overrides for incomplete builder and supplier
- Add a jdk8 supplier-esque builder function interface to support lambda builder functions. - Add overridden methods for incomplete builders as parameters that also call .build(). This way users can avoid the awkwardness from syntax such as this .build()).build()).build())... - Add methods to builders in GraphqlQLObjectType, GraphqlInputObjectType, GraphqlFieldDefinition, GraphQLInterfaceType to support lamda builder functions. - Update readme.md samples with new builder syntax - Update all tests to use the builder override
1 parent cbbe2e2 commit be0e7f3

31 files changed

Lines changed: 430 additions & 421 deletions

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ public class HelloWorld {
8888
.field(newFieldDefinition()
8989
.type(GraphQLString)
9090
.name("hello")
91-
.staticValue("world")
92-
.build())
91+
.staticValue("world"))
9392
.build();
9493

9594
GraphQLSchema schema = GraphQLSchema.newSchema()
@@ -160,13 +159,11 @@ GraphQLObjectType simpsonCharacter = newObject()
160159
.field(newFieldDefinition()
161160
.name("name")
162161
.description("The name of the character.")
163-
.type(GraphQLString)
164-
.build())
162+
.type(GraphQLString))
165163
.field(newFieldDefinition()
166164
.name("mainCharacter")
167165
.description("One of the main Simpson characters?")
168-
.type(GraphQLBoolean)
169-
.build())
166+
.type(GraphQLBoolean))
170167
.build();
171168

172169
```
@@ -181,8 +178,7 @@ GraphQLInterfaceType comicCharacter = newInterface()
181178
.field(newFieldDefinition()
182179
.name("name")
183180
.description("The name of the character.")
184-
.type(GraphQLString)
185-
.build())
181+
.type(GraphQLString))
186182
.build();
187183

188184
```
@@ -234,8 +230,7 @@ GraphQLInputObjectType inputObjectType = newInputObject()
234230
.name("inputObjectType")
235231
.field(newInputObjectField()
236232
.name("field")
237-
.type(GraphQLString)
238-
.build())
233+
.type(GraphQLString))
239234
.build()
240235

241236
```
@@ -289,8 +284,7 @@ GraphQLObjectType person = newObject()
289284
.name("Person")
290285
.field(newFieldDefinition()
291286
.name("friends")
292-
.type(new GraphQLList(new GraphQLTypeReference("Person")))
293-
.build())
287+
.type(new GraphQLList(new GraphQLTypeReference("Person"))))
294288
.build();
295289

296290
```
@@ -325,8 +319,7 @@ GraphQLObjectType objectType = newObject()
325319
.field(newFieldDefinition()
326320
.name("someComplicatedValue")
327321
.type(GraphQLString)
328-
.dataFetcher(calculateComplicatedValue)
329-
.build())
322+
.dataFetcher(calculateComplicatedValue))
330323
.build();
331324

332325
```
@@ -355,6 +348,19 @@ It's recommended to use a `ExecutorService` to speed up execution.
355348

356349
Alternatively, schemas with nested lists may benefit from using a BatchedExecutionStrategy and creating batched DataFetchers with get() methods annotated @Batched.
357350

351+
#### JDK8 Lambdas
352+
This project is built using JDK6. But if you're using JDK8 and above then you can also use lambdas.
353+
```java
354+
GraphQLObjectType queryType = newObject()
355+
.name("helloWorldQuery")
356+
.field(field -> field.type(GraphQLString)
357+
.name("hello")
358+
.argument(argument -> argument.name("arg")
359+
.type(GraphQLBoolean))
360+
.dataFetcher(env -> "hello"))
361+
.build();
362+
```
363+
358364
#### Logging
359365

360366
Logging is done with [SLF4J](http://www.slf4j.org/). Please have a look at the [Manual](http://www.slf4j.org/manual.html) for details.

src/main/java/graphql/Directives.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public class Directives {
1616
.argument(newArgument()
1717
.name("if")
1818
.type(new GraphQLNonNull(GraphQLBoolean))
19-
.description("Included when true.")
20-
.build())
19+
.description("Included when true."))
2120
.validLocations(FRAGMENT_SPREAD, INLINE_FRAGMENT, FIELD)
2221
.build();
2322

@@ -27,8 +26,7 @@ public class Directives {
2726
.argument(newArgument()
2827
.name("if")
2928
.type(new GraphQLNonNull(GraphQLBoolean))
30-
.description("Skipped when true.")
31-
.build())
29+
.description("Skipped when true."))
3230
.validLocations(FRAGMENT_SPREAD, INLINE_FRAGMENT, FIELD)
3331
.build();
3432

0 commit comments

Comments
 (0)