Serverless Search

Serverless Search can be used to index a database model or field.

Grafbase will automatically index the data inside the Grafbase Database for the selected model (or field), and generate a new search based query.

Model indexing can be enabled when declaring the database model:

import { g } from '@grafbase/sdk'

const user = g
  .model('Order', {
    customer: g.email(),
    total: g.int().default(0),
    shipped: g.boolean().optional().default(false),
    notes: g.string().optional()
  })
  .search()

The createdAt and updatedAt fields will be indexed too.

Field indexing can be enabled when declaring the individual fields of a database model:

import { g } from '@grafbase/sdk'

const user = g.model('Order', {
  customer: g.email().search(),
  total: g.int().default(0).search(),
  shipped: g.boolean().optional().default(false)
  notes: g.string().optional().search()
})

Fields using the type URL, PhoneNumber, String, Int, Float, Date, DateTime, Timestamp, Boolean, IPAddress, and enumerations will be indexable.

  • Only data created after search is configured will be indexed.
  • It's not currently possible to use the last argument when paginating.
Was this page helpful?