refactor(dashboard): remove code related to apollo

This commit is contained in:
Nicolas Meienberger 2023-02-11 23:52:32 +01:00 committed by Nicolas Meienberger
parent 36a6483ff7
commit 365f2fb1ab
11 changed files with 46 additions and 2139 deletions

View file

@ -1,9 +0,0 @@
overwrite: true
schema: "http://localhost:3000/api-legacy/graphql"
documents: "src/client/graphql/**/*.graphql"
generates:
src/client/generated/graphql.tsx:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"

View file

@ -12,11 +12,9 @@
"build": "next build",
"start": "NODE_ENV=production node server.js",
"lint": "next lint",
"lint:fix": "next lint --fix",
"gen": "graphql-codegen --config codegen.yml"
"lint:fix": "next lint --fix"
},
"dependencies": {
"@apollo/client": "^3.6.8",
"@hookform/resolvers": "^2.9.10",
"@prisma/client": "^4.8.0",
"@runtipi/postgres-migrations": "^5.3.0",
@ -35,6 +33,7 @@
"isomorphic-fetch": "^3.0.0",
"jsonwebtoken": "^9.0.0",
"next": "13.1.1",
"node-cron": "^3.0.1",
"pg": "^8.7.3",
"react": "18.2.0",
"react-dom": "18.2.0",
@ -60,10 +59,6 @@
"devDependencies": {
"@babel/core": "^7.0.0",
"@faker-js/faker": "^7.6.0",
"@graphql-codegen/cli": "^2.6.2",
"@graphql-codegen/typescript": "^2.5.1",
"@graphql-codegen/typescript-operations": "^2.4.2",
"@graphql-codegen/typescript-react-apollo": "^3.2.16",
"@testing-library/dom": "^8.19.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
@ -73,6 +68,7 @@
"@types/jest": "^29.2.4",
"@types/jsonwebtoken": "^9.0.0",
"@types/node": "18.11.18",
"@types/node-cron": "^3.0.2",
"@types/pg": "^8.6.5",
"@types/react": "18.0.8",
"@types/react-dom": "18.0.3",

View file

@ -1,11 +0,0 @@
import { ApolloClient, from, InMemoryCache } from '@apollo/client';
import links from './links';
export const createApolloClient = (): ApolloClient<unknown> => {
const additiveLink = from([links.errorLink, links.authLink, links.httpLink]);
return new ApolloClient({
link: additiveLink,
cache: new InMemoryCache(),
});
};

View file

@ -1,14 +0,0 @@
import { setContext } from '@apollo/client/link/context';
const authLink = setContext((_, { headers }) => {
const token = localStorage.getItem('token');
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : '',
},
};
});
export default authLink;

View file

@ -1,14 +0,0 @@
import { onError } from '@apollo/client/link/error';
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.forEach(({ message, locations, path }) => {
console.warn(`Error link [GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
});
if (networkError) {
console.warn(`Error link [Network error]: ${networkError}`);
}
});
export default errorLink;

View file

@ -1,7 +0,0 @@
import { HttpLink } from '@apollo/client';
const httpLink = new HttpLink({
uri: '/api-legacy/graphql',
});
export default httpLink;

View file

@ -1,11 +0,0 @@
import errorLink from './errorLink';
import httpLink from './httpLink';
import authLink from './authLink';
const links = {
errorLink,
httpLink,
authLink,
};
export default links;

View file

@ -1,21 +1,15 @@
import { useEffect, useState, useCallback } from 'react';
import { ApolloClient } from '@apollo/client';
import { createApolloClient } from '../core/apollo/client';
interface IReturnProps {
client?: ApolloClient<unknown>;
isLoadingComplete?: boolean;
}
export default function useCachedResources(): IReturnProps {
const [isLoadingComplete, setLoadingComplete] = useState(false);
const [client, setClient] = useState<ApolloClient<unknown>>();
const loadResourcesAndDataAsync = useCallback(() => {
try {
const restoredClient = createApolloClient();
setClient(restoredClient);
// Load any resources or data that we need prior to rendering the app
} catch (error) {
// We might want to provide this error information to an error reporting service
console.error(error);
@ -27,10 +21,8 @@ export default function useCachedResources(): IReturnProps {
}, [loadResourcesAndDataAsync]);
useEffect(() => {
if (client) {
setLoadingComplete(true);
}
}, [client]);
setLoadingComplete(true);
}, []);
return { client, isLoadingComplete };
return { isLoadingComplete };
}

View file

@ -1,6 +1,5 @@
import React, { useEffect } from 'react';
import type { AppProps } from 'next/app';
import { ApolloProvider } from '@apollo/client';
import Head from 'next/head';
import useCachedResources from '../client/hooks/useCachedRessources';
import '../client/styles/global.css';
@ -17,7 +16,7 @@ function MyApp({ Component, pageProps }: AppProps) {
const { setDarkMode } = useUIStore();
const { setStatus, setVersion } = useSystemStore();
trpc.system.status.useQuery(undefined, { refetchInterval: 1000, networkMode: 'online', onSuccess: (d) => setStatus(d.status || SystemStatus.RUNNING) });
trpc.system.status.useQuery(undefined, { networkMode: 'online', onSuccess: (d) => setStatus(d.status || SystemStatus.RUNNING) });
const version = trpc.system.getVersion.useQuery(undefined, { networkMode: 'online' });
useEffect(() => {
@ -40,25 +39,23 @@ function MyApp({ Component, pageProps }: AppProps) {
themeCheck();
}, [setDarkMode]);
const { client, isLoadingComplete } = useCachedResources();
if (!client || !isLoadingComplete) {
const { isLoadingComplete } = useCachedResources();
if (!isLoadingComplete) {
return <StatusScreen title="" subtitle="" />;
}
return (
<main className="h-100">
<ApolloProvider client={client}>
<Head>
<title>Tipi</title>
</Head>
<ToastProvider>
<StatusProvider>
<AuthProvider>
<Component {...pageProps} />
</AuthProvider>
</StatusProvider>
</ToastProvider>
</ApolloProvider>
<Head>
<title>Tipi</title>
</Head>
<ToastProvider>
<StatusProvider>
<AuthProvider>
<Component {...pageProps} />
</AuthProvider>
</StatusProvider>
</ToastProvider>
</main>
);
}

View file

@ -1,15 +1,12 @@
import 'reflect-metadata';
import express from 'express';
import { ApolloServerPluginLandingPageGraphQLPlayground as Playground } from 'apollo-server-core';
import { createServer } from 'http';
import { ZodError } from 'zod';
import cors, { CorsOptions } from 'cors';
import { ApolloLogs } from './config/logger/apollo.logger';
import logger from './config/logger/logger';
import getSessionMiddleware from './core/middlewares/sessionMiddleware';
import { __prod__ } from './config/constants/constants';
import startJobs from './core/jobs/jobs';
import { applyJsonConfig, getConfig } from './core/config/TipiConfig';
import { getConfig } from './core/config/TipiConfig';
import { eventDispatcher } from './core/config/EventDispatcher';
const corsOptions: CorsOptions = {

File diff suppressed because it is too large Load diff