module GraphqlGrpc::FieldDescriptorExt

Public Instance Methods

<=>(b) click to toggle source
# File lib/graphql_grpc/type_library.rb, line 83
def <=>(b)
  name <=> b.name
end
optional?() click to toggle source
# File lib/graphql_grpc/type_library.rb, line 117
def optional?
  label == :optional
end
repeated?() click to toggle source
# File lib/graphql_grpc/type_library.rb, line 121
def repeated?
  label == :repeated
end
to_gql_type(prefix) click to toggle source
# 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) click to toggle source
# 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