Skip to content

Commit 5653b0b

Browse files
committed
add tests
1 parent 0a19ecf commit 5653b0b

File tree

3 files changed

+396
-353
lines changed

3 files changed

+396
-353
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ We now wired the field "name" - so it will turn upper case when calling the fiel
573573
The ``Directive`` annotations requires the name of the directive, the wiring class (the ``UpperWiring`` class defined earlier), and the values of the arguments. If an argument has a default value, you don't have to supply a value in the arguments values.
574574

575575
Notice that in any way, the directives are sequential, so the first annotated directive will happen before the second one.
576+
If put both java annotation directive and `@GraphQLDirectives` annotation directives, the java annotation directive will be applied first.
576577

577578
## Relay support
578579

src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/DirectivesBuilder.java

+34-34
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import static graphql.schema.GraphQLDirective.newDirective;
3636

3737

38-
//todo: add tests for other directive types
3938
public class DirectivesBuilder implements Builder<GraphQLDirective[]> {
4039
private AnnotatedElement object;
4140
private ProcessingElementsContainer container;
@@ -45,6 +44,40 @@ public DirectivesBuilder(AnnotatedElement object, ProcessingElementsContainer co
4544
this.container = container;
4645
}
4746

47+
@Override
48+
public GraphQLDirective[] build() {
49+
// building directives from directives java annotations
50+
List<GraphQLDirective> graphQLDirectives = new ArrayList<>();
51+
DirectiveJavaAnnotationUtil.getDirectiveAnnotations(object)
52+
.forEach(annotation -> {
53+
String name = DirectiveJavaAnnotationUtil.getName(annotation);
54+
if (container.getDirectiveRegistry().containsKey(name)) {
55+
GraphQLDirective graphQLDirective = transformArgs(container.getDirectiveRegistry().get(name).getDirective(), annotation);
56+
graphQLDirectives.add(graphQLDirective);
57+
} else {
58+
throw new GraphQLAnnotationsException(String.format("No directive named %s is found in the directive registry", name), null);
59+
}
60+
});
61+
62+
// building directives from graphql-java-annotations directive annotation
63+
GraphQLDirectives directives = object.getAnnotation(GraphQLDirectives.class);
64+
if (directives != null) {
65+
List<GraphQLDirective> oldGraphQLDirectives = Arrays.stream(directives.value())
66+
.map(x -> {
67+
if (container.getDirectiveRegistry().containsKey(x.name())) {
68+
return transformArgs(container.getDirectiveRegistry().get(x.name()).getDirective(), x.argumentsValues());
69+
} else {
70+
throw new GraphQLAnnotationsException(String.format("No directive named %s is found in the directive registry", x.name()), null);
71+
}
72+
}
73+
).collect(Collectors.toList());
74+
graphQLDirectives.addAll(oldGraphQLDirectives);
75+
}
76+
77+
return graphQLDirectives.toArray(new GraphQLDirective[graphQLDirectives.size()]);
78+
}
79+
80+
4881
private GraphQLDirective transformArgs(GraphQLDirective graphQLDirective, Annotation annotation) {
4982
GraphQLDirective.Builder directiveBuilder = newDirective(graphQLDirective);
5083
directiveBuilder.clearArguments();
@@ -127,37 +160,4 @@ private void transformArgument(String[] argumentValues, GraphQLDirective.Builder
127160
}
128161
}));
129162
}
130-
131-
@Override
132-
public GraphQLDirective[] build() {
133-
// building directives from directives java annotations
134-
List<GraphQLDirective> graphQLDirectives = new ArrayList<>();
135-
DirectiveJavaAnnotationUtil.getDirectiveAnnotations(object)
136-
.forEach(annotation -> {
137-
String name = DirectiveJavaAnnotationUtil.getName(annotation);
138-
if (container.getDirectiveRegistry().containsKey(name)) {
139-
GraphQLDirective graphQLDirective = transformArgs(container.getDirectiveRegistry().get(name).getDirective(), annotation);
140-
graphQLDirectives.add(graphQLDirective);
141-
} else {
142-
throw new GraphQLAnnotationsException(String.format("No directive named %s is found in the directive registry", name), null);
143-
}
144-
});
145-
146-
// building directives from graphql-java-annotations directive annotation
147-
GraphQLDirectives directives = object.getAnnotation(GraphQLDirectives.class);
148-
if (directives != null) {
149-
List<GraphQLDirective> oldGraphQLDirectives = Arrays.stream(directives.value())
150-
.map(x -> {
151-
if (container.getDirectiveRegistry().containsKey(x.name())) {
152-
return transformArgs(container.getDirectiveRegistry().get(x.name()).getDirective(), x.argumentsValues());
153-
} else {
154-
throw new GraphQLAnnotationsException(String.format("No directive named %s is found in the directive registry", x.name()), null);
155-
}
156-
}
157-
).collect(Collectors.toList());
158-
graphQLDirectives.addAll(oldGraphQLDirectives);
159-
}
160-
161-
return graphQLDirectives.toArray(new GraphQLDirective[graphQLDirectives.size()]);
162-
}
163163
}

0 commit comments

Comments
 (0)