@@ -34,20 +34,27 @@ class DirectivesSchema {
34
34
private final Collection <RestrictTypeFactory <?>> global ;
35
35
private final Map <Class <? extends Annotation >, DirectiveCaller <?>> targets ;
36
36
private final Collection <Class <? extends Annotation >> directives ;
37
+ private final Collection <Class <? extends Annotation >> jakartaDirectives ;
37
38
private Map <Class <? extends Annotation >, DirectiveProcessor > directiveProcessors ;
38
39
39
40
private DirectivesSchema (
40
41
Collection <RestrictTypeFactory <?>> global ,
41
42
Map <Class <? extends Annotation >, DirectiveCaller <?>> targets ,
42
- Collection <Class <? extends Annotation >> directives
43
+ Collection <Class <? extends Annotation >> directives ,
44
+ Collection <Class <? extends Annotation >> jakartaDirectives
43
45
) {
44
46
this .global = global ;
45
47
this .targets = targets ;
46
48
this .directives = directives ;
49
+ this .jakartaDirectives = jakartaDirectives ;
47
50
}
48
51
49
52
//TODO:mess of exceptions
50
- public static DirectivesSchema build (List <RestrictTypeFactory <?>> globalDirectives , Set <Class <?>> directiveTypes , Set <Class <? extends Annotation >> jakartaDirectiveTypes ) throws ReflectiveOperationException {
53
+ public static DirectivesSchema build (
54
+ List <RestrictTypeFactory <?>> globalDirectives ,
55
+ Set <Class <?>> directiveTypes ,
56
+ Set <Class <?>> jakartaDirectiveTypes
57
+ ) throws ReflectiveOperationException {
51
58
Map <Class <? extends Annotation >, DirectiveCaller <?>> targets = new HashMap <>();
52
59
53
60
Collection <Class <? extends Annotation >> allDirectives = new ArrayList <>();
@@ -70,19 +77,23 @@ public static DirectivesSchema build(List<RestrictTypeFactory<?>> globalDirectiv
70
77
allDirectives .add ((Class <? extends Annotation >) directiveType );
71
78
}
72
79
73
- allDirectives .addAll (jakartaDirectiveTypes );
80
+ Collection <Class <? extends Annotation >> jakartaDirectives = new ArrayList <>();
81
+ for (Class <?> jakartaDirectiveType : jakartaDirectiveTypes ) {
82
+ if (!jakartaDirectiveType .isAnnotation ()) {
83
+ continue ;
84
+ }
85
+ jakartaDirectives .add ((Class <? extends Annotation >) jakartaDirectiveType );
86
+ }
74
87
75
- return new DirectivesSchema (globalDirectives , targets , allDirectives );
88
+ return new DirectivesSchema (globalDirectives , targets , allDirectives , jakartaDirectives );
76
89
}
77
90
78
91
private DirectiveCaller <?> get (Annotation annotation ) {
79
92
return targets .get (annotation .annotationType ());
80
93
}
81
94
82
95
private <T extends Annotation > DataFetcher <?> wrap (DirectiveCaller <T > directive , T annotation , DataFetcher <?> fetcher ) {
83
- return env -> {
84
- return directive .process (annotation , env , fetcher );
85
- };
96
+ return env -> directive .process (annotation , env , fetcher );
86
97
}
87
98
88
99
public Stream <GraphQLDirective > getSchemaDirective () {
@@ -104,18 +115,18 @@ private DataFetcher<?> wrap(RestrictTypeFactory<?> directive, DataFetcher<?> fet
104
115
}
105
116
return applyRestrict (restrict , response );
106
117
} catch (Exception e ) {
107
- if (e instanceof RuntimeException ) {
108
- throw ( RuntimeException ) e ;
118
+ if (e instanceof RuntimeException runtimeException ) {
119
+ throw runtimeException ;
109
120
}
110
121
throw new RuntimeException (e );
111
122
}
112
123
});
113
124
}
114
125
115
126
public boolean target (Method method , TypeMeta meta ) {
116
- for (var global : this .global ) {
127
+ for (var globalRestricts : this .global ) {
117
128
//TODO: extract class
118
- if (global .extractType ().isAssignableFrom (meta .getType ())) {
129
+ if (globalRestricts .extractType ().isAssignableFrom (meta .getType ())) {
119
130
return true ;
120
131
}
121
132
}
@@ -134,15 +145,15 @@ public DataFetcher<?> wrap(Method method, TypeMeta meta, DataFetcher<?> fetcher)
134
145
}
135
146
}
136
147
for (Annotation annotation : method .getAnnotations ()) {
137
- DirectiveCaller directive = ( DirectiveCaller ) get (annotation );
148
+ DirectiveCaller directive = get (annotation );
138
149
if (directive != null ) {
139
150
fetcher = wrap (directive , annotation , fetcher );
140
151
}
141
152
}
142
153
return fetcher ;
143
154
}
144
155
145
- private < T > CompletableFuture <Object > applyRestrict (RestrictType restrict , Object response ) {
156
+ private CompletableFuture <Object > applyRestrict (RestrictType restrict , Object response ) {
146
157
if (response instanceof List ) {
147
158
return restrict .filter ((List ) response );
148
159
} else if (response instanceof Publisher ) {
@@ -193,9 +204,10 @@ public void addSchemaDirective(AnnotatedElement element, Class<?> location, Cons
193
204
}
194
205
195
206
public void processDirectives (EntityProcessor ep ) { // Replacement of processSDL
196
- Map <Class <? extends Annotation >, DirectiveProcessor > directiveProcessors = new HashMap <>();
207
+ Map <Class <? extends Annotation >, DirectiveProcessor > directiveProcessorsList = new HashMap <>();
197
208
198
- this .directives .forEach (dir -> directiveProcessors .put (dir , DirectiveProcessor .build (ep , dir )));
199
- this .directiveProcessors = directiveProcessors ;
209
+ this .directives .forEach (dir -> directiveProcessorsList .put (dir , DirectiveProcessor .build (ep , dir , false )));
210
+ this .jakartaDirectives .forEach (dir -> directiveProcessorsList .put (dir , DirectiveProcessor .build (ep , dir , true )));
211
+ this .directiveProcessors = directiveProcessorsList ;
200
212
}
201
213
}
0 commit comments