Class: GraphQL::Schema::InstrumentedFieldMap
- Inherits:
-
Object
- Object
- GraphQL::Schema::InstrumentedFieldMap
- Defined in:
- lib/graphql/schema/instrumented_field_map.rb
Overview
A two-level map with fields as the last values. The first level is type names, which point to a second map. The second level is field names, which point to fields.
The catch is, the fields in this map may have been modified by being instrumented.
Instance Method Summary collapse
- #get(type_name, field_name) ⇒ Object
- #get_all(type_name) ⇒ Object
-
#initialize(schema, field_instrumenters) ⇒ InstrumentedFieldMap
constructor
Build a map using types from
schema
and instrumenters infield_instrumenters
. - #set(type_name, field_name, field) ⇒ Object
Constructor Details
#initialize(schema, field_instrumenters) ⇒ InstrumentedFieldMap
Build a map using types from schema
and instrumenters in field_instrumenters
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/graphql/schema/instrumented_field_map.rb', line 13 def initialize(schema, field_instrumenters) @storage = Hash.new { |h, k| h[k] = {} } schema.types.each do |type_name, type| if type.kind.fields? type.all_fields.each do |field_defn| instrumented_field_defn = field_instrumenters.reduce(field_defn) do |defn, inst| inst.instrument(type, defn) end self.set(type.name, field_defn.name, instrumented_field_defn) end end end end |
Instance Method Details
#get(type_name, field_name) ⇒ Object
31 32 33 |
# File 'lib/graphql/schema/instrumented_field_map.rb', line 31 def get(type_name, field_name) @storage[type_name][field_name] end |
#get_all(type_name) ⇒ Object
35 36 37 |
# File 'lib/graphql/schema/instrumented_field_map.rb', line 35 def get_all(type_name) @storage[type_name] end |
#set(type_name, field_name, field) ⇒ Object
27 28 29 |
# File 'lib/graphql/schema/instrumented_field_map.rb', line 27 def set(type_name, field_name, field) @storage[type_name][field_name] = field end |