Sha256: 72c88b5bd325f48d81b30a4ce8ea525f70d2428b4eebebcf117dc23e25ef7f68

Contents?: true

Size: 945 Bytes

Versions: 41

Compression:

Stored size: 945 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
      skip_authorization_check

      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

41 entries across 41 versions & 2 rubygems

Version Path
decidim-api-0.11.2 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.11.1 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.11.0.pre1 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.10.1 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.10.0 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.9.3 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.9.2 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.9.1 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.9.0 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.8.4 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.8.3 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.8.2 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.8.1 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.8.0 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.7.4 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.7.3 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.7.2 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.7.1 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.7.0 app/controllers/decidim/api/queries_controller.rb
decidim-api-0.6.8 app/controllers/decidim/api/queries_controller.rb