繁体   English   中英

react-apollo:长时间运行的突变似乎在 2 分钟后重试

[英]react-apollo: Long running mutation appears to be retried after 2 minutes

我有一个长时间运行的导入脚本(约 4 分钟),它以 graphql 突变开始。 登录服务器,我注意到在我触发突变后恰好 2 分钟,它被重试,导致导入运行两次。

我想这是由apollo-link的某些功能引起的,但我已经查看了那里的代码,但找不到将其关闭的选项。

这是我设置阿波罗的方式:

import ApolloClient from 'apollo-client'
import { ApolloLink } from 'apollo-link'
import { createHttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import config from 'src/config'
import { getItem } from 'src/utils/local-store'

const httpLink = createHttpLink({ uri: config.graphql })
const middlewareLink = new ApolloLink((operation, forward) => {
  const token = getItem(config.jwtKey)
  if (token) {
    operation.setContext({
      headers: {
        Authorization: `Bearer ${token}`
      }
    })
  }
  return forward(operation)
})

const client = new ApolloClient({
  link: middlewareLink.concat(httpLink),
  cache: new InMemoryCache().restore(window.__APOLLO_STATE__ || {})
})

export default client

突变本身没有什么花哨的事情:

export class ReleaseImport extends PureComponent {

  // ...

  handleSaveRelease = async () => {
    const { save, artistId } = this.props
    const { id, releaseGroupId } = this.state
    await save({ variables: { release: { id, releaseGroupId }, artistId } })
  }

  // ...

}

const saveArtistRelease = gql`
  mutation ImportSaveArtistRelease($release: ImportReleaseInput!, $artistId: Int!) {
    importSaveArtistRelease(release: $release, artistId: $artistId) {
      id
    }
  }
`

export default compose(
  graphql(saveArtistRelease, {
    name: 'save'
  })
)(ReleaseImport)

只是想关闭此重试功能。 谢谢。

我叫错了树。

原来节点的默认超时是 2 分钟,如果它确实达到了 2 分钟,它将重试请求。

就我而言,使用 Koa,修复方法很简单:

// make timeout value 5 minutes
app.use(async (ctx, next) => {
  ctx.req.setTimeout(5 * 60 * 1000)
  await next()
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM