Sha256: 0110e945784dca17c901d699b6957e9eb9f0739a0d079ab3ed8815e65affe9ef
Contents?: true
Size: 872 Bytes
Versions: 36
Compression:
Stored size: 872 Bytes
Contents
class GraphqlController < ApplicationController def execute variables = ensure_hash(params[:variables]) query = params[:query] operation_name = params[:operationName] context = { # Query context goes here, for example: # current_user: current_user, } result = <%= schema_name %>.execute(query, variables: variables, context: context, operation_name: operation_name) 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
36 entries across 36 versions & 1 rubygems