Class: Artemis::GraphQLEndpoint
- Inherits:
-
Object
- Object
- Artemis::GraphQLEndpoint
- Defined in:
- lib/artemis/graphql_endpoint.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#adapter_options ⇒ Object
readonly
Returns the value of attribute adapter_options.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pool_size ⇒ Object
readonly
Returns the value of attribute pool_size.
-
#schema_path ⇒ Object
readonly
Returns the value of attribute schema_path.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.lookup(service_name) ⇒ Object
Provides an endpoint instance specified in the
configuration
. - .register!(service_name, configurations) ⇒ Object
-
.registered_services ⇒ Object
Returns the registered services as an array.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(name, url: nil, adapter: :net_http, timeout: 10, schema_path: nil, pool_size: 25, adapter_options: {}) ⇒ GraphQLEndpoint
constructor
A new instance of GraphQLEndpoint.
- #schema ⇒ Object (also: #load_schema!)
Constructor Details
#initialize(name, url: nil, adapter: :net_http, timeout: 10, schema_path: nil, pool_size: 25, adapter_options: {}) ⇒ GraphQLEndpoint
Returns a new instance of GraphQLEndpoint.
49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 = @mutex_for_schema = Mutex.new @mutex_for_connection = Mutex.new end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
47 48 49 |
# File 'lib/artemis/graphql_endpoint.rb', line 47 def adapter @adapter end |
#adapter_options ⇒ Object (readonly)
Returns the value of attribute adapter_options.
47 48 49 |
# File 'lib/artemis/graphql_endpoint.rb', line 47 def @adapter_options end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
47 48 49 |
# File 'lib/artemis/graphql_endpoint.rb', line 47 def name @name end |
#pool_size ⇒ Object (readonly)
Returns the value of attribute pool_size.
47 48 49 |
# File 'lib/artemis/graphql_endpoint.rb', line 47 def pool_size @pool_size end |
#schema_path ⇒ Object (readonly)
Returns the value of attribute schema_path.
47 48 49 |
# File 'lib/artemis/graphql_endpoint.rb', line 47 def schema_path @schema_path end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
47 48 49 |
# File 'lib/artemis/graphql_endpoint.rb', line 47 def timeout @timeout end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
47 48 49 |
# File 'lib/artemis/graphql_endpoint.rb', line 47 def url @url end |
Class Method Details
.lookup(service_name) ⇒ Object
Provides an endpoint instance specified in the configuration
. If the endpoint is not found in ENDPOINT_INSTANCES
, it’ll raise an exception.
31 32 33 |
# 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 |
.register!(service_name, configurations) ⇒ Object
35 36 37 |
# 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 ⇒ Object
Returns the registered services as an array.
42 43 44 |
# File 'lib/artemis/graphql_endpoint.rb', line 42 def registered_services ENDPOINT_INSTANCES.keys end |
Instance Method Details
#connection ⇒ Object
73 74 75 76 77 |
# 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: ) end end |
#schema ⇒ Object Also known as: load_schema!
62 63 64 65 66 67 68 69 70 |
# 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 |