subql icon indicating copy to clipboard operation
subql copied to clipboard

Alternative ID types

Open stwiname opened this issue 5 months ago • 0 comments

Background

Currently all entities need to have id: ID to follow the graphql spec. Internally with postgres this creates a TEXT primary key column. This can have some limitations when using numbers as the id and ordering because it will order lexicographically.

Solution

We can add an additional directive to the graphql schema to allow specifying a different underlying type.

type Entity @entity {
  id: ID @dbType(type: "serial")
}

Requirements

  • This should still be compatible with historical indexing
  • Limit the type to compatible types.
  • Compatible with schema migrations
  • Update the store interface for Id to be optional when creating new entities and return the generated id. This could be pushed to a future release.

stwiname avatar Sep 24 '24 22:09 stwiname