Sha256: 72fc71eb609205da0895b16c66970b42270202174d9e7763de8afba37cfaa695

Contents?: true

Size: 796 Bytes

Versions: 18

Compression:

Stored size: 796 Bytes

Contents

class GraphqlController < ApplicationController
  def execute
    variables = ensure_hash(params[:variables])
    query = params[:query]
    context = {
      # Query context goes here, for example:
      # current_user: current_user,
    }
    result = <%= schema_name %>.execute(query, variables: variables, context: context)
    render json: result
  end

  private

  # Handle form data, JSON body, or a blank value
  def ensure_hash(ambiguous_param)
    case ambiguous_param
    when String
      if ambiguous_param.present?
        ensure_hash(JSON.parse(ambiguous_param))
      else
        {}
      end
    when Hash, ActionController::Parameters
      ambiguous_param
    when nil
      {}
    else
      raise ArgumentError, "Unexpected parameter: #{ambiguous_param}"
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
graphql-1.5.15 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.6.3 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.6.2 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.6.1 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.6.0 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.5.14 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.5.13 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.5.7.1 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.5.12 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.5.11 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.5.10 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.5.9 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.5.8 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.5.7 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.5.6 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.5.5 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.5.4 lib/generators/graphql/templates/graphql_controller.erb
graphql-1.5.3 lib/generators/graphql/templates/graphql_controller.erb