Struggling to sync Airtable data with Algolia via Gatsby GraphQL - plugin issues

Hey everyone,

I’m having trouble with the Gatsby Algolia plugin. It’s not populating my Algolia index when I run a build. I’ve already managed to push data to my index using algoliasearch and a JSON file, but I want this process to be automatic whenever I build, so my Algolia data stays in sync with my Airtable data.

I’ve tried setting up the plugin in my gatsby-config.js file as per the docs, but no luck. Here’s a simplified version of what I’ve got:

const myQuery = `{
  allAirtableLinked(filter: { table: { eq: \"Items\" } }) {
    edges {
      node {
        id
        data {
          title
          url_slug
        }
      }
    }
  }
}`;

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-source-airtable-linked',
      options: { /* Airtable config */ },
    },
    {
      resolve: 'gatsby-plugin-algolia',
      options: {
        appId: process.env.ALGOLIA_APP_ID,
        apiKey: process.env.ALGOLIA_API_KEY,
        indexName: 'myIndex',
        queries: [
          {
            query: myQuery,
            transformer: ({ data }) => data.allAirtableLinked.edges.map(({ node }) => node),
          },
        ],
      },
    },
  ],
};

Has anyone got this plugin working? Any tips would be super helpful. Thanks!

I’ve been there, John. The Gatsby Algolia plugin can be tricky. One thing that helped me was implementing a custom transformer function. Instead of using the default, try something like this:

transformer: ({ data }) => {
  const items = data.allAirtableLinked.edges.map(({ node }) => {
    return {
      objectID: node.id,
      title: node.data.title,
      slug: node.data.url_slug
    };
  });
  return items;
},

This way, you have more control over the data structure sent to Algolia. Also, make sure you’re running ‘gatsby build’ and not just ‘gatsby develop’ - the plugin only runs during the build process.

If you’re still having issues, try adding some console.log statements in your transformer function to see what data is actually being processed. Sometimes the problem is in the data structure coming from Airtable, not the plugin itself.

I’ve encountered similar problems with the Gatsby Algolia plugin. One often overlooked issue is the Algolia index settings. Ensure your index is properly configured in the Algolia dashboard, especially regarding searchable attributes and custom ranking.

Another potential pitfall is the Gatsby cache. Try running ‘gatsby clean’ before rebuilding. This clears the cache and can resolve unexpected behavior.

Additionally, consider implementing a separate script that runs post-build to verify the Algolia index update. This can help pinpoint whether the issue lies with the plugin or the build process itself.

Lastly, check your Algolia plan limits. Some plans have restrictions on index operations, which could silently fail during builds. If all else fails, reaching out to Algolia support can provide valuable insights specific to your setup.

hi john_fast, i’ve had similar issues. make sure ur env variables are set correctly and try adding a chunkSize option to the plugin config. Also, double-check ur query - sometimes the structure needs tweaking. if that doesn’t work, u might need to debug the transformer function. good luck!