我将 Gatsby.js 与 Wordpress 插件结合使用来查询 Wordpress REST-API。我无法弄清楚如何使用一个查询的结果来创建另一个有效循环返回数组的动态查询。
由于我在 wordpress 中使用 ACF 灵活内容,因此在进行第一次查询之前我无法知道数据的结构。第一个查询返回已添加到 CMS 中的灵活布局的 __typenames 数组,然后我执行第二个查询,该查询返回上述每个布局的 ID。
这是我遇到砖墙的地方 - 我如何循环遍历 IDs 数组并使用现在已知的 __typename 进行查询以获取 ACF 灵活内容中列出的所有字段?
{
wordpressPage(title : {eq:"About"}) {
acf {
components_page {
__typename
// This returns an array of types
// eg [
// __typename : WordPressAcf_image_and_copy,
// __typename : WordPressAcf_body_copy
// ]
}
}
children {
id
// This returns an array of IDs
// eg [
// id : 4d2dac46-889e-593b-a00b-4a5ccaa87dfa2componentsWordPressAcf_image_and_copy,
// id : 4d2dac46-889e-593b-a00b-4a5ccaa87dfa1componentsWordPressAcf_body_copy
// ]
}
}
/*
** This is the kind of query that I need to generate dynamically
** using the type returned above along with the ID returned above :
*/
wordPressAcfImageAndCopy(id : {eq: "4d2dac46-889e-593b-a00b-4a5ccaa87dfa3componentsWordPressAcf_image_and_copy"}) {
title
subtitle
body_copy
}
}
如果我没有非常清楚地解释这一点,我深表歉意 - 我很感激任何人都可以提供的任何指示。