Every time I call a query or a mutation It makes two network call and I get to items created. I tried to change the middleware but still getting the same issues. "apollo-cache-inmemory": "^1.2.2", "apollo-client": "^2.3.2", "apollo-link": "^1.2.12", "apollo-link-context": "^1.0.8", "apollo-upload-client": "^11.0.0",
I have tried reducing the middleware and changing some packages but still getting the same issue.
import { ApolloClient } from 'apollo-client'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { appConfig } from 'config'
import { ApolloLink, from } from 'apollo-link'
import { logger } from 'libs/logger'
import { fetchKeyFromSession } from 'libs/session'
import { AUTHENTICATION_TOKEN } from 'constants/index'
import { createUploadLink } from 'apollo-upload-client'
const authMiddleware = new ApolloLink((operation, forward) => {
logger(
'GraphQL Interceptor ==>> ',
operation.query.definitions[0].selectionSet.selections[0].name.value,
window.location.pathname,
operation.query.definitions[0].selectionSet.selections[0].arguments,
window.location.pathname,
operation.query.definitions[0].selectionSet.selections[0].arguments.map(
arg => arg && arg.value && arg.value.name.value,
),
)
operation.setContext({
headers: {
Authorization: `Bearer ${fetchKeyFromSession(AUTHENTICATION_TOKEN)}`
}
})
forward(operation).subscribe({
next: result => logger('Apollo Link Result ==>> ', result),
error: error => logger('Apollo Link Error ==>> ', error.response),
})
return forward(operation)
})
const uploadLink = createUploadLink({ uri: `${appConfig.config.BASE_URL}/api/v1` })
const cache = new InMemoryCache()
const defaultOptions = {
query: {
fetchPolicy: 'no-cache',
errorPolicy: 'all',
},
}
export const client = new ApolloClient({
link: from([authMiddleware, uploadLink]),
cache,
defaultOptions,
queryDeduplication: false
})
It's not throwing any error at all but it should call the query/mutation only once not twice. I got two items created in the database due to this.