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