Skip to content

Commit

Permalink
The CacheControl instance is now defaulted to non null (#1493)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbakerman committed May 14, 2019
1 parent 4fd3721 commit 400d008
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/graphql/ExecutionInput.java
Expand Up @@ -150,7 +150,7 @@ public static class Builder {
private Object root;
private Map<String, Object> variables = Collections.emptyMap();
private DataLoaderRegistry dataLoaderRegistry = new DataLoaderRegistry();
private CacheControl cacheControl;
private CacheControl cacheControl = CacheControl.newCacheControl();

public Builder query(String query) {
this.query = query;
Expand Down Expand Up @@ -209,7 +209,7 @@ public Builder dataLoaderRegistry(DataLoaderRegistry dataLoaderRegistry) {
}

public Builder cacheControl(CacheControl cacheControl) {
this.cacheControl = cacheControl;
this.cacheControl = assertNotNull(cacheControl);
return this;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/graphql/cachecontrol/CacheControl.java
Expand Up @@ -7,9 +7,11 @@
import graphql.schema.DataFetchingEnvironment;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

import static graphql.Assert.assertNotNull;
import static graphql.util.FpKit.map;
Expand Down Expand Up @@ -67,7 +69,7 @@ Map<String, Object> toMap() {
private final List<Hint> hints;

private CacheControl() {
hints = new ArrayList<>();
hints = new CopyOnWriteArrayList<>();
}


Expand Down
3 changes: 3 additions & 0 deletions src/test/groovy/graphql/ExecutionInputTest.groovy
Expand Up @@ -82,5 +82,8 @@ class ExecutionInputTest extends Specification {
def executionInput = ExecutionInput.newExecutionInput("{ q }").build()
then:
executionInput.query == "{ q }"
executionInput.cacheControl != null
executionInput.dataLoaderRegistry != null
executionInput.variables == [:]
}
}
30 changes: 27 additions & 3 deletions src/test/groovy/graphql/schema/idl/WiringFactoryTest.groovy
Expand Up @@ -193,10 +193,10 @@ class WiringFactoryTest extends Specification {

GraphQLObjectType humanType = schema.getType("Human") as GraphQLObjectType

def friendsDataFetcher = schema.getCodeRegistry().getDataFetcher(humanType,humanType.getFieldDefinition("friends")) as NamedDataFetcher
def friendsDataFetcher = schema.getCodeRegistry().getDataFetcher(humanType, humanType.getFieldDefinition("friends")) as NamedDataFetcher
friendsDataFetcher.name == "friends"

def cyborgDataFetcher = schema.getCodeRegistry().getDataFetcher(humanType,humanType.getFieldDefinition("cyborg")) as NamedDataFetcher
def cyborgDataFetcher = schema.getCodeRegistry().getDataFetcher(humanType, humanType.getFieldDefinition("cyborg")) as NamedDataFetcher
cyborgDataFetcher.name == "cyborg"

GraphQLScalarType longScalar = schema.getType("Long") as GraphQLScalarType
Expand Down Expand Up @@ -314,7 +314,7 @@ class WiringFactoryTest extends Specification {
GraphQLObjectType type = schema.getType("Query") as GraphQLObjectType

expect:
def fetcher = schema.getCodeRegistry().getDataFetcher(type,type.getFieldDefinition("homePlanet"))
def fetcher = schema.getCodeRegistry().getDataFetcher(type, type.getFieldDefinition("homePlanet"))
fetcher instanceof PropertyDataFetcher

PropertyDataFetcher propertyDataFetcher = fetcher as PropertyDataFetcher
Expand All @@ -329,4 +329,28 @@ class WiringFactoryTest extends Specification {
propertyDataFetcher2.getPropertyName() == "name"

}

def "Name"() {
WiringFactory wf = new WiringFactory() {
@Override
boolean providesDataFetcherFactory(FieldWiringEnvironment environment) {
def fieldDef = environment.getFieldDefinition();
if (fieldDef.getName() == "class") {
return true;
}
return false;
}

@Override
DataFetcher getDataFetcher(FieldWiringEnvironment environment) {
return new DataFetcher() {
@Override
Object get(DataFetchingEnvironment env) throws Exception {
def sourceObject = env.getSource()
return sourceObject.getClass().getSimpleName()
}
}
}
}
}
}

0 comments on commit 400d008

Please sign in to comment.