Sha256: 17dfe6bc8ae5d580c8b6e1231d5f0d6e7dec6338608efa78e131c5b0ebe364a5

Contents?: true

Size: 913 Bytes

Versions: 53

Compression:

Stored size: 913 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Api
    # This controller takes queries from an HTTP endpoint and sends them out to
    # the Schema to be executed, later returning the response as JSON.
    class QueriesController < Api::ApplicationController
      def create
        query_string = params[:query]
        query_variables = ensure_hash(params[:variables])
        result = Schema.execute(query_string, variables: query_variables, context: context)
        render json: result
      end

      private

      def context
        {
          current_organization: current_organization,
          current_user: current_user
        }
      end

      def ensure_hash(query_variables)
        if query_variables.blank?
          {}
        elsif query_variables.is_a?(String)
          JSON.parse(query_variables)
        else
          query_variables
        end
      end
    end
  end
end

Version data entries

53 entries across 53 versions & 2 rubygems

Version Path
decidim-api-0.23.6 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.23.5 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.23.4 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.23.3 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.23.2 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.23.1 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.23.1.rc1 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.23.0 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.22.0 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.21.0 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.20.1 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.20.0 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.19.1 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.18.1 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.19.0 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.17.2 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.18.0 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.17.1 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.16.1 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.17.0 app/controllers/decidim/api/queries_controller.rb