Skip to content

Commit ee80da5

Browse files
author
Thomas Draier
committed
Removed duplicate creation of GraphQLNonNull type. Support only GraphQLNonNull annotation.
1 parent b684e9f commit ee80da5

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

src/main/java/graphql/annotations/DefaultTypeFunction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ public GraphQLType buildType(boolean inputType, Class<?> aClass, AnnotatedType a
328328
}
329329

330330
GraphQLType result = typeFunction.buildType(inputType, aClass, annotatedType);
331-
if (aClass.getAnnotation(GraphQLNonNull.class) != null ||
332-
(annotatedType != null && annotatedType.getAnnotation(GraphQLNonNull.class) != null)) {
331+
if (annotatedType != null && annotatedType.isAnnotationPresent(GraphQLNonNull.class)) {
333332
result = new graphql.schema.GraphQLNonNull(result);
334333
}
335334
return result;

src/main/java/graphql/annotations/GraphQLAnnotations.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.osgi.service.component.annotations.Component;
2222
import org.osgi.service.component.annotations.Reference;
2323

24-
import javax.validation.constraints.NotNull;
2524
import java.lang.reflect.*;
2625
import java.util.*;
2726
import java.util.function.Function;
@@ -471,7 +470,6 @@ protected GraphQLFieldDefinition getField(Field field) throws GraphQLAnnotations
471470
}
472471

473472
GraphQLOutputType outputType = (GraphQLOutputType) typeFunction.buildType(field.getType(), field.getAnnotatedType());
474-
outputType = field.isAnnotationPresent(NotNull.class) ? new GraphQLNonNull(outputType) : outputType;
475473

476474
boolean isConnection = isConnection(field, outputType);
477475
if (isConnection) {
@@ -629,7 +627,6 @@ protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotatio
629627
}
630628

631629
GraphQLOutputType outputType = (GraphQLOutputType) outputTypeFunction.buildType(method.getReturnType(), annotatedReturnType);
632-
outputType = method.getAnnotation(NotNull.class) == null ? outputType : new GraphQLNonNull(outputType);
633630

634631
boolean isConnection = isConnection(method, outputType);
635632
if (isConnection) {
@@ -644,7 +641,7 @@ protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotatio
644641
filter(p -> !DataFetchingEnvironment.class.isAssignableFrom(p.getType())).
645642
map(parameter -> {
646643
Class<?> t = parameter.getType();
647-
graphql.schema.GraphQLType graphQLType = getInputObject(finalTypeFunction.buildType(t, parameter.getAnnotatedType()), DEFAULT_INPUT_PREFIX);
644+
graphql.schema.GraphQLInputType graphQLType = getInputObject(finalTypeFunction.buildType(t, parameter.getAnnotatedType()), DEFAULT_INPUT_PREFIX);
648645
return getArgument(parameter, graphQLType);
649646
}).collect(Collectors.toList());
650647

@@ -755,10 +752,9 @@ public static GraphQLInputObjectType inputObject(GraphQLObjectType graphQLType,
755752
return (GraphQLInputObjectType) getInstance().getInputObject(graphQLType, newNamePrefix);
756753
}
757754

758-
protected GraphQLArgument getArgument(Parameter parameter, graphql.schema.GraphQLType t) throws
755+
protected GraphQLArgument getArgument(Parameter parameter, graphql.schema.GraphQLInputType t) throws
759756
GraphQLAnnotationsException {
760-
GraphQLArgument.Builder builder = newArgument();
761-
builder.type(parameter.getAnnotation(NotNull.class) == null ? (GraphQLInputType) t : new graphql.schema.GraphQLNonNull(t));
757+
GraphQLArgument.Builder builder = newArgument().type(t);
762758
GraphQLDescription description = parameter.getAnnotation(GraphQLDescription.class);
763759
if (description != null) {
764760
builder.description(description.value());

src/main/java/graphql/annotations/GraphQLNonNull.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.lang.annotation.RetentionPolicy;
2020
import java.lang.annotation.Target;
2121

22-
@Target({ElementType.TYPE, ElementType.TYPE_USE, ElementType.METHOD, ElementType.PARAMETER})
22+
@Target({ElementType.FIELD, ElementType.TYPE_USE, ElementType.METHOD, ElementType.PARAMETER})
2323
@Retention(RetentionPolicy.RUNTIME)
2424
public @interface GraphQLNonNull {
2525
}

src/test/java/graphql/annotations/GraphQLObjectTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.testng.annotations.BeforeMethod;
3232
import org.testng.annotations.Test;
3333

34-
import javax.validation.constraints.NotNull;
3534
import java.lang.reflect.AnnotatedType;
3635
import java.util.*;
3736
import java.util.function.Supplier;
@@ -67,13 +66,13 @@ private static class TestObject {
6766
@GraphQLName("field0")
6867
@GraphQLDescription("field")
6968
public
70-
@NotNull
69+
@GraphQLNonNull
7170
String field() {
7271
return "test";
7372
}
7473

7574
@GraphQLField
76-
public String fieldWithArgs(@NotNull String a, @GraphQLDefaultValue(DefaultAValue.class) @GraphQLDescription("b") String b) {
75+
public String fieldWithArgs(@GraphQLNonNull String a, @GraphQLDefaultValue(DefaultAValue.class) @GraphQLDescription("b") String b) {
7776
return b;
7877
}
7978

0 commit comments

Comments
 (0)