use of graphql.servlet.GraphQLQueryProvider in project admin-console-beta by connexta.
the class GraphQLServletImpl method updateSchema.
private void updateSchema() {
GraphQLObjectType.Builder object = newObject().name("Query");
GraphQLTransformCommons transformCommons = new GraphQLTransformCommons();
List<GraphQLProviderImpl> graphqlProviders = transformCommons.fieldProvidersToGraphQLProviders(fieldProviders);
for (GraphQLQueryProvider provider : graphqlProviders) {
GraphQLObjectType query = provider.getQuery();
object.field(newFieldDefinition().type(query).staticValue(provider.context()).name(provider.getName()).description(query.getDescription()).build());
}
boolean noMutations = graphqlProviders.stream().map(GraphQLProviderImpl::getMutations).flatMap(Collection::stream).collect(Collectors.toList()).isEmpty();
if (noMutations) {
schema = newSchema().query(object.build()).build();
} else {
GraphQLObjectType.Builder mutationObject = newObject().name("Mutation");
for (GraphQLMutationProvider provider : graphqlProviders) {
provider.getMutations().forEach(mutationObject::field);
}
schema = newSchema().query(object.build()).mutation(mutationObject.build()).build();
}
}
Aggregations