如何为 graphql-client 设置超时

Pra*_*har 7 apollo graphql graphql-js apollo-client prisma-graphql

我正在尝试timeout设置prisma-labs/graphql-request. 我已经尝试过此处描述的方法 - https://github.com/prisma-labs/graphql-request/issues/103

const client = new GraphQLClient(config.url, {
  timeout: 30000,
  headers: {
    Authorization: `Bearer ${token}`
  }
})
Run Code Online (Sandbox Code Playgroud)

我的编译器抱怨超时没有直接出现在选项界面中 - https://github.com/prisma-labs/graphql-request/blob/master/src/types.ts#L7

我是否需要扩展选项接口以使用超时字段?

小智 0

如果您通过常规 api 为您的服务调用此服务,请记住它也可能在您的网络服务器(例如express或fastify)上超时,尝试增加那里的所有超时,例如

fastify: {
  trustProxy: true,
  connectionTimeout: 15000,
},
Run Code Online (Sandbox Code Playgroud)