Sha256: 9ae28f138681d04b374903de06a00ec42c148b6f7ae431324ac02de4a80cd278

Contents?: true

Size: 939 Bytes

Versions: 1

Compression:

Stored size: 939 Bytes

Contents

module GraphitiGql
  class Engine < ::Rails::Engine
    isolate_namespace GraphitiGql

    # TODO improvable?
    config.after_initialize do
    # initializer "graphiti_gql.generate_schema" do
      Dir.glob("#{Rails.root}/app/resources/**/*").each { |f| require(f) }
      GraphitiGql.schema!
    end

    initializer "graphiti_gql.define_controller" do
      app_controller = GraphitiGql.config.application_controller || ::ApplicationController

      # rubocop:disable Lint/ConstantDefinitionInBlock(Standard)
      class GraphitiGql::ExecutionController < app_controller
        def execute
          params = request.params # avoid strong_parameters
          variables = params[:variables] || {}
          ctx = respond_to?(:graphql_context) ? graphql_context : {}
          result = GraphitiGql.run params[:query],
            params[:variables],
            ctx
          render json: result
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphiti_gql-0.2.16 lib/graphiti_gql/engine.rb