Class: GraphQL::Schema::Finder
- Inherits:
- 
      Object
      
        - Object
- GraphQL::Schema::Finder
 
- Defined in:
- lib/graphql/schema/finder.rb
Overview
Find schema members using string paths
Defined Under Namespace
Classes: MemberNotFoundError
Instance Method Summary collapse
- 
  
    
      #find(path)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      #initialize(schema)  ⇒ Finder 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Finder. 
Constructor Details
#initialize(schema) ⇒ Finder
Returns a new instance of Finder.
| 22 23 24 | # File 'lib/graphql/schema/finder.rb', line 22 def initialize(schema) @schema = schema end | 
Instance Method Details
#find(path) ⇒ Object
| 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | # File 'lib/graphql/schema/finder.rb', line 26 def find(path) path = path.split(".") type_or_directive = path.shift if type_or_directive.start_with?("@") directive = schema.directives[type_or_directive[1..-1]] if directive.nil? raise MemberNotFoundError, "Could not find directive `#{type_or_directive}` in schema." end return directive if path.empty? find_in_directive(directive, path: path) else type = schema.get_type(type_or_directive) # rubocop:disable Development/ContextIsPassedCop -- build-time if type.nil? raise MemberNotFoundError, "Could not find type `#{type_or_directive}` in schema." end return type if path.empty? find_in_type(type, path: path) end end |