Skip to content

Commit 2a1dd13

Browse files
author
Robert Mosolgo
authored
Merge pull request rmosolgo#1753 from RobertWSaunders/explicitly-define-type-kind-predicate-methods
Explicitly define type kind predicate methods
2 parents 0f0eef8 + d523f48 commit 2a1dd13

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

lib/graphql/type_kinds.rb

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,38 @@ def input?; @input; end
2929
def to_s; @name; end
3030
# Is this TypeKind composed of many values?
3131
def composite?; @composite; end
32+
33+
def scalar?
34+
self == TypeKinds::SCALAR
35+
end
36+
37+
def object?
38+
self == TypeKinds::OBJECT
39+
end
40+
41+
def interface?
42+
self == TypeKinds::INTERFACE
43+
end
44+
45+
def union?
46+
self == TypeKinds::UNION
47+
end
48+
49+
def enum?
50+
self == TypeKinds::ENUM
51+
end
52+
53+
def input_object?
54+
self == TypeKinds::INPUT_OBJECT
55+
end
56+
57+
def list?
58+
self == TypeKinds::LIST
59+
end
60+
61+
def non_null?
62+
self == TypeKinds::NON_NULL
63+
end
3264
end
3365

3466
TYPE_KINDS = [
@@ -41,13 +73,5 @@ def composite?; @composite; end
4173
LIST = TypeKind.new("LIST", wraps: true, description: 'Indicates this type is a list. `ofType` is a valid field.'),
4274
NON_NULL = TypeKind.new("NON_NULL", wraps: true, description: 'Indicates this type is a non-null. `ofType` is a valid field.'),
4375
]
44-
45-
class TypeKind
46-
TYPE_KINDS.map(&:name).each do |kind_name|
47-
define_method("#{kind_name.downcase}?") do
48-
self.name == kind_name
49-
end
50-
end
51-
end
5276
end
5377
end

0 commit comments

Comments
 (0)