Querying

Serverless Search can be used with the auto-generated search query.

You can query across all indexed String-like fields using the query argument.

Grafbase uses the levenshtein distance to tolerate typos of one character for words with a length or 4, or more. Typos of two characters are allowed for words with a length of 8 or more.

query {
  orderSearch(first: 50, query: "hel1o") {
    edges {
      node {
        customer
        total
      }
    }
  }
}

By default, Grafbase searches across all indexed fields but you can query to only search across precise String-like fields you set.

For example, let's only query against the field "notes":

query {
  orderSearch(first: 50, query: "hello", fields: ["notes"]) {
    edges {
      node {
        customer
        total
      }
    }
  }
}

The search query also returns the field searchInfo that contains the totalHits of the query.

For example, let's reuse the query above and request for the totalHits in the same GraphQL request:

query {
  orderSearch(
    first: 100
    filter: { total: { lte: 500 }, shipped: { eq: false } }
  ) {
    searchInfo {
      totalHits
    }
    edges {
      node {
        customer
        total
      }
    }
  }
}

The generated query for Serverless Search works similarly to Database Pagination.

query {
  orderSearch(first: 10, after: "...") {
    edges {
      node {
        customer
        total
      }
    }
  }
}
Was this page helpful?