Class: GraphQL::TypeKinds::TypeKind

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/type_kinds.rb,
lib/graphql/type_kinds.rb

Overview

These objects are singletons, eg `GraphQL::TypeKinds::UNION`, `GraphQL::TypeKinds::SCALAR`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, resolves: false, fields: false, wraps: false, input: false) ⇒ TypeKind

Returns a new instance of TypeKind.


6
7
8
9
10
11
12
13
# File 'lib/graphql/type_kinds.rb', line 6

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


5
6
7
# File 'lib/graphql/type_kinds.rb', line 5

def name
  @name
end

Instance Method Details

#composite?Boolean

Is this TypeKind composed of many values?

Returns:

  • (Boolean)

25
# File 'lib/graphql/type_kinds.rb', line 25

def composite?; @composite; end

#fields?Boolean

Does this TypeKind have queryable fields?

Returns:

  • (Boolean)

18
# File 'lib/graphql/type_kinds.rb', line 18

def fields?;    @fields;    end

#input?Boolean

Is this TypeKind a valid query input?

Returns:

  • (Boolean)

22
# File 'lib/graphql/type_kinds.rb', line 22

def input?;     @input;     end

#resolve(type, value) ⇒ Object

Get the implementing type for `value` from `type` (no-op for TypeKinds which don't `resolves?`)


28
29
30
31
32
33
34
# File 'lib/graphql/type_kinds.rb', line 28

def resolve(type, value)
  if resolves?
    type.resolve_type(value)
  else
    type
  end
end

#resolves?Boolean

Does this TypeKind have multiple possible implementors?

Returns:

  • (Boolean)

16
# File 'lib/graphql/type_kinds.rb', line 16

def resolves?;  @resolves;  end

#to_sObject


23
# File 'lib/graphql/type_kinds.rb', line 23

def to_s;       @name;      end

#unwrap(type) ⇒ Object

Get the modified type for `type` (no-op for TypeKinds which don't `wraps?`)


37
38
39
40
41
42
43
44
# File 'lib/graphql/type_kinds.rb', line 37

def unwrap(type)
  if wraps?
    wrapped_type = type.of_type
    wrapped_type.kind.unwrap(wrapped_type)
  else
    type
  end
end

#wraps?Boolean

Does this TypeKind modify another type?

Returns:

  • (Boolean)

20
# File 'lib/graphql/type_kinds.rb', line 20

def wraps?;     @wraps;     end