react-apollo:长 运行 突变似乎在 2 分钟后重试
react-apollo: Long running mutation appears to be retried after 2 minutes
我有一个很长的 运行ning 导入脚本(约 4 分钟),它是通过 graphql 突变启动的。登录服务器,我注意到在我触发突变后整整 2 分钟,它被重试,导致导入 运行 两次。
我想这是由 apollo-link
中的某些功能引起的,但我已经查看了那里的代码,但找不到将其关闭的选项。
这是我设置 apollo 的方法:
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()
})
我有一个很长的 运行ning 导入脚本(约 4 分钟),它是通过 graphql 突变启动的。登录服务器,我注意到在我触发突变后整整 2 分钟,它被重试,导致导入 运行 两次。
我想这是由 apollo-link
中的某些功能引起的,但我已经查看了那里的代码,但找不到将其关闭的选项。
这是我设置 apollo 的方法:
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()
})