Search in sources :

Example 1 with GraphQLQueryProvider

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();
    }
}
Also used : GraphQLTransformCommons(org.codice.ddf.admin.graphql.common.GraphQLTransformCommons) GraphQLMutationProvider(graphql.servlet.GraphQLMutationProvider) GraphQLObjectType(graphql.schema.GraphQLObjectType) Collection(java.util.Collection) GraphQLQueryProvider(graphql.servlet.GraphQLQueryProvider)

Aggregations

GraphQLObjectType (graphql.schema.GraphQLObjectType)1 GraphQLMutationProvider (graphql.servlet.GraphQLMutationProvider)1 GraphQLQueryProvider (graphql.servlet.GraphQLQueryProvider)1 Collection (java.util.Collection)1 GraphQLTransformCommons (org.codice.ddf.admin.graphql.common.GraphQLTransformCommons)1