Amplify Algolia Search

thefinnomenon

Chris Finn

Posted on July 27, 2021

Amplify Algolia Search

I built a custom directive to enable searching with Algolia:
https://github.com/thefinnomenon/graphql-algolia-transformer

It has been a pleasure building MVPs with Amplify but I was annoyed at the monthly cost of Elasticsearch and wanted a search that fits the Serverless "pay per use" model -- enter Algolia. It has a decent free monthly quota so you can make a low cost MVP or small app. It also has a really simple management interface and solid client libraries and UI widgets.

I created a simple searchable blog example (which turned more into a recipe search 😆) that can be found in the Github repo. If you need to add search to your Amplify project, give this transformer a shot.

type Blog @model {
  id: ID!
  name: String!
  posts: [Post] @connection(keyName: "byBlog", fields: ["id"])
}

type Post @model @algolia(fields:{include:["title"]}) @key(name: "byBlog", fields: ["blogID"]) {
  id: ID!
  title: String!
  blogID: ID!
  blog: Blog @connection(fields: ["blogID"])
  comments: [Comment] @connection(keyName: "byPost", fields: ["id"])
}

type Comment @model @key(name: "byPost", fields: ["postID", "content"]) {
  id: ID!
  postID: ID!
  post: Post @connection(fields: ["postID"])
  content: String!
}
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
thefinnomenon
Chris Finn

Posted on July 27, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Amplify Algolia Search
aws Amplify Algolia Search

July 27, 2021