Class: GraphQLPreview::Instrumenter
- Inherits:
-
Object
- Object
- GraphQLPreview::Instrumenter
- Defined in:
- lib/graphql-preview/instrumenter.rb
Overview
Modify each field & argument in the schema so that its metadata contains the preview, if there is one.
Instance Method Summary collapse
-
#initialize(enabled_previews, possible_environments) ⇒ Instrumenter
constructor
A new instance of Instrumenter.
- #instrument(type, field) ⇒ Object
Constructor Details
#initialize(enabled_previews, possible_environments) ⇒ Instrumenter
Returns a new instance of Instrumenter.
5 6 7 8 |
# File 'lib/graphql-preview/instrumenter.rb', line 5 def initialize(enabled_previews, possible_environments) @enabled_previews = enabled_previews @possible_environments = possible_environments end |
Instance Method Details
#instrument(type, field) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/graphql-preview/instrumenter.rb', line 10 def instrument(type, field) # Maybe get an isolated copy that we can modify field_dup = nil if (preview = enabled_previews.find { |prev| prev.toggled_on.include?("#{type.name}.#{field.name}")}) field_dup = field.dup assign_preview(field_dup, preview) end # Return the modified copy if we made one, # otherwise return the original field_dup || field end |