14
14
*/
15
15
package graphql .annotations .processor ;
16
16
17
- import graphql .annotations .processor .exceptions .GraphQLAnnotationsException ;
18
- import graphql .annotations .processor .retrievers .GraphQLObjectHandler ;
19
17
import graphql .annotations .annotationTypes .GraphQLName ;
20
18
import graphql .annotations .annotationTypes .GraphQLTypeExtension ;
19
+ import graphql .annotations .processor .exceptions .GraphQLAnnotationsException ;
21
20
import graphql .annotations .processor .graphQLProcessors .GraphQLAnnotationsProcessor ;
22
21
import graphql .annotations .processor .graphQLProcessors .GraphQLInputProcessor ;
23
22
import graphql .annotations .processor .graphQLProcessors .GraphQLOutputProcessor ;
23
+ import graphql .annotations .processor .retrievers .GraphQLObjectHandler ;
24
24
import graphql .annotations .processor .typeFunctions .DefaultTypeFunction ;
25
25
import graphql .annotations .processor .typeFunctions .TypeFunction ;
26
- import graphql .annotations .processor .retrievers .GraphQLObjectInfoRetriever ;
27
26
import graphql .relay .Relay ;
28
- import graphql .schema .GraphQLFieldDefinition ;
29
27
import graphql .schema .GraphQLObjectType ;
30
28
import org .osgi .service .component .annotations .Component ;
29
+ import org .osgi .service .component .annotations .Reference ;
31
30
32
- import java .util .*;
31
+ import java .util .HashSet ;
32
+ import java .util .Map ;
33
33
34
34
import static graphql .annotations .processor .util .NamingKit .toGraphqlName ;
35
35
@@ -43,26 +43,13 @@ public class GraphQLAnnotations implements GraphQLAnnotationsProcessor {
43
43
private GraphQLObjectHandler graphQLObjectHandler ;
44
44
private ProcessingElementsContainer container ;
45
45
46
- private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever ;
47
-
48
46
public GraphQLAnnotations () {
49
- this (new DefaultTypeFunction (new GraphQLInputProcessor (), new GraphQLOutputProcessor ()), new GraphQLObjectInfoRetriever (), new GraphQLObjectHandler ());
47
+ this (new DefaultTypeFunction (new GraphQLInputProcessor (), new GraphQLOutputProcessor ()), new GraphQLObjectHandler ());
50
48
}
51
49
52
- public GraphQLAnnotations (TypeFunction defaultTypeFunction , GraphQLObjectInfoRetriever graphQLObjectInfoRetriever , GraphQLObjectHandler graphQLObjectHandler ) {
53
- this .graphQLObjectInfoRetriever = graphQLObjectInfoRetriever ;
54
- this .defaultTypeFunction = defaultTypeFunction ;
50
+ public GraphQLAnnotations (TypeFunction defaultTypeFunction , GraphQLObjectHandler graphQLObjectHandler ) {
55
51
this .graphQLObjectHandler = graphQLObjectHandler ;
56
- this .container = initializeContainer (this .defaultTypeFunction );
57
- }
58
-
59
- private ProcessingElementsContainer initializeContainer (TypeFunction defaultTypeFunction ) {
60
- Map <String , graphql .schema .GraphQLType > typeRegistry = new HashMap <>();
61
- Map <Class <?>, Set <Class <?>>> extensionsTypeRegistry = new HashMap <>();
62
- final Stack <String > processing = new Stack <>();
63
- Relay relay = new Relay ();
64
- ProcessingElementsContainer container = new ProcessingElementsContainer (defaultTypeFunction , relay , typeRegistry , extensionsTypeRegistry , processing );
65
- return container ;
52
+ this .container = new ProcessingElementsContainer (defaultTypeFunction );
66
53
}
67
54
68
55
public static GraphQLAnnotations instance = new GraphQLAnnotations ();
@@ -75,32 +62,16 @@ public void setRelay(Relay relay) {
75
62
this .container .setRelay (relay );
76
63
}
77
64
78
-
79
65
public String getTypeName (Class <?> objectClass ) {
80
66
GraphQLName name = objectClass .getAnnotation (GraphQLName .class );
81
67
return toGraphqlName (name == null ? objectClass .getSimpleName () : name .value ());
82
68
}
83
69
84
70
public static GraphQLObjectType object (Class <?> object ) throws GraphQLAnnotationsException {
85
- return new GraphQLObjectHandler ().getObject (object , getInstance ().getContainer ());
86
- }
87
-
88
- public static class GraphQLFieldDefinitionWrapper extends GraphQLFieldDefinition {
89
-
90
- public GraphQLFieldDefinitionWrapper (GraphQLFieldDefinition fieldDefinition ) {
91
- super (fieldDefinition .getName (), fieldDefinition .getDescription (), fieldDefinition .getType (),
92
- fieldDefinition .getDataFetcher (), fieldDefinition .getArguments (), fieldDefinition .getDeprecationReason ());
93
- }
94
-
95
- @ Override
96
- public boolean equals (Object obj ) {
97
- return obj instanceof GraphQLFieldDefinition &&
98
- ((GraphQLFieldDefinition ) obj ).getName ().contentEquals (getName ());
99
- }
71
+ GraphQLAnnotations instance = getInstance ();
72
+ return instance .graphQLObjectHandler .getObject (object , instance .getContainer ());
100
73
}
101
74
102
- protected TypeFunction defaultTypeFunction ;
103
-
104
75
public void registerTypeExtension (Class <?> objectClass ) {
105
76
GraphQLTypeExtension typeExtension = objectClass .getAnnotation (GraphQLTypeExtension .class );
106
77
if (typeExtension == null ) {
@@ -127,7 +98,7 @@ public void unregisterTypeExtension(Class<?> objectClass) {
127
98
}
128
99
129
100
public void registerType (TypeFunction typeFunction ) {
130
- ((DefaultTypeFunction ) defaultTypeFunction ).register (typeFunction );
101
+ ((DefaultTypeFunction ) container . getDefaultTypeFunction () ).register (typeFunction );
131
102
}
132
103
133
104
public static void register (TypeFunction typeFunction ) {
@@ -142,4 +113,13 @@ public ProcessingElementsContainer getContainer() {
142
113
return container ;
143
114
}
144
115
116
+ public void setContainer (ProcessingElementsContainer container ) {
117
+ this .container = container ;
118
+ }
119
+
120
+ @ Reference (target = "(type=default)" )
121
+ public void setDefaultTypeFunction (TypeFunction function ) {
122
+ this .container .setDefaultTypeFunction (function );
123
+ }
124
+
145
125
}
0 commit comments