Module: Dry::GraphQL::Struct

Defined in:
lib/dry/graphql.rb

Overview

Extends Dry::Struct functionality

Instance Method Summary collapse

Instance Method Details

#graphql_type(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dry/graphql.rb', line 12

def graphql_type(options = {})
  return @graphql_type if @graphql_type

  graphql_name = name.to_s.gsub('::', '__')
  graphql_schema = SchemaBuilder.build_graphql_schema_class(name)
  graphql_schema.graphql_name(name)
  schema_hash = schema.each_with_object({}) do |type, memo|
    memo[type.name] = type.type
  end

  opts = { name: graphql_name, type: schema_hash, schema: graphql_schema, options: options }
  @graphql_type ||= SchemaBuilder.new(opts).graphql_type
end