class Artemis::GraphQLEndpoint

Constants

ENDPOINT_INSTANCES

Hash object that holds references to adapter instances.

Attributes

adapter[R]
adapter_options[R]
name[R]
pool_size[R]
schema_path[R]
timeout[R]
url[R]

Public Class Methods

lookup(service_name) click to toggle source

Provides an endpoint instance specified in the configuration. If the endpoint is not found in ENDPOINT_INSTANCES, it'll raise an exception.

# File lib/artemis/graphql_endpoint.rb, line 31
def lookup(service_name)
  ENDPOINT_INSTANCES[service_name.to_s.underscore] || raise(Artemis::EndpointNotFound, "Service `#{service_name}' not registered.")
end
new(name, url: nil, adapter: :net_http, timeout: 10, schema_path: nil, pool_size: 25, adapter_options: {}) click to toggle source
# File lib/artemis/graphql_endpoint.rb, line 49
def initialize(name, url: nil, adapter: :net_http, timeout: 10, schema_path: nil, pool_size: 25, adapter_options: {})
  @name            = name.to_s
  @url             = url
  @adapter         = adapter
  @timeout         = timeout
  @schema_path     = schema_path
  @pool_size       = pool_size
  @adapter_options = adapter_options

  @mutex_for_schema     = Mutex.new
  @mutex_for_connection = Mutex.new
end
register!(service_name, configurations) click to toggle source
# File lib/artemis/graphql_endpoint.rb, line 35
def register!(service_name, configurations)
  ENDPOINT_INSTANCES[service_name.to_s.underscore] = new(service_name.to_s, **configurations.symbolize_keys)
end
registered_services() click to toggle source

Returns the registered services as an array.

# File lib/artemis/graphql_endpoint.rb, line 42
def registered_services
  ENDPOINT_INSTANCES.keys
end

Public Instance Methods

connection() click to toggle source
# File lib/artemis/graphql_endpoint.rb, line 73
def connection
  @connection || @mutex_for_connection.synchronize do
    @connection ||= ::Artemis::Adapters.lookup(adapter).new(url, service_name: name, timeout: timeout, pool_size: pool_size, adapter_options: adapter_options)
  end
end
load_schema!()
Alias for: schema
schema() click to toggle source
# File lib/artemis/graphql_endpoint.rb, line 62
def schema
  org, $stderr = $stderr, File.new("/dev/null", "w") if self.class.suppress_warnings_on_schema_load

  @schema || @mutex_for_schema.synchronize do
    @schema ||= ::GraphQL::Client.load_schema(schema_path.presence || connection)
  end
ensure
  $stderr = org if self.class.suppress_warnings_on_schema_load
end
Also aliased as: load_schema!