Class: Dry::GraphQL::SchemaBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/graphql/schema_builder.rb

Overview

Reduces a DRY type to a GraphQL type

Defined Under Namespace

Classes: NameGenerationError, TypeMappingError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, type: nil, schema: nil, parent: nil, options: {}) ⇒ SchemaBuilder

Returns a new instance of SchemaBuilder.



23
24
25
26
27
28
29
# File 'lib/dry/graphql/schema_builder.rb', line 23

def initialize(name: nil, type: nil, schema: nil, parent: nil, options: {})
  @name = name
  @type = type
  @schema = schema
  @options = options
  @parent = parent
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



17
18
19
# File 'lib/dry/graphql/schema_builder.rb', line 17

def field
  @field
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/dry/graphql/schema_builder.rb', line 17

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/dry/graphql/schema_builder.rb', line 17

def options
  @options
end

#parentObject (readonly)

Returns the value of attribute parent.



17
18
19
# File 'lib/dry/graphql/schema_builder.rb', line 17

def parent
  @parent
end

#schemaObject (readonly)

Returns the value of attribute schema.



17
18
19
# File 'lib/dry/graphql/schema_builder.rb', line 17

def schema
  @schema
end

#typeObject (readonly)

Returns the value of attribute type.



17
18
19
# File 'lib/dry/graphql/schema_builder.rb', line 17

def type
  @type
end

Class Method Details

.build_graphql_schema_class(name) ⇒ Object



46
47
48
49
50
51
# File 'lib/dry/graphql/schema_builder.rb', line 46

def self.build_graphql_schema_class(name)
  Dry::Core::ClassBuilder.new(
    name: "DryGraphQLGeneratedTypeFor#{name}",
    parent: ::Dry::GraphQL::BaseObject
  ).call
end

Instance Method Details

#graphql_typeObject



42
43
44
# File 'lib/dry/graphql/schema_builder.rb', line 42

def graphql_type
  reduce
end

#reduce_with(*args) ⇒ Object



38
39
40
# File 'lib/dry/graphql/schema_builder.rb', line 38

def reduce_with(*args)
  with(*args).reduce
end

#with(opts) ⇒ Object



31
32
33
34
35
36
# File 'lib/dry/graphql/schema_builder.rb', line 31

def with(opts)
  self.class.new(**{
    name: @name, type: @type, schema: @schema, options: @options,
    parent: self
  }.merge(opts))
end