【问题标题】:WordPress + Gatsby Custom Rest Route Not Showing in GraphQLWordPress + Gatsby 自定义休息路线未在 GraphQL 中显示
【发布时间】:2020-06-28 03:04:23
【问题描述】:

我对 Gatsby 还很陌生,我正在尝试使用 WP 作为内容提供者来构建一个站点。我有一个内置于 WP 的自定义休息路线 wp-json/lbt/v1/settings 现在它刚刚返回

{
"time_and_location": "Testing"
}

我似乎不知道如何在我的 Gatsby 网站的 graphQL 中获得该路线。我将它设置在我的includedRoutes 中

includedRoutes: [
 '/*/*/categories',
 '/*/*/posts',
 '/**/lbt/**',
 '/*/*/events',
 '/*/*/pages',
 '/*/*/media',
 '/*/*/tags',
 '/*/*/taxonomies',
 '/*/*/menus'
 ],

我在启动 Gatsby 时也看到了这一点

-> wordpress__lbt_v1 fetched : 1
-> wordpress__lbt_settings fetched : 1

我搜索了很多不同的网站,但没有找到任何东西。任何帮助表示赞赏。

【问题讨论】:

    标签: wordpress graphql gatsby


    【解决方案1】:

    您需要在“gatsby-config.js”中添加自定义规范器 喜欢

    ... 插件:[ ……, { 解决:“gatsby-source-wordpress”, 选项: { …… 规范化器:规范化器 => [ mapCustomApis,...规范化器], } } ……

    像这样添加“mapCustomApis”规范化器

    常量 mapCustomApis = { 名称:`mapCustomApis`, 规范化器:函数({实体}){ 返回实体.reduce((acc, e) => { 返回 acc.concat(e); }, []); } }

    【讨论】:

      猜你喜欢
      • 2012-06-18
      • 1970-01-01
      • 1970-01-01
      • 2020-04-20
      • 1970-01-01
      • 1970-01-01
      • 2020-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多