![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
gatsby-plugin-source-algolia
Advanced tools
Gatsby Plugin to source Algolia Data in a scalable manner.
npm i gatsby-plugin-source-algolia
If you're using Algolia as a psuedo-data-store or want to make build-time-rendered results pages without touching the Algolia client, this package is for you.
Unlike whatever solution you (may) have already hacked together, this plugin abstracts full Algolia object fetching into resolvers, which Gatsby can run in parallel - instead of relying on big, singular browseObjects queries that make your dev experience slow + fragile, and your build times long.
To power this - it relies on a few important assumptions:
createPages
when generating pages from Algolia dataslug
- which you can define inside the plugin's config - based on data sourced from AlgoliaUsed in production on many projects at Healthmarkets.com.
Yes!
Very! When used on Gatsby Cloud on a site with >100K pages, build times decreased ~5x without caching, compared to sourcing data in createPages. Install it and see for yourself. By running most of the data fetching inside resolvers, Gatsby can parallel our data fetching across multiple worker processes, without the choking Algolia usually experiences when returning massive pages of data.
After installing, add the plugin to your gatsby-config.js
file. You will need to add config options to setup the plugin.
Option Name | Description |
---|---|
applicationId (required) | Your Algolia application ID. |
browseObjectsApiKey (required) | Your Algolia 'all-access' browseObjects API key. |
indexName (required) | The name of your index on Algolia. |
gatsbyTypeName (required) | This will be the typename for your new data source in GraphQL. |
dependencies (required) | The data you need in advance to create your pages and slugs. This is an array of keys (string) representing keys on your Algolia object. Examples would be objectID, permalink, firstName - any data you need in advance. |
getSlug (optional) | This is a function that can implement in order to create slugs for your Algolia items - so that you can build pages with them. Return a string to source a node, return undefined to exclude the node from being sourced. More on this below. If you do not include use a function for this, all nodes will be sourced, and the slug field will be populated with the Algolia entry's objectID. |
limitItems (optional) | Optionally provide a max amount of items to source - occasionally useful when working in dev if you are having issues with connecting to Algolia. |
cacheLifetime (optional) | The max amount of time to save your Algolia records in Gatsby's cache - in hours. This will speed up your builds a lot if your Algolia data isn't changing frequently. Default is 72 hours. Set to 0 to disable. |
{
resolve: 'gatsby-plugin-source-algolia',
options: {
indexName: 'locations',
applicationId: "XXXXXXXXX",
browseObjectsApiKey: "XXXXXXXXX",
gatsbyTypeName: 'Locations',
dependencies: ['objectID', 'state', 'city', 'active'],
getSlug: (data) => {
if (data.active) {
// Return the node if the record is 'active'
return data.state + "/" + data.city
}
// Exclude this node from Gatsby if the record wasn't 'active' on Algolia
return undefined;
},
limitItems: process.env.NODE_ENV === "development" ? 10000 : undefined,
cacheLifetime: 48, // 48 hours
},
},
FAQs
Gatsby Plugin to source Algolia Data in a scalable manner.
We found that gatsby-plugin-source-algolia demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.