首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-apollo:长时间运行的突变似乎在2分钟后重试

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

Stack Overflow用户
提问于 2018-02-07 18:41:40
回答 1查看 639关注 0票数 2

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

我猜这是由apollo-link中的某些功能引起的,但我已经看过那里的代码,但找不到一个选项来关闭它。

下面是我如何设置apollo的:

代码语言:javascript
复制
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

变异本身并没有什么奇特之处:

代码语言:javascript
复制
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)

我只是想关闭这个重试功能。谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-12 21:48:17

我找错人了。

结果是节点的默认超时时间是2分钟,如果超时到了2分钟,它将重试请求。

在我的例子中,使用Koa,修复方法很简单:

代码语言:javascript
复制
// make timeout value 5 minutes
app.use(async (ctx, next) => {
  ctx.req.setTimeout(5 * 60 * 1000)
  await next()
})
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48661753

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档