Sha256: fe72766e571cd39ad08504f7971f5b9d24d8ee88764da248a09a2eb73da2f73f

Contents?: true

Size: 991 Bytes

Versions: 4

Compression:

Stored size: 991 Bytes

Contents

require "graphql"
require "dry-initializer"
require "kanji/types"
require "kanji/type/attribute"
require "kanji/graph/coerce_type"

module Kanji
  class Graph
    class RegisterObject
      extend Dry::Initializer

      option :attributes, Types::Strict::Array.member(Type::Attribute)
      option :name, Types::Strict::String
      option :description, Types::Strict::String, optional: true

      def call
        name = "#{self.name}Type"
        attributes = self.attributes
        description = self.description
        coercer = Graph::CoerceType

        GraphQL::ObjectType.define do
          name name
          description description

          attributes.each do |attribute|
            field attribute.name do
              type -> { coercer.(attribute.type) }
              description attribute.description

              if attribute.resolve
                resolve attribute.resolve
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kanji-web-0.2.2 lib/kanji/graph/register_object.rb
kanji-web-0.2.1 lib/kanji/graph/register_object.rb
kanji-web-0.2.0 lib/kanji/graph/register_object.rb
kanji-web-0.1.0 lib/kanji/graph/register_object.rb