module GraphqlGrpc::DescriptorExt

Public Instance Methods

<=>(b) click to toggle source
# File lib/graphql_grpc/type_library.rb, line 25
def <=>(b)
  name <=> b.name
end
input_or_type(prefix) click to toggle source

Decide whether this is a GraphQL 'type' or 'input'

# File lib/graphql_grpc/type_library.rb, line 62
def input_or_type(prefix)
  return :input unless prefix.empty?

  :type
end
sub_types(known_types=[]) click to toggle source

Return an array of all (recursive) types known within this type

# File lib/graphql_grpc/type_library.rb, line 37
def sub_types(known_types=[])
  return known_types if known_types.include?(name)

  # Iterate through the Google::Protobuf::FieldDescriptor list
  entries.map do |fd|
    # fd.name = 'current_entity_to_update'
    # fd.number = 1
    # fd.label = :optional
    # fd.submsg_name = "com.foo.bar.Baz"
    # fd.subtype = #<Google::Protobuf::Descriptor:0x007fabb3947f08>
    if fd.subtype.class == Google::Protobuf::Descriptor
      [name, fd.subtype.sub_types(known_types + [name])].flatten
    else
      [name, fd.submsg_name]
    end
  end.flatten.compact.uniq
end
to_gql_type(prefix = '') click to toggle source
# File lib/graphql_grpc/type_library.rb, line 68
    def to_gql_type(prefix = '')
      if entries.any?
      <<EOF
  #{input_or_type(prefix)} #{prefix}#{type_name} {
    #{types(prefix).join("\n  ")}
  }
EOF
      else
        # For now, treat empty types as scalars
        "scalar #{prefix}#{type_name}"
      end
    end
type_name() click to toggle source
# File lib/graphql_grpc/type_library.rb, line 55
def type_name
  name.split('::').last.split('.').last
end
types(prefix) click to toggle source
# File lib/graphql_grpc/type_library.rb, line 29
def types(prefix)
  # Iterate through the Google::Protobuf::FieldDescriptor list
  entries.sort.map { |fd| fd.to_gql_type(prefix) }
end