Module: ManageIQ::API::Common::GraphQL

Defined in:
lib/manageiq/api/common/graphql.rb,
lib/manageiq/api/common/graphql/generator.rb,
lib/manageiq/api/common/graphql/types/big_int.rb,
lib/manageiq/api/common/graphql/types/date_time.rb,
lib/manageiq/api/common/graphql/associated_records.rb,
lib/manageiq/api/common/graphql/association_loader.rb,
lib/manageiq/api/common/graphql/types/query_filter.rb

Defined Under Namespace

Modules: Api, Generator, Types Classes: AssociatedRecords, AssociationLoader

Class Method Summary collapse

Class Method Details

.ensure_hash(ambiguous_param) ⇒ Object

Following code is auto-generated via rails generate graphql:install

Handle form data, JSON body, or a blank value



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/manageiq/api/common/graphql.rb', line 107

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_descriptionObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/manageiq/api/common/graphql.rb', line 24

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_requestObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/manageiq/api/common/graphql.rb', line 55

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_responseObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/manageiq/api/common/graphql.rb', line 81

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) ⇒ Object



100
101
102
# File 'lib/manageiq/api/common/graphql.rb', line 100

def self.search_options(scope, args)
  args[:id] ? scope.where(:id => args[:id]) : scope
end

.version(request) ⇒ Object



19
20
21
22
# File 'lib/manageiq/api/common/graphql.rb', line 19

def self.version(request)
  /\/?\w+\/v(?<major>\d+)[x\.]?(?<minor>\d+)?\// =~ request.original_url
  [major, minor].compact.join(".")
end