Class: WCC::Contentful::Graphql::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/wcc/contentful/graphql/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types, store) ⇒ Builder

Returns a new instance of Builder.



11
12
13
14
# File 'lib/wcc/contentful/graphql/builder.rb', line 11

def initialize(types, store)
  @types = types
  @store = store
end

Instance Attribute Details

#schema_typesObject (readonly)

Returns the value of attribute schema_types.



9
10
11
# File 'lib/wcc/contentful/graphql/builder.rb', line 9

def schema_types
  @schema_types
end

Instance Method Details

#build_schemaObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wcc/contentful/graphql/builder.rb', line 16

def build_schema
  @schema_types = build_schema_types

  root_query_type = build_root_query(@schema_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