У меня длинный сценарий импорта (~ 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 минут, WILL повторит запрос.
В моем случае, используя Koa, исправление было просто:
// make timeout value 5 minutes
app.use(async (ctx, next) => {
ctx.req.setTimeout(5 * 60 * 1000)
await next()
})