Class: Graphlyte::Schema
Overview
Represents a schema definition, containing all type definitions available in a server Reflects the response to a [schema query](./schema_query.rb)
Defined Under Namespace
Classes: Directive, Enum, Field, InputValue, Type, TypeRef
Instance Attribute Summary collapse
-
#directives ⇒ Object
readonly
Returns the value of attribute directives.
-
#mutation_type ⇒ Object
Returns the value of attribute mutation_type.
-
#query_type ⇒ Object
Returns the value of attribute query_type.
-
#subscription_type ⇒ Object
Returns the value of attribute subscription_type.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Class Method Summary collapse
- .entity_list(entity, resp) ⇒ Object
- .entity_map(entity, resp) ⇒ Object
- .from_schema_response(response) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Schema
constructor
A new instance of Schema.
Methods inherited from Data
#==, attr_accessor, attr_reader, attributes, #dup, #eql?, #hash, #inspect
Constructor Details
#initialize ⇒ Schema
Returns a new instance of Schema.
133 134 135 136 137 138 |
# File 'lib/graphlyte/schema.rb', line 133 def initialize(**) super @types ||= {} @directives ||= {} end |
Instance Attribute Details
#directives ⇒ Object (readonly)
Returns the value of attribute directives.
131 132 133 |
# File 'lib/graphlyte/schema.rb', line 131 def directives @directives end |
#mutation_type ⇒ Object
Returns the value of attribute mutation_type.
130 131 132 |
# File 'lib/graphlyte/schema.rb', line 130 def mutation_type @mutation_type end |
#query_type ⇒ Object
Returns the value of attribute query_type.
130 131 132 |
# File 'lib/graphlyte/schema.rb', line 130 def query_type @query_type end |
#subscription_type ⇒ Object
Returns the value of attribute subscription_type.
130 131 132 |
# File 'lib/graphlyte/schema.rb', line 130 def subscription_type @subscription_type end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
131 132 133 |
# File 'lib/graphlyte/schema.rb', line 131 def types @types end |
Class Method Details
.entity_list(entity, resp) ⇒ Object
153 154 155 156 157 |
# File 'lib/graphlyte/schema.rb', line 153 def self.entity_list(entity, resp) return unless resp resp.map { entity.from_schema_response(_1) } end |
.entity_map(entity, resp) ⇒ Object
159 160 161 162 163 |
# File 'lib/graphlyte/schema.rb', line 159 def self.entity_map(entity, resp) return unless resp resp.to_h { |entry| [entry['name'], entity.from_schema_response(entry)] } end |
.from_schema_response(response) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/graphlyte/schema.rb', line 140 def self.from_schema_response(response) data = response.dig('data', '__schema') raise Argument, 'No data' unless data new( query_type: data.dig('queryType', 'name'), mutation_type: data.dig('queryType', 'name'), subscription_type: data.dig('subscriptionType', 'name'), types: entity_map(Type, data['types']), directives: entity_map(Directive, data['directives']) ) end |