Javascript 为弹性应用程序搜索构建盖茨比插件-获取graphql查询
我想创建一个本地的盖茨比插件来索引弹性应用程序搜索中的graphql查询 我的问题是,如何将graphql查询作为数组获取文章。 我需要这样的结构:Javascript 为弹性应用程序搜索构建盖茨比插件-获取graphql查询,javascript,graphql,gatsby,Javascript,Graphql,Gatsby,我想创建一个本地的盖茨比插件来索引弹性应用程序搜索中的graphql查询 我的问题是,如何将graphql查询作为数组获取文章。 我需要这样的结构: const documents = [ { id: 'INscMGmhmX4', url: 'https://www.youtube.com/watch?v=INscMGmhmX4', title: 'The Original Grumpy Cat', body: 'A wonderful video of a magnificent cat.'
const documents = [
{
id: 'INscMGmhmX4',
url: 'https://www.youtube.com/watch?v=INscMGmhmX4',
title: 'The Original Grumpy Cat',
body: 'A wonderful video of a magnificent cat.'
},
{
id: 'JNDFojsd02',
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
title: 'Another Grumpy Cat',
body: 'A great video of another cool cat.'
}
]
这是我要从Strapi索引的查询:
const myQuery = `
{
allStrapiKbArticles {
edges {
node {
id
title
content
}
}
}
}
`
下面是我当前的gatsby-node.js文件代码:
const chunk = require('lodash.chunk');
const report = require('gatsby-cli/lib/reporter');
const AppSearchClient = require ('@elastic/app-search-node');
let activity = report.activityTimer(`Indexing to ElasticSearch`);
exports.onCreateDevServer = async function (
{ graphql },
{ baseUrlFn, apiKey, queries, chunkSize = 1000 }
) {
activity.start();
const client = new AppSearchClient(undefined, apiKey, baseUrlFn)
setStatus(activity, `${queries.length} queries to index`);
const jobs = queries.map(async function doQuery(
{ engineName: engineName, query, transformer = identity, indexConfig },
i
) {
if (!query) {
report.panic(
`failed to index to Elastic. You did not give "query" to this query`
);
}
setStatus(activity, `query ${i}: executing query`);
const result = await graphql((query)
).then(result => console.log(result))
activity.end();
})
}
错误:TypeError:graphql不是函数(const result=await graphql((查询))为什么不和?@xadm我使用strapi插件从那里获取数据。但是我很难处理自己插件的gatsby-node.js文件中的代码。有一个algolia索引插件。但是我不明白他们是如何使用graphql客户机用graphql编码部件的?即使是最简单的fetch/axios也可以做到这一点,为什么不在构建期间索引,在createPage调用(标准gatsby节点用法)?当然有一种方法可以实现这一点。。。