Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,43 @@ GraphQLObjectType person = newObject()
.build();

```


##### Specific Recursive Types

Certain situations require specific type classes as input. For example the possible union types inside a `GraphQLUnionType` are required
to be `GraphQLObjectType` objects. You can't use a `GraphQLTypeReference` in this case as it is not specifically that type.

You can use a `reference` method on each specific type to create a reference to that type.

```java
GraphQLObjectType objectReference = GraphQLObjectType.reference("ObjectReference");
GraphQLInterfaceType interfaceReference = GraphQLInterfaceType.reference("InterfaceReference");
GraphQLInputObjectType inputObjectReference = GraphQLInputObjectType.reference("InputObjectReference");

```

you would use this say like this :

```java
GraphQLUnionType PetType = newUnionType()
.name("Pet")
.possibleType(GraphQLObjectType.reference("Cat"))
.possibleType(DogType)
.typeResolver(new TypeResolver() {
@Override
public GraphQLObjectType getType(Object object) {
if (object instanceof GarfieldSchema.Cat) {
return CatType;
}
if (object instanceof GarfieldSchema.Dog) {
return DogType;
}
return null;
}
})
.build();

```

#### Data fetching

Expand Down
26 changes: 25 additions & 1 deletion src/test/groovy/readme/ReadmeExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public GraphQLObjectType getType(Object object) {
.build();
}


void recursiveTypes() {

GraphQLObjectType person = newObject()
Expand All @@ -142,6 +141,31 @@ void recursiveTypes() {
.build();
}

void recursiveTypesSpecifically() {

GraphQLObjectType objectReference = GraphQLObjectType.reference("ObjectReference");
GraphQLInterfaceType interfaceReference = GraphQLInterfaceType.reference("InterfaceReference");
GraphQLInputObjectType inputObjectReference = GraphQLInputObjectType.reference("InputObjectReference");

GraphQLUnionType PetType = newUnionType()
.name("Pet")
.possibleType(GraphQLObjectType.reference("Cat"))
.possibleType(DogType)
.typeResolver(new TypeResolver() {
@Override
public GraphQLObjectType getType(Object object) {
if (object instanceof GarfieldSchema.Cat) {
return CatType;
}
if (object instanceof GarfieldSchema.Dog) {
return DogType;
}
return null;
}
})
.build();
}

void executionStrategies() {

ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
Expand Down