Skip to content

Commit 4aae259

Browse files
authored
Merge pull request #11 from Jahia/initial-types-support
Added support for initial types dictionnary
2 parents 1fb85f3 + 52a1a4c commit 4aae259

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/main/java/graphql/servlet/GraphQLServlet.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import graphql.schema.GraphQLFieldDefinition;
2727
import graphql.schema.GraphQLObjectType;
2828
import graphql.schema.GraphQLSchema;
29+
import graphql.schema.GraphQLType;
2930
import graphql.validation.ValidationError;
3031
import lombok.Getter;
3132
import 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);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.servlet;
16+
17+
import graphql.schema.GraphQLType;
18+
19+
import java.util.Collection;
20+
21+
public interface GraphQLTypesProvider {
22+
Collection<GraphQLType> getTypes();
23+
}

0 commit comments

Comments
 (0)