【问题标题】:Gatsby WhereInput query compiles with errorsGatsby WhereInput 查询编译时出现错误
【发布时间】:2018-12-25 19:36:42
【问题描述】:

我有一个 GraphQL 查询,我可以使用 GraphQL 操场完美地运行它。

但是,当我将它放在 Gatsby 页面中时,它会引发错误并且不会提供进一步的诊断。

export const query = graphql`
  query($path: String!) {
    cms {
      headerActions: callToActions(
        where: { placement: Header, AND: { pages_some: { path: $path } } }
      ) {
        url
        label
      }
    }
  }
`

错误:

error GraphQL Error Expected a value matching type `[CMS_CallToActionWhereInput!]`, but got an object value

我不知道该往哪个方向挖掘,因为 Gatsby 没有给出任何错误细节。

【问题讨论】:

    标签: graphql gatsby


    【解决方案1】:

    错误说它需要一个 Array 但我在您的 calToAction 查询中没有看到任何数组,我想这可能会解决您的问题:

    export const query = graphql`
      query($path: String!) {
        cms {
          headerActions: callToActions(
            where: [ { placement: Header, AND: { pages_some: { path: $path } } } ]
          ) {
            url
            label
          }
        }
      }
    `
    

    【讨论】:

    • 好的,在你的帮助下弄清楚了: where: { placement: Header, AND: [{ pages_some: { path: $path } }] } 然后简化为 where: { placement: Header, pages_some: { path: $path } } 谢谢!
    猜你喜欢
    • 2021-06-12
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 2018-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多