Skip to content

Commit

Permalink
Merge pull request #27 from nfl/update-graphql-java
Browse files Browse the repository at this point in the history
bumping to the latest release of graphql-java
  • Loading branch information
vaant authored Jan 18, 2018
2 parents e6dce74 + 4a5ca54 commit 55ba690
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ repositories {

dependencies {
// GraphQL dependencies
compile("com.graphql-java:graphql-java:6.0")
compile("com.graphql-java:graphql-java:7.0")

// Commons dependencies
compile("org.apache.commons:commons-lang3:3.4")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ maven.central.sync=false
sonatype.username=DUMMY_SONATYPE_USER
sonatype.password=DUMMY_SONATYPE_PASSWORD

PROJECT_VERSION=1.3.0
PROJECT_VERSION=1.4.0
PROJECT_GITHUB_REPO_URL=https://github.com/nfl/glitr
PROJECT_LICENSE_URL=https://github.com/nfl/glitr/blob/master/LICENSE
25 changes: 17 additions & 8 deletions src/main/java/com/nfl/glitr/Glitr.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.nfl.glitr;

import com.nfl.glitr.exception.GlitrException;
import com.nfl.glitr.registry.TypeRegistry;
import com.nfl.glitr.relay.RelayHelper;
import com.nfl.glitr.util.ObjectMapper;
import com.nfl.glitr.util.QueryComplexityCalculator;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;
import graphql.schema.visibility.GraphqlFieldVisibility;

import javax.annotation.Nullable;

Expand All @@ -22,11 +22,11 @@ public class Glitr {
private static ObjectMapper objectMapper;


public Glitr(TypeRegistry typeRegistry, Class queryRoot, @Nullable ObjectMapper objectMapper, @Nullable Class mutationRoot, @Nullable QueryComplexityCalculator queryComplexityCalculator) {
this(typeRegistry, queryRoot, objectMapper, null, mutationRoot, queryComplexityCalculator);
public Glitr(TypeRegistry typeRegistry, Class queryRoot, @Nullable GraphqlFieldVisibility fieldVisibility, @Nullable ObjectMapper objectMapper, @Nullable Class mutationRoot, @Nullable QueryComplexityCalculator queryComplexityCalculator) {
this(typeRegistry, queryRoot, fieldVisibility, objectMapper, null, mutationRoot, queryComplexityCalculator);
}

public Glitr(TypeRegistry typeRegistry, Class queryRoot, @Nullable ObjectMapper objectMapper, @Nullable RelayHelper relayHelper, @Nullable Class mutationRoot, @Nullable QueryComplexityCalculator queryComplexityCalculator) {
public Glitr(TypeRegistry typeRegistry, Class queryRoot, @Nullable GraphqlFieldVisibility fieldVisibility, @Nullable ObjectMapper objectMapper, @Nullable RelayHelper relayHelper, @Nullable Class mutationRoot, @Nullable QueryComplexityCalculator queryComplexityCalculator) {
assertNotNull(typeRegistry, "TypeRegistry can't be null");
assertNotNull(queryRoot, "queryRoot class can't be null");
this.typeRegistry = typeRegistry;
Expand All @@ -37,7 +37,7 @@ public Glitr(TypeRegistry typeRegistry, Class queryRoot, @Nullable ObjectMapper
.withQueryComplexityExcludeNodes(typeRegistry.getQueryComplexityExcludeNodes());
}
Glitr.objectMapper = objectMapper;
this.schema = buildSchema(queryRoot, mutationRoot);
this.schema = buildSchema(queryRoot, mutationRoot, fieldVisibility);
}

public TypeRegistry getTypeRegistry() {
Expand Down Expand Up @@ -65,22 +65,31 @@ public static ObjectMapper getObjectMapper() {
return objectMapper;
}

private GraphQLSchema buildSchema(Class queryRoot, Class mutationRoot) {
private GraphQLSchema buildSchema(Class queryRoot, Class mutationRoot, GraphqlFieldVisibility fieldVisibility) {
// create GraphQL Schema
GraphQLObjectType mutationType = null;
if (mutationRoot != null) {
mutationType = typeRegistry.createRelayMutationType(mutationRoot);
}

GraphQLObjectType queryType = (GraphQLObjectType) typeRegistry.lookup(queryRoot);

if (fieldVisibility != null) {
return GraphQLSchema.newSchema()
.query(queryType)
.mutation(mutationType)
.fieldVisibility(fieldVisibility)
.build(typeRegistry.getTypeDictionary());
}

return GraphQLSchema.newSchema()
.query(queryType)
.mutation(mutationType)
.build(typeRegistry.getTypeDictionary());
}

public GraphQLSchema reloadSchema(Class queryRoot, Class mutationRoot) {
this.schema = buildSchema(queryRoot, mutationRoot);
public GraphQLSchema reloadSchema(Class queryRoot, Class mutationRoot, GraphqlFieldVisibility fieldVisibility) {
this.schema = buildSchema(queryRoot, mutationRoot, fieldVisibility);
return this.schema;
}
}
13 changes: 9 additions & 4 deletions src/main/java/com/nfl/glitr/GlitrBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.nfl.glitr.util.ObjectMapper;
import com.nfl.glitr.util.QueryComplexityCalculator;
import graphql.schema.*;
import graphql.schema.visibility.GraphqlFieldVisibility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rx.functions.Func4;
Expand All @@ -36,6 +37,7 @@ public class GlitrBuilder {
private RelayConfig relayConfig = null;
private Object queryRoot = null;
private Object mutationRoot = null;
private GraphqlFieldVisibility fieldVisibility = null;
private ObjectMapper objectMapper = null;
private QueryComplexityCalculator queryComplexityCalculator;

Expand Down Expand Up @@ -63,6 +65,11 @@ public GlitrBuilder withMutationRoot(Object mutationRoot) {
return this;
}

public GlitrBuilder withFieldVisibility(GraphqlFieldVisibility fieldVisibility) {
this.fieldVisibility = fieldVisibility;
return this;
}

public GlitrBuilder withOverrides(Map<Class, List<Object>> overrides) {
this.overrides = overrides;
return this;
Expand Down Expand Up @@ -146,7 +153,6 @@ public Glitr build() {
}

private Glitr buildGlitr() {

if (objectMapper == null) {
logger.warn("No ObjectMapper instance has been registered.");
}
Expand All @@ -163,11 +169,10 @@ private Glitr buildGlitr() {

Class mutationRootClass = mutationRoot != null ? mutationRoot.getClass() : null;

return new Glitr(typeRegistry, queryRoot.getClass(), objectMapper, null, mutationRootClass, queryComplexityCalculator);
return new Glitr(typeRegistry, queryRoot.getClass(), fieldVisibility, objectMapper, null, mutationRootClass, queryComplexityCalculator);
}

private Glitr buildGlitrWithRelaySupport() {

if (objectMapper == null) {
throw new IllegalArgumentException("No ObjectMapper instance has been registered. It's required to register one when using GLiTR with Relay");
}
Expand Down Expand Up @@ -201,6 +206,6 @@ private Glitr buildGlitrWithRelaySupport() {

Class mutationRootClass = mutationRoot != null ? mutationRoot.getClass() : null;

return new Glitr(typeRegistry, queryRoot.getClass(), objectMapper, relayHelper, mutationRootClass, queryComplexityCalculator);
return new Glitr(typeRegistry, queryRoot.getClass(), fieldVisibility, objectMapper, relayHelper, mutationRootClass, queryComplexityCalculator);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private int calculateMaxDepth(Node queryNode) {
}

int maxChildDepth = 0;
for (Node childNode : queryNode.getChildren()) {
for (Node childNode : (List<Node>) queryNode.getChildren()) {
final int currentChildDepth = calculateMaxDepth(childNode);
maxChildDepth = Math.max(maxChildDepth, currentChildDepth);
}
Expand Down Expand Up @@ -309,7 +309,7 @@ private int queryScore(String path, Node queryNode, int depth) {
}
}

for (Node currentChild : queryNode.getChildren()) {
for (Node currentChild : (List<Node>) queryNode.getChildren()) {
if (currentChild.getClass() == Argument.class) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class GlitrAdditionalTypesTest extends Specification {
when: "add additional types to type registry and reload the schema"
glitr.typeRegistry.lookup(Man.class)
glitr.typeRegistry.lookup(Cyborg.class)
glitr.reloadSchema(QueryRoot.class, null)
glitr.reloadSchema(QueryRoot.class, null, null)
then: "Man and Cyborg are now part of the schema"
glitr.typeRegistry.getType(typeResolutionEnvMan) != null
glitr.typeRegistry.getType(typeResolutionEnvCyborg) != null
Expand Down

0 comments on commit 55ba690

Please sign in to comment.