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