Module: GraphqlGrpc::FieldDescriptorExt
- Defined in:
- lib/graphql_grpc/type_library.rb
Instance Method Summary collapse
- #<=>(b) ⇒ Object
- #optional? ⇒ Boolean
- #repeated? ⇒ Boolean
- #to_gql_type(prefix) ⇒ Object
- #to_gql_type_field(prefix) ⇒ Object
Instance Method Details
#<=>(b) ⇒ Object
83 84 85 |
# File 'lib/graphql_grpc/type_library.rb', line 83 def <=>(b) name <=> b.name end |
#optional? ⇒ Boolean
117 118 119 |
# File 'lib/graphql_grpc/type_library.rb', line 117 def optional? label == :optional end |
#repeated? ⇒ Boolean
121 122 123 |
# File 'lib/graphql_grpc/type_library.rb', line 121 def repeated? label == :repeated end |
#to_gql_type(prefix) ⇒ Object
125 126 127 |
# File 'lib/graphql_grpc/type_library.rb', line 125 def to_gql_type(prefix) "#{name}: #{to_gql_type_field(prefix)}" end |
#to_gql_type_field(prefix) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/graphql_grpc/type_library.rb', line 87 def to_gql_type_field(prefix) t = case type when :int64, :int32, :uint32, :uint64 'Int' when :string 'String' when :bool, :boolean 'Boolean' when :double, :float 'Float' when :message prefix + submsg_name.to_s.split('.').last when :enum # Enums are interesting; for Google::Protobuf::FieldDescriptor fd # fd.type = :enum # fd.subtype. = Google::Protobuf::EnumDescriptor # fd.submsg_name = 'com.foo.bar.Baz # ed = fd.subtype # ed.entries. = [[:OUT, 0], [:IN, 1]] # prefix + submsg_name.to_s.split('.')[-2..-1].join('_') else type.to_s + '--Unknown' end return "[#{t}]" if repeated? return "#{t}!" unless optional? t end |