向 woocommerce wordpress store 添加更多产品后 graphql 失败

After adding more products to woocomerce wordpress store graphql fails

有人知道如何修复此 graphql 错误吗?它出现在我添加了更多的 woocomerce 产品之后。 Url 似乎不错,因为在删除部分 woocomerce 产品后,一切都恢复正常。

ERROR 

timeout of 30000ms exceeded


 ERROR #gatsby-source-wordpress_111006 

 gatsby-source-wordpress  It took too long for https://my-web-url/graphql to respond (longer than 30 seconds).

Either your URL is wrong, you need to increase server resources, or you need to decrease the amount of resources each
request takes.

You can configure how much resources each request takes by lowering your `options.schema.perPage` value from the default
of 100 nodes per request.
Alternatively you can increase the request timeout by setting a value in milliseconds to `options.schema.timeout`, the
current setting is 30000.

GraphQL request to https://my-web-url/graphql failed.

输出是不言自明的。由于要获取更多数据,您已达到超时阈值。

根据提示,您可以在 gatsby-sourde-wordpress 中添加一堆 options 来自定义该限制:

{
  resolve: `gatsby-source-wordpress`,
  options: {
    schema: {
      timeout: 30000,
    },
  },
}

timeout,默认取值为30000ms。

此外,您可以更改页面获取的节点数(perPage)。

混合两种定制:

{
  resolve: `gatsby-source-wordpress`,
  options: {
    schema: {
      timeout: 30000,
      perPage: 100,
    },
  },
}

尝试增加这些默认值,看看您的请求是否成功。

要解决此问题,您需要通过添加选项架构来提高 gatsby-config.js 文件中的超时时间。 options: {schema: { timeout: 1000000,},}

但是仅仅这样做可能是不够的,因为如果您收到超时错误,您的 wordpress 服务器要么已经过载,要么很快就会过载。您需要在 wordpress 服务器中增加分配的内存。您可以使用某些 FTP 软件(如 filezilla)并将此行添加到 wp.config 文件来完成此操作。 define( ‘WP_MEMORY_LIMIT’, ‘512M’ ); 如果您没有那么多数据,您应该选择较小的数字,例如 256MB。

在您的 gaysby-config.js 中,添加这些选项可以解决问题。

options: {
    url: `${wordPressUrl}/graphql`,
    verbose: true,
    schema: {
      timeout: 1000000,
      perPage: 10,
      requestConcurrency: 50,
      previewRequestConcurrency: 50,
    },
    develop: {....

您可以在此处查看更多选项: Timeout error gatsby development