[createClient.ts] refactor

This commit is contained in:
Dawid Wysokiński 2021-03-21 08:39:51 +01:00
parent 03542b8564
commit 446c0cff29
1 changed files with 12 additions and 9 deletions

View File

@ -3,11 +3,11 @@ import {
InMemoryCache,
NormalizedCacheObject,
ApolloLink,
} from "@apollo/client";
import { createUploadLink } from "apollo-upload-client";
import { onError } from "@apollo/client/link/error";
import createAuthMiddleware from "./links/authMiddleware";
import TokenStorage from "libs/tokenstorage/TokenStorage";
} from '@apollo/client';
import { createUploadLink } from 'apollo-upload-client';
import { onError } from '@apollo/client/link/error';
import createAuthMiddleware from './links/authMiddleware';
import TokenStorage from 'libs/tokenstorage/TokenStorage';
const createClient = (
uri: string,
@ -19,14 +19,17 @@ const createClient = (
link: ApolloLink.from([
createAuthMiddleware(tokenStorage),
onError(({ graphQLErrors, networkError }) => {
if (process.env.NODE_ENV === "development") {
if (graphQLErrors)
graphQLErrors.map(({ message, locations, path }) =>
if (process.env.NODE_ENV === 'development') {
if (graphQLErrors) {
graphQLErrors.forEach(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
)
);
if (networkError) console.log(`[Network error]: ${networkError}`);
}
if (networkError) {
console.log(`[Network error]: ${networkError}`);
}
}
}),
createUploadLink({