试图将从 airtable 中提取的数据连接到 gatsby graphql 到 algolia,插件不工作

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

https://github.com/algolia/gatsby-plugin-algolia

当我 运行 一个构建(没有填充我的 algolia 索引)时,这个插件似乎没有在我的 gatsby-config 中工作——我已经使用 algoliasearch 将数据推送到我的索引中和一个 json 文件,但我希望它在我构建时自动连接 - 因此数据始终与我的 airtable 数据保持同步。

我已经通过 github 上的文档尝试了 'gatsby-plugin-algolia' 方法(放在我的 gatsby-config.js 文件中)

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,
      },
    },
  ],
};

我还通过 airtable 在组件上使用的更具体的实例替换了 'myQuery',如下所示

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
          }
        }
      }
    }
    }`;

如果有人有这个插件 运行正在运行 - 我绝对可以使用一些提示来说明如何让它工作(关于这个包的文档不多)

谢谢!

想通了!任何 运行 遇到同样问题的人,请执行以下步骤:

  1. 检查您是否拥有正确的 API 密钥
  2. 检查转换器方法是否更改以匹配在 graphql 中查询的对象。我的不得不改成这个:

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

  1. 检查你的查询是否在 graphql 中有效,确保它在语法上是正确的,并且正在提取正确的数据。我使用的查询是

const pageQuery = `query {
  items: allAirtableLinked(
    filter: {
      table: { eq: "Items" }
      data: { hubs: { eq: "cf4ao8fjzn4xsRrD" } }
    }
  ) {
    edges {
      node {
        id
        data {
          title
          thumbnail_url
          thumbnail_alt_text
          duration
          url_slug
          asset_type
          uberflip_stream_id
          uberflip_id
        }
      }
    }
  }
}`;

  1. 最后,如果将查询和查询抽象到 src 中的 ultil 目录中,然后将其要求到配置文件中,这样会更干净:

i got this idea from this repo, very helpful! check out this example