module Insights::API::Common::GraphQL
Public Class Methods
ensure_hash(ambiguous_param)
click to toggle source
Following code is auto-generated via rails generate graphql:install
Handle form data, JSON body, or a blank value
# File lib/insights/api/common/graphql.rb, line 108 def self.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
openapi_graphql_description()
click to toggle source
# File lib/insights/api/common/graphql.rb, line 25 def self.openapi_graphql_description { "summary" => "Perform a GraphQL Query", "operationId" => "postGraphQL", "description" => "Performs a GraphQL Query", "requestBody" => { "content" => { "application/json" => { "schema" => { "$ref" => "#/components/schemas/GraphQLRequest" } } }, "description" => "GraphQL Query Request", "required" => true }, "responses" => { "200" => { "description" => "GraphQL Query Response", "content" => { "application/json" => { "schema" => { "$ref" => "#/components/schemas/GraphQLResponse" } } } } } } end
openapi_graphql_request()
click to toggle source
# File lib/insights/api/common/graphql.rb, line 56 def self.openapi_graphql_request { "type" => "object", "properties" => { "query" => { "type" => "string", "description" => "The GraphQL query", "default" => "{}" }, "operationName" => { "type" => "string", "description" => "If the Query contains several named operations, the operationName controls which one should be executed", "default" => "" }, "variables" => { "type" => "object", "description" => "Optional Query variables", "nullable" => true } }, "required" => [ "query" ] } end
openapi_graphql_response()
click to toggle source
# File lib/insights/api/common/graphql.rb, line 82 def self.openapi_graphql_response { "type" => "object", "properties" => { "data" => { "type" => "object", "description" => "Results from the GraphQL query" }, "errors" => { "type" => "array", "description" => "Errors resulting from the GraphQL query", "items" => { "type" => "object" } } } } end
search_options(scope, args)
click to toggle source
# File lib/insights/api/common/graphql.rb, line 101 def self.search_options(scope, args) args[:id] ? scope.where(:id => args[:id]) : scope end
version(request)
click to toggle source
# File lib/insights/api/common/graphql.rb, line 20 def self.version(request) /\/?\w+\/v(?<major>\d+)[x\.]?(?<minor>\d+)?\// =~ request.original_url [major, minor].compact.join(".") end