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
-
#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
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/graphql/schema/instrumented_field_map.rb', line 12 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
30 31 32 33 |
# File 'lib/graphql/schema/instrumented_field_map.rb', line 30 def get(type_name, field_name) type = @storage[type_name] type && type[field_name] end |
#set(type_name, field_name, field) ⇒ Object
26 27 28 |
# File 'lib/graphql/schema/instrumented_field_map.rb', line 26 def set(type_name, field_name, field) @storage[type_name][field_name] = field end |