From 05980e1099e09e93532c1ffef2f33c8d570e66af Mon Sep 17 00:00:00 2001 From: Chika Date: Thu, 28 Apr 2022 18:17:24 +0300 Subject: [PATCH] project: organize apollo files --- {services/crm/graphql => apollo}/client.js | 6 ------ apollo/hooks.js | 7 +++++++ pages/_app.tsx | 2 +- pages/index.tsx | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) rename {services/crm/graphql => apollo}/client.js (85%) create mode 100644 apollo/hooks.js diff --git a/services/crm/graphql/client.js b/apollo/client.js similarity index 85% rename from services/crm/graphql/client.js rename to apollo/client.js index 2d86319..27b68e8 100644 --- a/services/crm/graphql/client.js +++ b/apollo/client.js @@ -1,5 +1,4 @@ import { ApolloClient, InMemoryCache } from '@apollo/client'; -import { useMemo } from 'react'; /** @type {import('@apollo/client').ApolloClient} */ 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; -} diff --git a/apollo/hooks.js b/apollo/hooks.js new file mode 100644 index 0000000..b2d092c --- /dev/null +++ b/apollo/hooks.js @@ -0,0 +1,7 @@ +import { useMemo } from 'react'; +import { initializeApollo } from './client'; + +export function useApollo(initialState) { + const client = useMemo(() => initializeApollo(initialState), [initialState]); + return client; +} diff --git a/pages/_app.tsx b/pages/_app.tsx index 3806f71..23cd5d6 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -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'; diff --git a/pages/index.tsx b/pages/index.tsx index 0d1d527..10c1033 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -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';