【问题标题】:trying to connect data pulled in from airtable into gatsby graphql to algolia, plugin not working试图将从空气表中提取的数据连接到 gatsby graphql 到 algolia,插件不起作用
【发布时间】:2018-10-11 17:33:23
【问题描述】:

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

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

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

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

如果有人让这个插件运行和工作——我绝对可以使用一些提示来了解如何让它工作(这个包上没有太多文档)

谢谢!

【问题讨论】:

  • 也许这需要在组件内触发?如果是这样的话,我很乐意看到这方面的文档
  • 如果有人有代码链接,很乐意看到这个功能齐全的实例
  • 我已经将配置对象上的这个推送到最后一个插件,认为它依赖于另一个方面,但它仍然没有填充 algollia
  • 想通了!首先需要正确的 API 密钥,但使用 airtable 到转换器时转换器方法也会发生变化:({ data }) => data.items.edges.map(({ node }) => node)。我使用的查询是 query { items: allAirtableLinked( filter: { table: { eq: "Items" } } ) { edges { node { id data { title thumbnail_url thumbnail_alt_text duration url_slugasset_type uberflip_stream_id uberflip_id } } } } } 并且有效!

标签: javascript reactjs algolia gatsby airtable


【解决方案1】:

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

  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

【讨论】:

  • 你使用的是 V2 还是 V1 的 Gatsby ?
  • 我使用的是 2.4.2
猜你喜欢
  • 2022-07-03
  • 2013-11-12
  • 1970-01-01
  • 2015-12-12
  • 2019-06-03
  • 2021-01-10
  • 2020-08-17
  • 2022-12-03
  • 2022-08-19
相关资源
最近更新 更多