2626import graphql .schema .GraphQLFieldDefinition ;
2727import graphql .schema .GraphQLObjectType ;
2828import graphql .schema .GraphQLSchema ;
29+ import graphql .schema .GraphQLType ;
2930import graphql .validation .ValidationError ;
3031import lombok .Getter ;
3132import lombok .Setter ;
@@ -64,6 +65,7 @@ public class GraphQLServlet extends HttpServlet implements Servlet, GraphQLMBean
6465
6566 private List <GraphQLQueryProvider > queryProviders = new ArrayList <>();
6667 private List <GraphQLMutationProvider > mutationProviders = new ArrayList <>();
68+ private List <GraphQLTypesProvider > typesProviders = new ArrayList <>();
6769
6870 @ Getter
6971 GraphQLSchema schema ;
@@ -83,7 +85,12 @@ protected void updateSchema() {
8385 build ());
8486 }
8587
86- readOnlySchema = newSchema ().query (object .build ()).build ();
88+ Set <GraphQLType > types = new HashSet <>();
89+ for (GraphQLTypesProvider typesProvider : typesProviders ) {
90+ types .addAll (typesProvider .getTypes ());
91+ }
92+
93+ readOnlySchema = newSchema ().query (object .build ()).build (types );
8794
8895 if (mutationProviders .isEmpty ()) {
8996 schema = readOnlySchema ;
@@ -127,6 +134,16 @@ public void unbindMutationProvider(GraphQLMutationProvider mutationProvider) {
127134 updateSchema ();
128135 }
129136
137+ @ Reference (cardinality = ReferenceCardinality .MULTIPLE , policyOption = ReferencePolicyOption .GREEDY )
138+ public void typesProviders (GraphQLTypesProvider typesProvider ) {
139+ typesProviders .add (typesProvider );
140+ updateSchema ();
141+ }
142+ public void unbindTypesProvider (GraphQLTypesProvider typesProvider ) {
143+ typesProviders .remove (typesProvider );
144+ updateSchema ();
145+ }
146+
130147 @ Override
131148 public String [] getQueries () {
132149 return schema .getQueryType ().getFieldDefinitions ().stream ().map (GraphQLFieldDefinition ::getName ).toArray (String []::new );
0 commit comments