Sha256: 2380c3e3c9dd9d8d6f3e2b9103d46253d448ad3475e9ec151a96b788b029a1dc

Contents?: true

Size: 1.64 KB

Versions: 20

Compression:

Stored size: 1.64 KB

Contents

# Type kinds are the basic categories which a type may belong to (`Object`, `Scalar`, `Union`...)
module GraphQL::TypeKinds
  # These objects are singletons, eg `GraphQL::TypeKinds::UNION`, `GraphQL::TypeKinds::SCALAR`.
  class TypeKind
    attr_reader :name
    def initialize(name, resolves: false, fields: false, wraps: false, input: false)
      @name = name
      @resolves = resolves
      @fields = fields
      @wraps = wraps
      @input = input
      @composite = fields? || resolves?
    end

    # Does this TypeKind have multiple possible implementors?
    def resolves?;  @resolves;  end
    # Does this TypeKind have queryable fields?
    def fields?;    @fields;    end
    # Does this TypeKind modify another type?
    def wraps?;     @wraps;     end
    # Is this TypeKind a valid query input?
    def input?;     @input;     end
    def to_s;       @name;      end
    # Is this TypeKind composed of many values?
    def composite?; @composite; end
  end

  TYPE_KINDS = [
    SCALAR =        TypeKind.new("SCALAR", input: true),
    OBJECT =        TypeKind.new("OBJECT", fields: true),
    INTERFACE =     TypeKind.new("INTERFACE", resolves: true, fields: true),
    UNION =         TypeKind.new("UNION", resolves: true),
    ENUM =          TypeKind.new("ENUM", input: true),
    INPUT_OBJECT =  TypeKind.new("INPUT_OBJECT", input: true),
    LIST =          TypeKind.new("LIST", wraps: true),
    NON_NULL =      TypeKind.new("NON_NULL", wraps: true),
  ]

  KIND_NAMES = TYPE_KINDS.map(&:name)
  class TypeKind
    KIND_NAMES.each do |kind_name|
      define_method("#{kind_name.downcase}?") do
        self.name == kind_name
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
graphql-0.12.1 lib/graphql/type_kinds.rb
graphql-0.12.0 lib/graphql/type_kinds.rb
graphql-0.11.1 lib/graphql/type_kinds.rb
graphql-0.11.0 lib/graphql/type_kinds.rb
graphql-0.10.9 lib/graphql/type_kinds.rb
graphql-0.10.8 lib/graphql/type_kinds.rb
graphql-0.10.7 lib/graphql/type_kinds.rb
graphql-0.10.6 lib/graphql/type_kinds.rb
graphql-0.10.5 lib/graphql/type_kinds.rb
graphql-0.10.4 lib/graphql/type_kinds.rb
graphql-0.10.3 lib/graphql/type_kinds.rb
graphql-0.10.2 lib/graphql/type_kinds.rb
graphql-0.10.1 lib/graphql/type_kinds.rb
graphql-0.10.0 lib/graphql/type_kinds.rb
graphql-0.9.5 lib/graphql/type_kinds.rb
graphql-0.9.4 lib/graphql/type_kinds.rb
graphql-0.9.3 lib/graphql/type_kinds.rb
graphql-0.9.2 lib/graphql/type_kinds.rb
graphql-0.8.1 lib/graphql/type_kinds.rb
graphql-0.8.0 lib/graphql/type_kinds.rb