Ok, as per your index.js file I see how subscriptions are handled in apollo-client 2.0. But how are applyBatchAfterware and applyBatchMiddleware handled in 2.0?
Currently in apollo-client 1.9.2, which I would like to convert to 2.0, I'm doing the following:
const logErrors = {
applyBatchAfterware({ response }, next) {
if (!response) return next();
if (!response.ok) {
response.clone().text().then((bodyText) => {
console.log('...', `Network Error: ${response.status} (${response.statusText}) - ${bodyText}`);
next();
});
} else {
response.clone().json().then(({ errors }) => {
if (errors) {
console.log('...', 'GraphQL Errors:', errors.map(e => e.message));
}
next();
});
}
},
};
const authMiddleware = {
applyBatchMiddleware(req, next) {
if (!req.options.headers) {
req.options.headers = {};
}
getStoredState({ storage: localForage }, (err, state = {}) => {
req.options.headers['authorization'] = state.auth ? `Bearer ${state.auth.token}` : null;
next();
});
}
}
const wsClient = new SubscriptionClient(SubscriptionClient_URL, {
reconnect: true,
});
networkInterface.use([authMiddleware]);
if (process.env.NODE_ENV !== 'production') {
networkInterface.useAfter([logErrors]);
}
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
networkInterface,
wsClient
);
const client = new ApolloClient({
networkInterface: networkInterfaceWithSubscriptions,
dataIdFromObject: (o) => o.id,
addTypeName: true,
});
networkInterface.setClient(client);
export default client;