algolia / gatsby-plugin-algolia

A plugin to push to Algolia based on graphQl queries
https://yarn.pm/gatsby-plugin-algolia
Apache License 2.0
179 stars 45 forks source link

trying to connect data pulled in from airtable into gatsby graphql to algolia, plugin not working #15

Closed rosettazach closed 6 years ago

rosettazach commented 6 years ago

this plugin doesn't seem to be working in my gatsby-config when i run a build (doesn't populate my algolia index) -- i've already pushed data into my index using algoliasearch and a json file, but i want this to be automatically hooked up whenever i build -- so the data is always current with my airtable data.

i've tried the 'gatsby-plugin-algolia' approach via the documentation on github (placed in my gatsby-config.js file)

const myQuery = `{
  allSitePage {
    edges {
      node {
        # try to find a unique id for each node
        # if this field is absent, it's going to
        # be inserted by Algolia automatically
        # and will be less simple to update etc.
        objectID: id
        component
        path
        componentChunkName
        jsonName
        internal {
          type
          contentDigest
          owner
        }
      }
    }
  }
}`;

const queries = [
  {
    query: myQuery,
    transformer: ({ data }) => data.allSitePage.edges.map(({ node }) => node), 
    indexName: 'cardDemo',
  },
];

module.exports = {
  plugins: [
        {
      resolve: 'gatsby-source-airtable-linked',
      options: {
        apiKey: process.env.MY_API_KEY,
        tables: [
          {
            baseId: process.env.MY_BASE_ID,
            tableName: 'Streams',
            tableView: 'DO NOT MODIFY',
          },
        ],
      },
    },
    {
      resolve: 'gatsby-plugin-algolia',
      options: {
        appId: process.env.MY_AGOLIA_APP_ID,
        apiKey: process.env.MY_AGOLIA_API_KEY,
        indexName: 'cardDemo',
        queries,
        chunkSize: 1000000,
      },
    },
  ],
};

i've also subbed out the 'myQuery' for a more specific instance that i'm using on a component via airtable, shown below

const myQuery = `{
      items: allAirtableLinked(
      filter: {
        table: { eq: "Items" }
      }
    ) {
      edges {
        node {
          id
          data {
            title
            thumbnail_url
            thumbnail_alt_text
            url_slug
            uberflip_stream_id
            uberflip_id
          }
        }
      }
    }
    }`;

if anyone has this plugin running and working -- i could definitely use some hints as to how to get this working (not much documentation on this package)

thank you!

Haroenv commented 6 years ago

There's an example in this repo that works, and https://github.com/StudentenBildenSchueler/homepage and https://github.com/TryGhost/docs/blob/algolia/gatsby-config.js which work too.

You sent me an email as well, but I think it's likely to do with some conflict between the two queries? Can you send me the full code with API keys (via email) so I can try it out on my end?

rosettazach commented 6 years ago

this was a huge help thanks! i got it working with the help of the studenten repo !

firstly, i need the proper API key...

but also the transformer method changes when using airtable to

transformer: ({ data }) => data.items.edges.map(({ node }) => node).

then, the query i used was:

 query {
  items: allAirtableLinked(
    filter: { table: { eq: "Items" } }
  ) {
    edges {
      node {
        id
        data {
          title
          thumbnail_url
          thumbnail_alt_text
          duration
          url_slug
          asset_type
          uberflip_stream_id
          uberflip_id
        }
      }
    }
  }
} 

and it worked!

ethaneisenhard commented 5 years ago

@rosettazach do you think you could publish a working example for the site you built? I want to use the same stack and think your work would help a lot in the process. thanks!