Table of Contents


This gem provides the GraphQL::Controller concern that has everything you may need to run your requests through ActionController. You can also use the GraphQL::BaseController as your superclass (which just implements the concern).



This setting allows defining which schema will be used by default.

# app/controllers/my_controller.rb
self.gql_schema = 'GraphQL::MySchema'
# OR
self.gql_schema = GraphQL::MySchema

The namespace is not supported because the class must be loaded before the schema can be found.


Here is the list of actions that are implemented by the concern:

POST execute

It will use the helpers provided to execute a request for the gql_query.

GET describe

It will print a plain GraphQL document that represents everything that is defined in the schema.

GET graphiql

It will render a GraphiQL console for the underlying schema.



Identifies if the request should be threated as a compiled request.
Default: false.

gql_request_response(*args, **xargs)

It will render a JSON with the response of the gql_request helper.

gql_request(document, **xargs)

It will collect the necessary pieces using other helpers and then execute the request for the provided document. You can provide the following named arguments: operation_name, variables, context, schema, and query_cache_key.


It will resolve the underlying schema from self.class.gql_schema or by attempting to find a schema with the same name as your application.


It returns the GraphQL document as params[:query].

gql_query_cache_key(key = nil, version = nil)

Attempt to build build a cache key for cached requests. You can provide the key, or it will be fetched from params[:query_cache_key], and the version, or it will be fetched from params[:query_cache_version].


It returns the name for the GraphQL operation as params[:operationName] || params[:operation_name].


It returns the context for the GraphQL request. You should override this method to add your own keys to it.

gql_variables(variables = params[:variables])

It will properly parse the provided variables, so it is a usable Hash. For example, if the value is a string, it will JSON.parse(variables), and if it is controller parameters, it will variables.permit!.to_h.

gql_describe_schema(schema = gql_schema)

It will generate the GraphQL string document of the provided schema.


It will provide a nice header for the gql_describe_schema.

It will provide a nice footer for the gql_describe_schema.


It returns the version of the Type Map.

graphiql_settings(mode = nil)

It will return the proper settings for the GraphiQL console. It supports the :fetch and :cable. You can override this method to change the :url and :channel settings.