/*
 * Copyright 2019 Red Hat, Inc.
 *
 * Red Hat licenses this file to you 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:
 *
 * http://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.vertx.ext.web.handler.graphql;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.common.WebEnvironment;

import java.util.HashMap;
import java.util.Map;

Embedded GraphiQL user interface options.
Author:Thomas Segismont
/** * Embedded GraphiQL user interface options. * * @author Thomas Segismont */
@DataObject(generateConverter = true) public class GraphiQLOptions {
Whether GraphiQL development tool should be enabled by default = false.
/** * Whether GraphiQL development tool should be enabled by default = false. */
public static final boolean DEFAULT_ENABLED = WebEnvironment.development(); private boolean enabled = DEFAULT_ENABLED; private String graphQLUri; private Map<String, String> headers; private String query; private JsonObject variables;
Default constructor.
/** * Default constructor. */
public GraphiQLOptions() { }
Copy constructor.
Params:
  • other – the options to copy
/** * Copy constructor. * * @param other the options to copy */
public GraphiQLOptions(GraphiQLOptions other) { enabled = other.enabled; graphQLUri = other.graphQLUri; headers = other.headers == null ? null : new HashMap<>(other.headers); query = other.query; variables = other.variables == null ? null : other.variables.copy(); }
Constructor to create options from JSON.
Params:
  • json – the JSON
/** * Constructor to create options from JSON. * * @param json the JSON */
public GraphiQLOptions(JsonObject json) { this(); GraphiQLOptionsConverter.fromJson(json, this); }
Returns:a JSON representation of these options
/** * @return a JSON representation of these options */
public JsonObject toJson() { JsonObject json = new JsonObject(); GraphiQLOptionsConverter.toJson(this, json); return json; }
Returns:true if the GraphiQL development tool should be enabled, false otherwise
/** * @return true if the GraphiQL development tool should be enabled, false otherwise */
public boolean isEnabled() { return enabled; }
Whether the GraphiQL development tool should be enabled. Defaults to false.
Params:
  • enabled – true to enable the GraphiQL development tool, false otherwise
Returns:a reference to this, so the API can be used fluently
/** * Whether the GraphiQL development tool should be enabled. Defaults to {@code false}. * * @param enabled true to enable the GraphiQL development tool, false otherwise * * @return a reference to this, so the API can be used fluently */
public GraphiQLOptions setEnabled(boolean enabled) { this.enabled = enabled; return this; }
Returns:the GraphQL endpoint URI
/** * @return the GraphQL endpoint URI */
public String getGraphQLUri() { return graphQLUri; }
Set the GraphQL endpoint URI. Defaults to the path used to get the GraphiQL user interface.
Params:
  • graphQLUri – the GraphQL endpoint URI
Returns:a reference to this, so the API can be used fluently
/** * Set the GraphQL endpoint URI. Defaults to the path used to get the GraphiQL user interface. * * @param graphQLUri the GraphQL endpoint URI * * @return a reference to this, so the API can be used fluently */
public GraphiQLOptions setGraphQLUri(String graphQLUri) { this.graphQLUri = graphQLUri; return this; }
Returns:the fixed set of HTTP headers to add to GraphiQL requests
/** * @return the fixed set of HTTP headers to add to GraphiQL requests */
public Map<String, String> getHeaders() { return headers; }
A fixed set of HTTP headers to add to GraphiQL requests. Defaults to null.
Params:
  • headers – the set of HTTP headers to add to GraphiQL requests
Returns:a reference to this, so the API can be used fluently
/** * A fixed set of HTTP headers to add to GraphiQL requests. Defaults to {@code null}. * * @param headers the set of HTTP headers to add to GraphiQL requests * * @return a reference to this, so the API can be used fluently */
public GraphiQLOptions setHeaders(Map<String, String> headers) { this.headers = headers; return this; }
Returns:the query to set as initial value in the GraphiQL user interface
/** * @return the query to set as initial value in the GraphiQL user interface */
public String getQuery() { return query; }
Initial value of the query area in the GraphiQL user interface. Defaults to null.
Params:
  • query – the query to set as initial value
Returns:a reference to this, so the API can be used fluently
/** * Initial value of the query area in the GraphiQL user interface. Defaults to {@code null}. * * @param query the query to set as initial value * * @return a reference to this, so the API can be used fluently */
public GraphiQLOptions setQuery(String query) { this.query = query; return this; }
Returns:the variables to set as initial value in the GraphiQL user interface
/** * @return the variables to set as initial value in the GraphiQL user interface */
public JsonObject getVariables() { return variables; }
Initial value of the variables area in the GraphiQL user interface. Defaults to null.
Params:
  • variables – the variables to set as initial value
Returns:a reference to this, so the API can be used fluently
/** * Initial value of the variables area in the GraphiQL user interface. Defaults to {@code null}. * * @param variables the variables to set as initial value * * @return a reference to this, so the API can be used fluently */
public GraphiQLOptions setVariables(JsonObject variables) { this.variables = variables; return this; } }