Sha256: 7ea6b62d158e12d391137bde898e621c78f670131aee5e9747bacd1a02aa1641
Contents?: true
Size: 1.26 KB
Versions: 2
Compression:
Stored size: 1.26 KB
Contents
module GraphQL class Schema # 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. class InstrumentedFieldMap # Build a map using types from `schema` and instrumenters in `field_instrumenters` # @param schema [GraphQL::Schema] # @param field_instrumenters [Array<#instrument(type, field)>] 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 def set(type_name, field_name, field) @storage[type_name][field_name] = field end def get(type_name, field_name) type = @storage[type_name] type && type[field_name] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
graphql-1.2.6 | lib/graphql/schema/instrumented_field_map.rb |
graphql-1.2.5 | lib/graphql/schema/instrumented_field_map.rb |