All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.micronaut.configuration.graphql.GraphQLConfiguration Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2017-2020 original authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.micronaut.configuration.graphql;

import io.micronaut.context.annotation.ConfigurationProperties;
import io.micronaut.core.util.Toggleable;

import java.util.Collections;
import java.util.Map;

import static io.micronaut.configuration.graphql.GraphQLConfiguration.PREFIX;

/**
 * Configuration properties for GraphQL.
 *
 * @author Marcel Overdijk
 * @author James Kleeh
 * @since 1.0
 */
@ConfigurationProperties(PREFIX)
public class GraphQLConfiguration implements Toggleable {

    /**
     * The prefix to use for all GraphQL configuration properties.
     */
    public static final String PREFIX = "graphql";

    /**
     * The configuration name whether GraphQL is enabled.
     */
    public static final String ENABLED_CONFIG = PREFIX + ".enabled";

    /**
     * The default enabled value.
     */
    public static final boolean DEFAULT_ENABLED = true;

    /**
     * The configuration name of the GraphQL path.
     */
    public static final String PATH_CONFIG = PREFIX + ".path";

    /**
     * The default GraphQL path.
     */
    public static final String DEFAULT_PATH = "/graphql";

    protected boolean enabled = DEFAULT_ENABLED;
    protected String path = DEFAULT_PATH;
    protected GraphiQLConfiguration graphiql = new GraphiQLConfiguration();

    /**
     * Returns whether GraphQL is enabled.
     *
     * @return whether GraphQL is enabled
     */
    @Override
    public boolean isEnabled() {
        return enabled;
    }

    /**
     * Returns the GraphQL path.
     *
     * @return the GraphQL path
     */
    public String getPath() {
        return path;
    }

    /**
     * Returns the GraphiQL configuration.
     *
     * @return the GraphiQL configuration
     */
    public GraphiQLConfiguration getGraphiql() {
        return graphiql;
    }

    /**
     * Configuration properties for GraphiQL.
     */
    @ConfigurationProperties(GraphiQLConfiguration.PREFIX)
    public static class GraphiQLConfiguration implements Toggleable {

        /**
         * The prefix to use for all GraphiQL configuration properties.
         */
        public static final String PREFIX = "graphiql";

        /**
         * The configuration name whether GraphiQL is enabled.
         */
        public static final String ENABLED_CONFIG = GraphQLConfiguration.PREFIX + "." + PREFIX + ".enabled";

        /**
         * The default enabled value.
         */
        public static final boolean DEFAULT_ENABLED = false;

        /**
         * The configuration name of the GraphiQL version.
         */
        public static final String VERSION_CONFIG = PREFIX + ".version";

        /**
         * The configuration name of the GraphIQL Explorer plugin version.
         * @since 4.1
         */
        public static final String EXPLORER_PLUGIN_VERSION = PREFIX + ".explorerPluginVersion";

        /**
         * The default GraphiQL version.
         */
        public static final String DEFAULT_VERSION = "3.0.6";

        /**
         * The default GraphIQL Explorer plugin version.
         * @since 4.1
         */
        public static final String DEFAULT_EXPLORER_PLUGIN_VERSION = "0.3.5";

        /**
         * The configuration name of the GraphiQL path.
         */
        public static final String PATH_CONFIG = PREFIX + ".path";

        /**
         * The default GraphiQL path.
         */
        public static final String DEFAULT_PATH = "/graphiql";

        /**
         * The configuration name of the GraphiQL template path.
         */
        public static final String TEMPLATE_PATH_CONFIG = PREFIX + ".template-path";

        /**
         * The default GraphiQL template path.
         */
        public static final String DEFAULT_TEMPLATE_PATH = "classpath:graphiql/index.html";

        /**
         * The configuration name of the GraphiQL template parameters.
         */
        public static final String TEMPLATE_PARAMETERS_CONFIG = PREFIX + ".template-parameters";

        /**
         * The default GraphiQL template parameters.
         */
        public static final Map DEFAULT_TEMPLATE_PARAMETERS = Collections.emptyMap();

        /**
         * The configuration name of the GraphiQL page title.
         */
        public static final String PAGE_TITLE_CONFIG = PREFIX + ".page-title";

        /**
         * The default GraphiQL page title.
         */
        public static final String DEFAULT_PAGE_TITLE = "GraphiQL";

        protected boolean enabled = DEFAULT_ENABLED;
        protected String version = DEFAULT_VERSION;
        protected String explorerPluginVersion = DEFAULT_EXPLORER_PLUGIN_VERSION;
        protected String path = DEFAULT_PATH;
        protected String templatePath = DEFAULT_TEMPLATE_PATH;
        protected Map templateParameters = DEFAULT_TEMPLATE_PARAMETERS;
        protected String pageTitle = DEFAULT_PAGE_TITLE;

        /**
         * Returns whether GraphiQL is enabled. Default value ({@value #DEFAULT_ENABLED}).
         *
         * @return whether GraphiQL is enabled
         */
        @Override
        public boolean isEnabled() {
            return enabled;
        }

        /**
         * Returns the GraphiQL version. Default value ({@value #DEFAULT_VERSION}).
         *
         * @return the GraphiQL version
         */
        public String getVersion() {
            return version;
        }

        /**
         * Returns the GraphIQL Explorer plugin version. Default value ({@value #DEFAULT_EXPLORER_PLUGIN_VERSION}).
         *
         * @return the GraphIQL Explorer plugin version
         * @since 4.1
         */
        public String getExplorerPluginVersion() {
            return explorerPluginVersion;
        }

        /**
         * Returns the GraphiQL path. Default value ({@value #DEFAULT_PATH}).
         *
         * @return the GraphiQL path
         */
        public String getPath() {
            return path;
        }

        /**
         * Returns the GraphiQL template path. Default value ({@value #DEFAULT_TEMPLATE_PATH}).
         *
         * @return the GraphiQL template path
         */
        public String getTemplatePath() {
            return templatePath;
        }

        /**
         * Returns the GraphiQL template parameters to be substituted in the template.
         *
         * @return the GraphiQL template parameters
         */
        public Map getTemplateParameters() {
            return templateParameters;
        }

        /**
         * Returns the GraphiQL page title. Default value ({@value #DEFAULT_PAGE_TITLE}).
         *
         * @return the GraphiQL page title
         */
        public String getPageTitle() {
            return pageTitle;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy