refactor: remove whole graphql implementation

This commit is contained in:
Ali BARIN
2024-09-26 13:29:46 +00:00
parent a043a044ca
commit 0b7591edce
28 changed files with 28 additions and 1181 deletions

View File

@@ -4,7 +4,6 @@
"license": "See LICENSE file",
"description": "The open source Zapier alternative. Build workflow automation without spending time and money.",
"dependencies": {
"@apollo/client": "^3.6.9",
"@casl/ability": "^6.5.0",
"@casl/react": "^3.1.0",
"@dagrejs/dagre": "^1.1.2",
@@ -21,7 +20,6 @@
"@testing-library/user-event": "^12.1.10",
"clipboard-copy": "^4.0.1",
"compare-versions": "^4.1.3",
"graphql": "^15.6.0",
"lodash": "^4.17.21",
"luxon": "^2.3.1",
"mui-color-input": "^2.0.0",

View File

@@ -6,11 +6,11 @@ import Menu from '@mui/material/Menu';
import { Link } from 'react-router-dom';
import Can from 'components/Can';
import apolloClient from 'graphql/client';
import * as URLS from 'config/urls';
import useAuthentication from 'hooks/useAuthentication';
import useFormatMessage from 'hooks/useFormatMessage';
import useRevokeAccessToken from 'hooks/useRevokeAccessToken';
function AccountDropdownMenu(props) {
const formatMessage = useFormatMessage();
const authentication = useAuthentication();
@@ -23,7 +23,6 @@ function AccountDropdownMenu(props) {
await revokeAccessTokenMutation.mutateAsync();
authentication.removeToken();
await apolloClient.clearStore();
onClose();
navigate(URLS.LOGIN);
};

View File

@@ -7,7 +7,6 @@ import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
import CircularProgress from '@mui/material/CircularProgress';
import { ApolloError } from '@apollo/client';
import { FieldPropType } from 'propTypes/propTypes';
import useFormatMessage from 'hooks/useFormatMessage';
@@ -89,7 +88,9 @@ function AdminApplicationAuthClientDialog(props) {
}
AdminApplicationAuthClientDialog.propTypes = {
error: PropTypes.instanceOf(ApolloError),
error: PropTypes.shape({
message: PropTypes.string,
}),
onClose: PropTypes.func.isRequired,
title: PropTypes.string.isRequired,
loading: PropTypes.bool.isRequired,

View File

@@ -1,34 +0,0 @@
import { ApolloProvider as BaseApolloProvider } from '@apollo/client';
import * as React from 'react';
import { mutateAndGetClient } from 'graphql/client';
import useAuthentication from 'hooks/useAuthentication';
import useEnqueueSnackbar from 'hooks/useEnqueueSnackbar';
const ApolloProvider = (props) => {
const enqueueSnackbar = useEnqueueSnackbar();
const authentication = useAuthentication();
const onError = React.useCallback(
(message) => {
enqueueSnackbar(message, {
variant: 'error',
SnackbarProps: {
'data-test': 'snackbar-error',
},
});
},
[enqueueSnackbar],
);
const client = React.useMemo(() => {
return mutateAndGetClient({
onError,
token: authentication.token,
});
}, [onError, authentication]);
return <BaseApolloProvider client={client} {...props} />;
};
export default ApolloProvider;

View File

@@ -4,7 +4,6 @@ import { useNavigate } from 'react-router-dom';
import * as URLS from 'config/urls';
import ConfirmationDialog from 'components/ConfirmationDialog';
import apolloClient from 'graphql/client';
import useAuthentication from 'hooks/useAuthentication';
import useFormatMessage from 'hooks/useFormatMessage';
import useCurrentUser from 'hooks/useCurrentUser';
@@ -27,8 +26,6 @@ function DeleteAccountDialog(props) {
authentication.removeToken();
await apolloClient.clearStore();
navigate(URLS.LOGIN);
}, [deleteCurrentUser, authentication, navigate]);

View File

@@ -1,5 +1,4 @@
import { useEffect, useCallback, createContext, useRef, useState } from 'react';
import { useMutation } from '@apollo/client';
import { useQueryClient } from '@tanstack/react-query';
import { FlowPropType } from 'propTypes/propTypes';
import ReactFlow, { useNodesState, useEdgesState } from 'reactflow';

View File

@@ -1,6 +1,5 @@
import * as React from 'react';
import { useNavigate } from 'react-router-dom';
import { useMutation } from '@apollo/client';
import Paper from '@mui/material/Paper';
import Typography from '@mui/material/Typography';
import LoadingButton from '@mui/lab/LoadingButton';

View File

@@ -16,7 +16,6 @@ const computeUrl = (url, backendUrl) => {
const config = {
baseUrl: process.env.REACT_APP_BASE_URL,
graphqlUrl: computeUrl('/graphql', backendUrl),
restApiUrl: computeUrl('/api', backendUrl),
supportEmailAddress: 'support@automatisch.io',
};

View File

@@ -1,13 +0,0 @@
import { InMemoryCache } from '@apollo/client';
const cache = new InMemoryCache({
typePolicies: {
App: {
keyFields: ['key'],
},
Mutation: {
mutationType: true,
fields: {},
},
},
});
export default cache;

View File

@@ -1,31 +0,0 @@
import { ApolloClient } from '@apollo/client';
import cache from './cache';
import createLink from './link';
import appConfig from 'config/app';
const client = new ApolloClient({
cache,
link: createLink({ uri: appConfig.graphqlUrl }),
defaultOptions: {
watchQuery: {
fetchPolicy: 'cache-and-network',
},
},
});
export function mutateAndGetClient(options) {
const { onError, token } = options;
const link = createLink({
uri: appConfig.graphqlUrl,
token,
onError,
});
client.setLink(link);
return client;
}
export default client;

View File

@@ -1,46 +0,0 @@
import { HttpLink, from } from '@apollo/client';
import { onError } from '@apollo/client/link/error';
import { setItem } from 'helpers/storage';
import * as URLS from 'config/urls';
const createHttpLink = (options) => {
const { uri, token } = options;
const headers = {
authorization: token,
};
return new HttpLink({ uri, headers });
};
const NOT_AUTHORISED = 'Not Authorised!';
const createErrorLink = (callback) =>
onError(({ graphQLErrors, networkError, operation }) => {
const context = operation.getContext();
const autoSnackbar = context.autoSnackbar ?? true;
if (graphQLErrors)
graphQLErrors.forEach(({ message, locations, path }) => {
if (autoSnackbar) {
callback?.(message);
}
console.error(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
);
if (message === NOT_AUTHORISED) {
setItem('token', '');
if (window.location.pathname !== URLS.LOGIN) {
window.location.href = URLS.LOGIN;
}
}
});
if (networkError) {
if (autoSnackbar) {
callback?.(networkError.toString());
}
console.error(`[Network error]: ${networkError}`);
}
});
const noop = () => {};
const createLink = (options) => {
const { uri, onError = noop, token } = options;
const httpOptions = { uri, token };
return from([createErrorLink(onError), createHttpLink(httpOptions)]);
};
export default createLink;

View File

@@ -1,32 +0,0 @@
const makeEmptyData = () => {
return {
edges: [],
pageInfo: {
currentPage: 1,
totalPages: 1,
},
};
};
function offsetLimitPagination(keyArgs = false) {
return {
keyArgs,
merge(existing, incoming, { args }) {
if (!existing) {
existing = makeEmptyData();
}
if (!incoming || incoming === null) return existing;
const existingEdges = existing?.edges || [];
const incomingEdges = incoming.edges || [];
if (args) {
const newEdges = [...existingEdges, ...incomingEdges];
return {
pageInfo: incoming.pageInfo,
edges: newEdges,
};
} else {
return existing;
}
},
};
}
export default offsetLimitPagination;

View File

@@ -1,69 +0,0 @@
import { gql } from '@apollo/client';
export const GET_DYNAMIC_FIELDS = gql`
query GetDynamicFields(
$stepId: String!
$key: String!
$parameters: JSONObject
) {
getDynamicFields(stepId: $stepId, key: $key, parameters: $parameters) {
label
key
type
required
description
variables
dependsOn
value
options {
label
value
}
source {
type
name
arguments {
name
value
}
}
additionalFields {
type
name
arguments {
name
value
}
}
fields {
label
key
type
required
description
variables
value
dependsOn
options {
label
value
}
source {
type
name
arguments {
name
value
}
}
additionalFields {
type
name
arguments {
name
value
}
}
}
}
}
`;

View File

@@ -3,7 +3,6 @@ import { Settings } from 'luxon';
import ThemeProvider from 'components/ThemeProvider';
import IntlProvider from 'components/IntlProvider';
import ApolloProvider from 'components/ApolloProvider';
import SnackbarProvider from 'components/SnackbarProvider';
import MetadataProvider from 'components/MetadataProvider';
import { AuthenticationProvider } from 'contexts/Authentication';
@@ -23,13 +22,11 @@ root.render(
<SnackbarProvider>
<AuthenticationProvider>
<QueryClientProvider>
<ApolloProvider>
<IntlProvider>
<ThemeProvider>
<MetadataProvider>{routes}</MetadataProvider>
</ThemeProvider>
</IntlProvider>
</ApolloProvider>
<IntlProvider>
<ThemeProvider>
<MetadataProvider>{routes}</MetadataProvider>
</ThemeProvider>
</IntlProvider>
</QueryClientProvider>
</AuthenticationProvider>
</SnackbarProvider>