Class: FlyIO::ExperimentalGraphQL
- Inherits:
-
Object
- Object
- FlyIO::ExperimentalGraphQL
- Defined in:
- lib/fly_io/graphql_client.rb
Constant Summary collapse
- MANIFEST_PATH =
File.("generated/graphql_operations.json", __dir__)
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(name, variables: {}) ⇒ Object
-
#initialize(client) ⇒ ExperimentalGraphQL
constructor
A new instance of ExperimentalGraphQL.
- #operations ⇒ Object
Constructor Details
#initialize(client) ⇒ ExperimentalGraphQL
Returns a new instance of ExperimentalGraphQL.
82 83 84 85 |
# File 'lib/fly_io/graphql_client.rb', line 82 def initialize(client) @client = client freeze end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
80 81 82 |
# File 'lib/fly_io/graphql_client.rb', line 80 def client @client end |
Class Method Details
.operations ⇒ Object
99 100 101 |
# File 'lib/fly_io/graphql_client.rb', line 99 def self.operations @operations ||= JSON.parse(File.read(MANIFEST_PATH)).fetch("operations").freeze end |
Instance Method Details
#execute(name, variables: {}) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/fly_io/graphql_client.rb', line 91 def execute(name, variables: {}, **) operation = operations.find { |entry| entry.fetch("name") == name.to_s } raise FlyIO::ArgumentError, "unknown experimental GraphQL operation: #{name}" unless operation client.query(document: operation.fetch("document"), operation_name: operation["operation_name"], variables: variables, **) end |
#operations ⇒ Object
87 88 89 |
# File 'lib/fly_io/graphql_client.rb', line 87 def operations self.class.operations end |