Skip to content

Commit

Permalink
Merge pull request #3 from nfl/graphiql-fix
Browse files Browse the repository at this point in the history
latest version of graphiql enforces type on default values, this is an interim fix to enable support
  • Loading branch information
tinnou committed Nov 30, 2016
2 parents 804e830 + ffa7c40 commit b1ee714
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
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.1.0
PROJECT_VERSION=1.1.1
PROJECT_GITHUB_REPO_URL=https://github.com/nfl/glitr
PROJECT_LICENSE_URL=https://github.com/nfl/glitr/blob/master/LICENSE
4 changes: 3 additions & 1 deletion src/main/java/com/nfl/glitr/annotation/GlitrArgument.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
String name();
Class type();
boolean nullable() default true;
String defaultValue() default "No Default Value";
String description() default "No Description";

String NO_DEFAULT_VALUE = "No Default Value";
String defaultValue() default NO_DEFAULT_VALUE;
}
15 changes: 11 additions & 4 deletions src/main/java/com/nfl/glitr/registry/TypeRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public GraphQLType lookupOutput(Class clazz) {
}

/**
* Check if the given class if found the registry, if not, first create it ({@link GraphQLInputType}), next add it
* Check if the given class is found in the registry, if not, first create it ({@link GraphQLInputType}), then add it
* to the registry
*
* @param clazz class on which to preform input introspection
Expand Down Expand Up @@ -239,11 +239,17 @@ private GraphQLArgument createRelayInputArgument(Class methodDeclaringClass, Met
inputType = new GraphQLNonNull(inputType);
}

// Default values need to match type so we replace our default String with null
Object defaultValue = null;
if (!arg.defaultValue().equalsIgnoreCase(GlitrArgument.NO_DEFAULT_VALUE)) {
defaultValue = arg.defaultValue();
}

return newArgument()
.name(arg.name())
.description(arg.description())
.type(inputType)
.defaultValue(arg.defaultValue())
.defaultValue(defaultValue)
.build();
}

Expand Down Expand Up @@ -419,7 +425,7 @@ public GraphQLOutputType retrieveGraphQLOutputType(Class declaringClass, Method
GraphQLOutputType graphQLOutputType;
String name = ReflectionUtil.sanitizeMethodName(method.getName());

graphQLOutputType = getGraphQLOutputTypeFromAnnotationsOnGetter(declaringClass, method, null);
graphQLOutputType = getGraphQLOutputTypeFromAnnotationsOnGetter(declaringClass, method);
graphQLOutputType = getGraphQLOutputTypeFromAnnotationsOnField(declaringClass, method, graphQLOutputType, name);

// default OutputType
Expand Down Expand Up @@ -468,7 +474,8 @@ private Field getFieldByName(Class declaringClass, String name) {
return field;
}

private GraphQLOutputType getGraphQLOutputTypeFromAnnotationsOnGetter(Class declaringClass, Method method, GraphQLOutputType graphQLOutputType) {
private GraphQLOutputType getGraphQLOutputTypeFromAnnotationsOnGetter(Class declaringClass, Method method) {
GraphQLOutputType graphQLOutputType = null;
Annotation[] methodAnnotations = method.getDeclaredAnnotations();
for (Annotation annotation: methodAnnotations) {
// custom OutputType
Expand Down

0 comments on commit b1ee714

Please sign in to comment.