001// --------------------------------------------------------------------------------
002// Copyright 2002-2024 Echo Three, LLC
003//
004// Licensed under the Apache License, Version 2.0 (the "License");
005// you may not use this file except in compliance with the License.
006// You may obtain a copy of the License at
007//
008//     http://www.apache.org/licenses/LICENSE-2.0
009//
010// Unless required by applicable law or agreed to in writing, software
011// distributed under the License is distributed on an "AS IS" BASIS,
012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013// See the License for the specific language governing permissions and
014// limitations under the License.
015// --------------------------------------------------------------------------------
016
017package com.echothree.model.control.graphql.server.util;
018
019import com.echothree.model.control.graphql.server.graphql.GraphQlMutations;
020import com.echothree.model.control.graphql.server.graphql.GraphQlQueries;
021import com.echothree.model.control.graphql.server.graphql.count.RelayWithCounting;
022import graphql.annotations.AnnotationsSchemaCreator;
023import graphql.annotations.processor.GraphQLAnnotations;
024import graphql.schema.GraphQLSchema;
025
026public class GraphQlSchemaUtils {
027    
028    private GraphQLSchema readOnlySchema;
029    private GraphQLSchema schema;
030
031    private GraphQlSchemaUtils() {
032        buildSchema();
033    }
034    
035    private static class GraphQlSchemaUtilsHolder {
036        static GraphQlSchemaUtils instance = new GraphQlSchemaUtils();
037    }
038    
039    public static GraphQlSchemaUtils getInstance() {
040        return GraphQlSchemaUtilsHolder.instance;
041    }
042    
043    private void buildSchema() {
044        readOnlySchema = AnnotationsSchemaCreator.newAnnotationsSchema()
045                .setAnnotationsProcessor(new GraphQLAnnotations())
046                .setRelay(new RelayWithCounting())
047                .query(GraphQlQueries.class)
048                .setAlwaysPrettify(true)
049                .build();
050
051        schema = AnnotationsSchemaCreator.newAnnotationsSchema()
052                .setAnnotationsProcessor(new GraphQLAnnotations())
053                .setRelay(new RelayWithCounting())
054                .query(GraphQlQueries.class)
055                .mutation(GraphQlMutations.class)
056                .setAlwaysPrettify(true)
057                .build();
058    }
059
060    public GraphQLSchema getReadOnlySchema() {
061        return readOnlySchema;
062    }
063
064    public GraphQLSchema getSchema() {
065        return schema;
066    }
067
068}