Skip to content

Commit

Permalink
experiment: faster boolean accessor methods
Browse files Browse the repository at this point in the history
  • Loading branch information
amomchilov committed Sep 2, 2024
1 parent a5e12e8 commit 7e10088
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions lib/graphql/type_kinds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,41 @@ def initialize(name, abstract: false, leaf: false, fields: false, wraps: false,
@description = description
end

# Is this TypeKind abstract?
attr_reader :abstract
alias_method :abstract?, :abstract
remove_method :abstract

# Does this TypeKind have multiple possible implementers?
# @deprecated Use `abstract?` instead of `resolves?`.
def resolves?; @abstract; end
# Is this TypeKind abstract?
def abstract?; @abstract; end
alias_method :resolves?, :abstract?

# Does this TypeKind have queryable fields?
def fields?; @fields; end
attr_reader :fields
alias_method :fields?, :fields
remove_method :fields

# Does this TypeKind modify another type?
def wraps?; @wraps; end
attr_reader :wraps
alias_method :wraps?, :wraps
remove_method :wraps

# Is this TypeKind a valid query input?
def input?; @input; end
def to_s; @name; end
attr_reader :input
alias_method :input?, :input
remove_method :input

# Is this TypeKind a primitive value?
def leaf?; @leaf; end
attr_reader :leaf
alias_method :leaf?, :leaf
remove_method :leaf

# Is this TypeKind composed of many values?
def composite?; @composite; end
attr_reader :composite
alias_method :composite?, :composite
remove_method :composite

alias_method :to_s, :name

def scalar?
self == TypeKinds::SCALAR
Expand Down

0 comments on commit 7e10088

Please sign in to comment.