https://github.com/algolia/gatsby-plugin-algolia
这个插件似乎在我的gatsby-config中工作,当我运行一个build (不填充我的gatsby索引) --我已经使用algoliasearch和一个json文件将数据插入到我的索引中了,但是我希望每当我构建的时候,这个插件就会自动连接起来--所以数据总是与我的可飞行数据同步。
我通过github的文档(放在我的gatsby-config.js文件中)尝试了‘gatsby-plugin’方法。
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
}
}
}
}
}`;
如果有人运行并运行了这个插件--我肯定需要一些提示来说明如何让这个插件工作(这个包上的文档不多)。
谢谢!
发布于 2018-10-12 17:43:02
弄明白了!任何遇到同样问题的人,请执行以下步骤:
transformer: ({ data }) => data.items.edges.map(({ node }) => node)
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
}
}
}
}
}`;
https://stackoverflow.com/questions/52765928
复制相似问题