【问题标题】:Gatsby and Strapi: Specific instances of data queried from Gatsby return null, despite existing in StrapiGatsby 和 Strapi:从 Gatsby 查询的特定数据实例返回 null,尽管 Strapi 中存在
【发布时间】:2020-11-26 22:32:14
【问题描述】:

我正在使用 Gatsby 从 Strapi 查询数据。尽管 CMS 中存在某些特定的“where”查询,但它们返回 null。这种数据的许多实例都发生了这种情况(估计 120 页中的大约 20 页。

例如,此页面根本无法呈现:https://flutterbyexample.com/lesson/bring-it-all-together

与此比较:https://flutterbyexample.com/lesson/wrap-the-pegs-in-animated-widgets

最后,当我直接 ping API 时,内容确实存在。 所以,我认为这是一个盖茨比问题。

在控制台或本地运行gatsby build 时没有错误。 gatsby clean 也无济于事。


背景信息:

  • 我从 Strapi 查询的数据位于名为 lesson 的集合下
  • Strapi 部署到 Heroku,这部分 API 是公开的

盖茨比查询:

此查询不起作用:

{
  strapiLesson(slug: {eq: "bring-it-all-together"}) {
    id
    author {
      email
      username
      twitter
    }
    content
    updated_at(formatString: "dddd, Do of MMMM, YYYY")
    slug
    strapiId
    title
    tutorial {
      category
      title
    }
  }
}


RETURNS:
{
  "data": {
    "strapiLesson": null
  }
}

为了后代,一个成功的查询:

{
  strapiLesson(slug: {eq: "about-dart"}) {
    id
    author {
      email
      username
      twitter
    }
    content
    updated_at(formatString: "dddd, Do of MMMM, YYYY")
    slug
    strapiId
    title
    tutorial {
      category
      title
    }
  }
}


RETURNS

{
  "data": {
    "strapiLesson": {
      "id": "Lesson_1",
      "author": {
        "email": "eric@ericwindmill.com",
        "username": "Eric Windmill",
        "twitter": "ericwindmill"
      },
      "content": "...",
      "updated_at": "Sunday, 12th of July, 2020",
      "slug": "about-dart",
      "strapiId": 1,
      "title": "About Dart",
      "tutorial": {
        "category": "Dart",
        "title": "Getting Started with Dart"
      }
    }
  }
}

同样,如果我使用 slug bring-it-all-together 直接为 lesson ping API,我会得到这个 JSON。所以,我知道 API 可以工作。

[
  {
    "id": 121,
    "title": "Bring it all together",
    "author": {
      "id": 1,
      "username": "Eric Windmill",
      "email": "eric@ericwindmill.com",
      "provider": "local",
      "confirmed": true,
      "blocked": false,
      "role": 1,
      "twitter": "ericwindmill",
      "bio": "Creator of Flutter by Example. Author of Flutter in Action. Located in lovely Portland, Oregon.",
      "created_at": "2020-07-06T19:22:22.529Z",
      "updated_at": "2020-07-11T16:32:52.601Z",
      "profile_image": null
    },
    "content": "...",
    "slug": "bring-it-all-together",
    "tutorial": {
      "id": 9,
      "title": "Custom Animation: Progress Indicator",
      "category": "Flutter",
      "author": 1,
      "created_at": "2020-07-24T16:49:09.645Z",
      "updated_at": "2020-07-24T16:50:23.886Z"
    },
    "created_at": "2020-08-06T15:24:05.612Z",
    "updated_at": "2020-08-06T15:24:05.624Z"
  }
]

这里最后一个有趣的事情是,再次强调 Strapi 似乎有效,当我查询与 lesson 具有一对多关联的 tutorial 时,关于 @ 的元信息987654333@ 确实有课。这是 GraphQL 查询:

{
  strapiLesson(slug: {eq: "bring-it-all-together"}) {
    id
    author {
      email
      username
      twitter
    }
    content
    updated_at(formatString: "dddd, Do of MMMM, YYYY")
    slug
    strapiId
    title
    tutorial {
      category
      title
    }
  }
  strapiTutorial(title: {eq: "Custom Animation: Progress Indicator"}) {
    lessons {
      author
      created_at
      id
      slug
      title
      tutorial
      updated_at
    }
  }
  strapiTableOfContents {
    contents
  }
}

RETURNS:

{
  "data": {
    "strapiLesson": null,  // <--- lesson data should be here
    "strapiTutorial": {
      "lessons": [
        {
          "author": 1,
          "created_at": "2020-07-24T17:01:01.352Z",
          "id": 83,
          "slug": "build-the-example-app-boiler-plate",
          "title": "Build the example app boiler-plate",
          "tutorial": 9,
          "updated_at": "2020-07-24T17:01:01.364Z"
        },
        {
          "author": 1,
          "created_at": "2020-07-24T17:41:14.728Z",
          "id": 86,
          "slug": "tween-by-example",
          "title": "Tween by example",
          "tutorial": 9,
          "updated_at": "2020-07-24T17:41:14.736Z"
        },
        {
          "author": 1,
          "created_at": "2020-07-24T17:42:02.927Z",
          "id": 88,
          "slug": "wrap-the-pegs-in-animated-widgets",
          "title": "Wrap the Pegs in AnimatedWidgets",
          "tutorial": 9,
          "updated_at": "2020-08-05T19:12:37.252Z"
        },
        {
          "author": 1,
          "created_at": "2020-07-24T17:40:51.308Z",
          "id": 85,
          "slug": "tween-and-animation-controller-classes",
          "title": "Tween and AnimationController classes",
          "tutorial": 9,
          "updated_at": "2020-07-24T17:40:51.317Z"
        },
        {
          "author": 1,
          "created_at": "2020-07-24T17:00:31.617Z",
          "id": 82,
          "slug": "progress-indicator-intro-and-overview",
          "title": "Intro and Overview",
          "tutorial": 9,
          "updated_at": "2020-07-24T17:00:31.627Z"
        },
        {
          "author": 1,
          "created_at": "2020-08-06T15:24:05.612Z",
          "id": 121,
          "slug": "bring-it-all-together",          // <-- the data exists
          "title": "Bring it all together",
          "tutorial": 9,
          "updated_at": "2020-08-06T15:24:05.624Z"
        },
        {
          "author": 1,
          "created_at": "2020-07-24T17:41:39.161Z",
          "id": 87,
          "slug": "using-tweens-and-intervals",
          "title": "Using Tweens and Intervals",
          "tutorial": 9,
          "updated_at": "2020-07-24T17:41:39.173Z"
        },
        {
          "author": 1,
          "created_at": "2020-07-24T17:01:38.537Z",
          "id": 84,
          "slug": "custom-widget-peg",
          "title": "Custom Widget: Peg",
          "tutorial": 9,
          "updated_at": "2020-07-24T17:01:38.546Z"
        }
      ]
    }
  }
}

【问题讨论】:

    标签: gatsby netlify strapi


    【解决方案1】:

    难以置信。这么愚蠢的错误。浪费时间。

    在我的gatsby-source-strapi 插件的gatsby-config 配置中,我将查询限制设置为100。

    【讨论】:

      猜你喜欢
      • 2022-07-12
      • 2021-07-20
      • 1970-01-01
      • 2021-04-13
      • 2021-06-20
      • 2022-06-28
      • 2020-10-25
      • 2020-11-07
      • 1970-01-01
      相关资源
      最近更新 更多