Class: FlyIO::GraphQLClient
- Inherits:
-
Object
- Object
- FlyIO::GraphQLClient
- Defined in:
- lib/fly_io/graphql_client.rb
Overview
Fly documents this control-plane GraphQL endpoint as internal and unstable. Raw documents are first class; generated flyctl-observed operations live behind #experimental and carry no compatibility guarantee.
Constant Summary collapse
- INTROSPECTION_PATTERN =
/\b__(?:schema|type)\b/
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Instance Method Summary collapse
- #experimental ⇒ Object
-
#initialize(configuration = nil) ⇒ GraphQLClient
constructor
A new instance of GraphQLClient.
- #introspect(document:) ⇒ Object
- #query(document:, variables: {}, operation_name: nil, headers: {}, timeout: nil, retry_unsafe: false, introspection: false) ⇒ Object (also: #execute)
Constructor Details
#initialize(configuration = nil) ⇒ GraphQLClient
Returns a new instance of GraphQLClient.
14 15 16 17 18 19 |
# File 'lib/fly_io/graphql_client.rb', line 14 def initialize(configuration = nil, **) @configuration = configuration || Configuration.new(**) graphql_configuration = @configuration.with(base_url: graphql_origin) @transport = Transport.new(graphql_configuration) freeze end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
12 13 14 |
# File 'lib/fly_io/graphql_client.rb', line 12 def configuration @configuration end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
12 13 14 |
# File 'lib/fly_io/graphql_client.rb', line 12 def transport @transport end |
Instance Method Details
#experimental ⇒ Object
43 44 45 |
# File 'lib/fly_io/graphql_client.rb', line 43 def experimental ExperimentalGraphQL.new(self) end |
#introspect(document:) ⇒ Object
39 40 41 |
# File 'lib/fly_io/graphql_client.rb', line 39 def introspect(document:, **) query(document: document, introspection: true, **) end |
#query(document:, variables: {}, operation_name: nil, headers: {}, timeout: nil, retry_unsafe: false, introspection: false) ⇒ Object Also known as: execute
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fly_io/graphql_client.rb', line 21 def query(document:, variables: {}, operation_name: nil, headers: {}, timeout: nil, retry_unsafe: false, introspection: false) validate_document!(document, introspection) body = {"query" => String(document), "variables" => variables} body["operationName"] = operation_name if operation_name response = transport.request(method: :post, path: graphql_path, headers: headers, body: body, retry_unsafe: retry_unsafe, timeout: timeout) errors = response.body.is_a?(Hash) ? response.body["errors"] : nil if errors&.any? raise GraphQLError.new(graphql_errors: errors, status: response.status, headers: response.headers, request_id: response.request_id, request: response.request) end response end |