project: organize apollo files

This commit is contained in:
Chika 2022-04-28 18:17:24 +03:00
parent b8ddce6f09
commit 05980e1099
4 changed files with 9 additions and 8 deletions

View File

@ -1,5 +1,4 @@
import { ApolloClient, InMemoryCache } from '@apollo/client';
import { useMemo } from 'react';
/** @type {import('@apollo/client').ApolloClient<NormalizedCacheObject>} */
let apolloClient;
@ -32,8 +31,3 @@ export function initializeApollo(initialState = null) {
return _apolloClient;
}
export function useApollo(initialState) {
const client = useMemo(() => initializeApollo(initialState), [initialState]);
return client;
}

7
apollo/hooks.js Normal file
View File

@ -0,0 +1,7 @@
import { useMemo } from 'react';
import { initializeApollo } from './client';
export function useApollo(initialState) {
const client = useMemo(() => initializeApollo(initialState), [initialState]);
return client;
}

View File

@ -1,9 +1,9 @@
import { ApolloProvider } from '@apollo/client';
import 'antd/dist/antd.less';
import { useApollo } from 'apollo/hooks';
import Layout from 'Components/Layout';
import type { AppProps } from 'next/app';
import Head from 'next/head';
import { useApollo } from 'services/crm/graphql/client';
import { ThemeProvider } from 'styled-components';
import { GlobalStyle } from 'UIKit/colors';
import theme from 'UIKit/theme';

View File

@ -1,6 +1,6 @@
import { NormalizedCacheObject } from '@apollo/client';
import { initializeApollo } from 'apollo/client';
import type { GetServerSideProps, NextPage } from 'next';
import { initializeApollo } from 'services/crm/graphql/client';
import { fetchUser } from 'services/user';
import type { User } from 'services/user/types';