mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
First rough version of proxy logs frontend
This commit is contained in:
48
admin/src/lib/graphql.ts
Normal file
48
admin/src/lib/graphql.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { useMemo } from "react";
|
||||
import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";
|
||||
import { concatPagination } from "@apollo/client/utilities";
|
||||
|
||||
let apolloClient;
|
||||
|
||||
function createApolloClient() {
|
||||
return new ApolloClient({
|
||||
ssrMode: typeof window === "undefined",
|
||||
link: new HttpLink({
|
||||
uri: "http://localhost:3000/api/graphql",
|
||||
}),
|
||||
cache: new InMemoryCache({
|
||||
typePolicies: {
|
||||
Query: {
|
||||
fields: {
|
||||
allPosts: concatPagination(),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export function initializeApollo(initialState = null) {
|
||||
const _apolloClient = apolloClient ?? createApolloClient();
|
||||
|
||||
// If your page has Next.js data fetching methods that use Apollo Client, the initial state
|
||||
// gets hydrated here
|
||||
if (initialState) {
|
||||
// Get existing cache, loaded during client side data fetching
|
||||
const existingCache = _apolloClient.extract();
|
||||
// Restore the cache using the data passed from getStaticProps/getServerSideProps
|
||||
// combined with the existing cached data
|
||||
_apolloClient.cache.restore({ ...existingCache, ...initialState });
|
||||
}
|
||||
// For SSG and SSR always create a new Apollo Client
|
||||
if (typeof window === "undefined") return _apolloClient;
|
||||
// Create the Apollo Client once in the client
|
||||
if (!apolloClient) apolloClient = _apolloClient;
|
||||
|
||||
return _apolloClient;
|
||||
}
|
||||
|
||||
export function useApollo(initialState) {
|
||||
const store = useMemo(() => initializeApollo(initialState), [initialState]);
|
||||
return store;
|
||||
}
|
7
admin/src/lib/theme.ts
Normal file
7
admin/src/lib/theme.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { createMuiTheme } from "@material-ui/core/styles";
|
||||
import { red } from "@material-ui/core/colors";
|
||||
|
||||
// Create a theme instance.
|
||||
const theme = createMuiTheme({});
|
||||
|
||||
export default theme;
|
Reference in New Issue
Block a user