Class: FlyIO::ExperimentalGraphQL

Inherits:
Object
  • Object
show all
Defined in:
lib/fly_io/graphql_client.rb

Constant Summary collapse

MANIFEST_PATH =
File.expand_path("generated/graphql_operations.json", __dir__)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#clientObject (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

.operationsObject



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

#operationsObject



87
88
89
# File 'lib/fly_io/graphql_client.rb', line 87

def operations
  self.class.operations
end