Class: Tina4::GraphQLType
- Inherits:
-
Object
- Object
- Tina4::GraphQLType
- Defined in:
- lib/tina4/graphql.rb
Overview
─── Type System ──────────────────────────────────────────────────────
Constant Summary collapse
- SCALARS =
%w[String Int Float Boolean ID].freeze
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.parse(type_str) ⇒ Object
Parse a type string like “String”, “String!”, “[String]”, “[Int!]!”.
Instance Method Summary collapse
-
#initialize(name, kind = :object, fields: {}, of_type: nil, description: nil) ⇒ GraphQLType
constructor
kind: :scalar, :object, :list, :non_null, :input_object, :enum.
- #list? ⇒ Boolean
- #non_null? ⇒ Boolean
- #of_type ⇒ Object
- #scalar? ⇒ Boolean
Constructor Details
#initialize(name, kind = :object, fields: {}, of_type: nil, description: nil) ⇒ GraphQLType
kind: :scalar, :object, :list, :non_null, :input_object, :enum
18 19 20 21 22 23 24 |
# File 'lib/tina4/graphql.rb', line 18 def initialize(name, kind = :object, fields: {}, of_type: nil, description: nil) @name = name @kind = kind.to_sym @fields = fields # { field_name => { type:, args:, resolve:, description: } } @of_type = of_type # wrapped type for list / non_null @description = description end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
15 16 17 |
# File 'lib/tina4/graphql.rb', line 15 def description @description end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
15 16 17 |
# File 'lib/tina4/graphql.rb', line 15 def fields @fields end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
15 16 17 |
# File 'lib/tina4/graphql.rb', line 15 def kind @kind end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/tina4/graphql.rb', line 15 def name @name end |
Class Method Details
.parse(type_str) ⇒ Object
Parse a type string like “String”, “String!”, “[String]”, “[Int!]!”
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tina4/graphql.rb', line 43 def self.parse(type_str) type_str = type_str.to_s.strip if type_str.end_with?("!") inner = parse(type_str[0..-2]) new(type_str, :non_null, of_type: inner) elsif type_str.start_with?("[") && type_str.end_with?("]") inner = parse(type_str[1..-2]) new(type_str, :list, of_type: inner) elsif SCALARS.include?(type_str) new(type_str, :scalar) else new(type_str, :object) end end |
Instance Method Details
#list? ⇒ Boolean
30 31 32 |
# File 'lib/tina4/graphql.rb', line 30 def list? @kind == :list end |
#non_null? ⇒ Boolean
34 35 36 |
# File 'lib/tina4/graphql.rb', line 34 def non_null? @kind == :non_null end |
#of_type ⇒ Object
38 39 40 |
# File 'lib/tina4/graphql.rb', line 38 def of_type @of_type end |
#scalar? ⇒ Boolean
26 27 28 |
# File 'lib/tina4/graphql.rb', line 26 def scalar? @kind == :scalar || SCALARS.include?(@name) end |