Skip to content

Commit

Permalink
Merge pull request graphql-java#159 from IamCornholio/feature/builder…
Browse files Browse the repository at this point in the history
…-function

Improve schema builders
  • Loading branch information
dminkovsky authored Sep 2, 2016
2 parents cbbe2e2 + be0e7f3 commit 0946f83
Show file tree
Hide file tree
Showing 31 changed files with 430 additions and 421 deletions.
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ public class HelloWorld {
.field(newFieldDefinition()
.type(GraphQLString)
.name("hello")
.staticValue("world")
.build())
.staticValue("world"))
.build();

GraphQLSchema schema = GraphQLSchema.newSchema()
Expand Down Expand Up @@ -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();

```
Expand All @@ -181,8 +178,7 @@ GraphQLInterfaceType comicCharacter = newInterface()
.field(newFieldDefinition()
.name("name")
.description("The name of the character.")
.type(GraphQLString)
.build())
.type(GraphQLString))
.build();

```
Expand Down Expand Up @@ -234,8 +230,7 @@ GraphQLInputObjectType inputObjectType = newInputObject()
.name("inputObjectType")
.field(newInputObjectField()
.name("field")
.type(GraphQLString)
.build())
.type(GraphQLString))
.build()

```
Expand Down Expand Up @@ -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();

```
Expand Down Expand Up @@ -325,8 +319,7 @@ GraphQLObjectType objectType = newObject()
.field(newFieldDefinition()
.name("someComplicatedValue")
.type(GraphQLString)
.dataFetcher(calculateComplicatedValue)
.build())
.dataFetcher(calculateComplicatedValue))
.build();

```
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/graphql/Directives.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand Down
Loading

0 comments on commit 0946f83

Please sign in to comment.