Workspace member (#552)
* fix: clean small back-end issues * fix: apollo factory causing infinite loop on token renew * feat: small refactor and add ability to remove workspace member * fix: test
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { useMemo, useRef } from 'react';
|
||||
import { useEffect, useMemo, useRef } from 'react';
|
||||
import { InMemoryCache, NormalizedCacheObject } from '@apollo/client';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
@ -38,6 +38,8 @@ export function useApolloFactory() {
|
||||
fetchPolicy: 'cache-first',
|
||||
},
|
||||
},
|
||||
// We don't want to re-create the client on token change or it will cause infinite loop
|
||||
initialTokenPair: tokenPair,
|
||||
onTokenPairChange(tokenPair) {
|
||||
setTokenPair(tokenPair);
|
||||
},
|
||||
@ -46,11 +48,17 @@ export function useApolloFactory() {
|
||||
},
|
||||
extraLinks: [],
|
||||
isDebugMode,
|
||||
tokenPair,
|
||||
});
|
||||
|
||||
return apolloRef.current.getClient();
|
||||
}, [setTokenPair, isDebugMode, tokenPair]);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [setTokenPair, isDebugMode]);
|
||||
|
||||
useEffect(() => {
|
||||
if (apolloRef.current) {
|
||||
apolloRef.current.updateTokenPair(tokenPair);
|
||||
}
|
||||
}, [tokenPair]);
|
||||
|
||||
return apolloClient;
|
||||
}
|
||||
|
||||
@ -28,9 +28,9 @@ export interface Options<TCacheShape> extends ApolloClientOptions<TCacheShape> {
|
||||
onNetworkError?: (err: Error | ServerParseError | ServerError) => void;
|
||||
onTokenPairChange?: (tokenPair: AuthTokenPair) => void;
|
||||
onUnauthenticatedError?: () => void;
|
||||
initialTokenPair: AuthTokenPair | null;
|
||||
extraLinks?: ApolloLink[];
|
||||
isDebugMode?: boolean;
|
||||
tokenPair: AuthTokenPair | null;
|
||||
}
|
||||
|
||||
export class ApolloFactory<TCacheShape> implements ApolloManager<TCacheShape> {
|
||||
@ -44,13 +44,13 @@ export class ApolloFactory<TCacheShape> implements ApolloManager<TCacheShape> {
|
||||
onNetworkError,
|
||||
onTokenPairChange,
|
||||
onUnauthenticatedError,
|
||||
initialTokenPair,
|
||||
extraLinks,
|
||||
isDebugMode,
|
||||
tokenPair,
|
||||
...options
|
||||
} = opts;
|
||||
|
||||
this.tokenPair = tokenPair;
|
||||
this.tokenPair = initialTokenPair;
|
||||
|
||||
const buildApolloLink = (): ApolloLink => {
|
||||
const httpLink = createUploadLink({
|
||||
|
||||
Reference in New Issue
Block a user