Skip to content



fieldname: FieldType @bb_primaryKey


The @bb_primaryKey directive specifies that a field in a GraphQL object serves as the primary key for the corresponding database table. A primary key is an identifier in a database table that allows someone to uniquely identify a record in a database table.


If an object type has a single field of type ID, the compiler will assume that this is the corresponding table's primary key. This will be created as an autogenerated UUID column in the database. If you would like to create an alternative primary key to the ID field, have a primary key of a different type (e.g. externalId: String! in a type) or have multiple ID fields in an object type then it is essential to use the @bb_primaryKey directive.*


Externally generated primary key
type Patient {
  # The reference number refers to an externally generated reference number
  referenceNumber: String @bb_primaryKey
  name: String!
  databaseId: ID!
In this example, the Patient object uses a reference number as the primary key for the corresponding table created in the database. We have also added a databaseId that is of type ID. This will be created as a UUID field and be autogenerated by the database. It is however not the primary key here.

Multiple ID fields in an object type
type Demo {
  id: ID! @bb_primaryKey
  id2: ID!
In the above example, the object type has two ID fields. The compiler cannot assume which one is the primary key so the @bb_primaryKey directive has to be specified.