Class: Graphql::Dashboard

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/graphql/dashboard.rb

Overview

GraphQL::Dashboard is a Rails::Engine-based dashboard for viewing metadata about your GraphQL schema.

Pass the class name of your schema when mounting it.

Examples:

Mounting the Dashboard in your app

mount GraphQL::Dashboard, at: "graphql_dashboard", schema: "MySchema"

Authenticating the Dashboard with HTTP Basic Auth

# config/initializers/graphql_dashboard.rb
GraphQL::Dashboard.middleware.use(Rack::Auth::Basic) do |username, password|
  # Compare the provided username/password to an application setting:
  ActiveSupport::SecurityUtils.secure_compare(Rails.application.credentials.graphql_dashboard_username, username) &&
    ActiveSupport::SecurityUtils.secure_compare(Rails.application.credentials.graphql_dashboard_username, password)
end

Custom Rails authentication

# config/initializers/graphql_dashboard.rb
ActiveSupport.on_load(:graphql_dashboard_application_controller) do
  # context here is GraphQL::Dashboard::ApplicationController

  before_action do
    raise ActionController::RoutingError.new('Not Found') unless current_user&.admin?
  end

  def current_user
    # load current user
  end
end

See Also:

Defined Under Namespace

Classes: ApplicationController, LandingsController, StaticsController, TracesController