Class: Ecoportal::API::Common::GraphQL::Client
- Inherits:
-
Graphlient::Client
- Object
- Graphlient::Client
- Ecoportal::API::Common::GraphQL::Client
- Includes:
- AuthService
- Defined in:
- lib/ecoportal/api/common/graphql/client.rb
Constant Summary collapse
- ENDPOINT_PATH =
'external/graphql'.freeze
- READ_TIMEOUT =
90- WRITE_TIMEOUT =
90
Constants included from AuthService
AuthService::DEFAULT_SERVER, AuthService::TOKEN_AUTORENEW
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#http_client ⇒ Object
Returns the value of attribute http_client.
Instance Method Summary collapse
-
#initialize(email: nil, pass: nil, org_id: self.org_id, host: server, schema_path: host, no_schema: false) ⇒ Client
constructor
A new instance of Client.
- #new(org_id: self.org_id, host: self.host, schema_path: host, no_schema: @no_schema) ⇒ Object
- #org_id ⇒ Object
-
#schema ⇒ Object
Graphlient/graphql-client build the client-side schema from the server's raw introspection JSON (GraphQL::Schema.from_introspection -> GraphQL::Schema::Loader).
Methods included from AuthService
Methods included from AuthService::InstanceMethods
#session_token, #session_token_renewed
Constructor Details
#initialize(email: nil, pass: nil, org_id: self.org_id, host: server, schema_path: host, no_schema: false) ⇒ Client
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ecoportal/api/common/graphql/client.rb', line 16 def initialize( email: nil, pass: nil, org_id: self.org_id, host: server, schema_path: host, no_schema: false ) @org_id = org_id @host = host @no_schema = no_schema @user_email = email @user_pass = pass puts "Configuring GraphQL Client onto '#{url}'" super( url, headers: { 'Authorization' => "Bearer #{session_token(host: host)}" }, http_options: { read_timeout: READ_TIMEOUT, write_timeout: WRITE_TIMEOUT }.tap do || .merge!(schema_path: schema_path) unless @no_schema end ) end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/ecoportal/api/common/graphql/client.rb', line 9 def host @host end |
#http_client ⇒ Object
Returns the value of attribute http_client.
9 10 11 |
# File 'lib/ecoportal/api/common/graphql/client.rb', line 9 def http_client @http_client end |
Instance Method Details
#new(org_id: self.org_id, host: self.host, schema_path: host, no_schema: @no_schema) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/ecoportal/api/common/graphql/client.rb', line 46 def new(org_id: self.org_id, host: self.host, schema_path: host, no_schema: @no_schema) self.class.new( org_id: org_id, host: host, schema_path: schema_path, no_schema: no_schema ) end |
#org_id ⇒ Object
55 56 57 |
# File 'lib/ecoportal/api/common/graphql/client.rb', line 55 def org_id @org_id || fetch_env_required('ORGANIZATION_ID') end |
#schema ⇒ Object
Graphlient/graphql-client build the client-side schema from the server's raw
introspection JSON (GraphQL::Schema.from_introspection -> GraphQL::Schema::Loader).
That loader defines one GraphQL::Schema::InputObject subclass per INPUT_OBJECT type,
but it never calls has_no_arguments(true) on the ones whose inputFields came back
empty. graphql-ruby then warns (and, in a future version, raises) the first time
anything asks such a type for its arguments -- which happens whenever this schema is
re-serialized (e.g. schema.to_json/to_definition, as the -graphql-schema use
case in eco-helpers does). The live server never emits this warning because its own
schema classes are defined directly in Ruby with real argument lists (or with
has_no_arguments(true) already set) -- it is only the client-side schema, rebuilt
purely from introspection data, that loses that annotation.
Patching the built classes here (rather than pre-processing the introspection JSON) keeps the schema's shape untouched and uses graphql-ruby's own documented escape hatch for this exact situation.
74 75 76 |
# File 'lib/ecoportal/api/common/graphql/client.rb', line 74 def schema mark_argumentless_input_objects!(super) end |