Skip to content

Commit b1ee714

Browse files
authored
Merge pull request #3 from nfl/graphiql-fix
latest version of graphiql enforces type on default values, this is an interim fix to enable support
2 parents 804e830 + ffa7c40 commit b1ee714

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ maven.central.sync=false
55
sonatype.username=DUMMY_SONATYPE_USER
66
sonatype.password=DUMMY_SONATYPE_PASSWORD
77

8-
PROJECT_VERSION=1.1.0
8+
PROJECT_VERSION=1.1.1
99
PROJECT_GITHUB_REPO_URL=https://github.com/nfl/glitr
1010
PROJECT_LICENSE_URL=https://github.com/nfl/glitr/blob/master/LICENSE

src/main/java/com/nfl/glitr/annotation/GlitrArgument.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
String name();
2020
Class type();
2121
boolean nullable() default true;
22-
String defaultValue() default "No Default Value";
2322
String description() default "No Description";
23+
24+
String NO_DEFAULT_VALUE = "No Default Value";
25+
String defaultValue() default NO_DEFAULT_VALUE;
2426
}

src/main/java/com/nfl/glitr/registry/TypeRegistry.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public GraphQLType lookupOutput(Class clazz) {
151151
}
152152

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

242+
// Default values need to match type so we replace our default String with null
243+
Object defaultValue = null;
244+
if (!arg.defaultValue().equalsIgnoreCase(GlitrArgument.NO_DEFAULT_VALUE)) {
245+
defaultValue = arg.defaultValue();
246+
}
247+
242248
return newArgument()
243249
.name(arg.name())
244250
.description(arg.description())
245251
.type(inputType)
246-
.defaultValue(arg.defaultValue())
252+
.defaultValue(defaultValue)
247253
.build();
248254
}
249255

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

422-
graphQLOutputType = getGraphQLOutputTypeFromAnnotationsOnGetter(declaringClass, method, null);
428+
graphQLOutputType = getGraphQLOutputTypeFromAnnotationsOnGetter(declaringClass, method);
423429
graphQLOutputType = getGraphQLOutputTypeFromAnnotationsOnField(declaringClass, method, graphQLOutputType, name);
424430

425431
// default OutputType
@@ -468,7 +474,8 @@ private Field getFieldByName(Class declaringClass, String name) {
468474
return field;
469475
}
470476

471-
private GraphQLOutputType getGraphQLOutputTypeFromAnnotationsOnGetter(Class declaringClass, Method method, GraphQLOutputType graphQLOutputType) {
477+
private GraphQLOutputType getGraphQLOutputTypeFromAnnotationsOnGetter(Class declaringClass, Method method) {
478+
GraphQLOutputType graphQLOutputType = null;
472479
Annotation[] methodAnnotations = method.getDeclaredAnnotations();
473480
for (Annotation annotation: methodAnnotations) {
474481
// custom OutputType

0 commit comments

Comments
 (0)