Class: WCC::Contentful::Graphql::Builder
- Inherits:
- 
      Object
      
        - Object
- WCC::Contentful::Graphql::Builder
 
- Defined in:
- lib/wcc/contentful/graphql/builder.rb
Instance Attribute Summary collapse
- 
  
    
      #root_types  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute root_types. 
- 
  
    
      #schema_types  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute schema_types. 
Instance Method Summary collapse
- #build_schema ⇒ Object
- #configure(&block) ⇒ Object
- 
  
    
      #initialize(types, store)  ⇒ Builder 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Builder. 
Constructor Details
#initialize(types, store) ⇒ Builder
Returns a new instance of Builder.
| 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | # File 'lib/wcc/contentful/graphql/builder.rb', line 15 def initialize(types, store) @types = types if types.is_a? WCC::Contentful::IndexedRepresentation @types ||= if types.is_a?(String) && File.exist?(types) WCC::Contentful::ContentTypeIndexer.load(types).types end unless @types raise ArgumentError, 'Cannot parse types - not an IndexedRepresentation ' \ "nor a schema file on disk: #{types}" end @store = store @schema_types = build_schema_types @root_types = @schema_types.dup end | 
Instance Attribute Details
#root_types ⇒ Object (readonly)
Returns the value of attribute root_types.
| 13 14 15 | # File 'lib/wcc/contentful/graphql/builder.rb', line 13 def root_types @root_types end | 
#schema_types ⇒ Object (readonly)
Returns the value of attribute schema_types.
| 12 13 14 | # File 'lib/wcc/contentful/graphql/builder.rb', line 12 def schema_types @schema_types end | 
Instance Method Details
#build_schema ⇒ Object
| 38 39 40 41 42 43 44 45 46 47 48 49 50 | # File 'lib/wcc/contentful/graphql/builder.rb', line 38 def build_schema root_query_type = build_root_query(root_types) builder = self GraphQL::Schema.define do query root_query_type resolve_type ->(_type, obj, _ctx) { content_type = WCC::Contentful::Helpers.content_type_from_raw(obj) builder.schema_types[content_type] } end end | 
#configure(&block) ⇒ Object
| 33 34 35 36 | # File 'lib/wcc/contentful/graphql/builder.rb', line 33 def configure(&block) instance_exec(&block) self end |