Sha256: e7c8e916889408bee67eaab8d2c5e8758c8a301b7ca469f901b2537c5208094b
Contents?: true
Size: 1.19 KB
Versions: 7
Compression:
Stored size: 1.19 KB
Contents
# frozen_string_literal: true module Api module V1 class GraphqlController < ApplicationController include GraphqlDevise::SetUserByToken include ActionController::Cookies def graphql result = DummySchema.execute(params[:query], **execute_params(params)) render json: result unless performed? end def interpreter render json: InterpreterSchema.execute(params[:query], **execute_params(params)) end private def execute_params(item) { operation_name: item[:operationName], variables: ensure_hash(item[:variables]), context: gql_devise_context(SchemaUser, User) } end 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 def verify_authenticity_token end end end end
Version data entries
7 entries across 7 versions & 1 rubygems