* merge squashed
- A couple of CJS modules into ESM (config mostly)
- Vite complains about node.js modules: fixed `useIsMatchingLocation.ts`
> or use rollupOptions in vite.config.ts
> ref: f0e4f59d97/vite.config.js (L6)
- Adjust Storybook to work with Vite: use @storybook/test
- Use SWC for jest tranformations
- Remove unused deps:
- ts-jest: replaced with @swc/jest, typecheck by `tsc`
- babel plugins
- @svgr/plugin-jsx: not used
- @testing-library/user-event: handled by @storybook/test
- @typescript-eslint/utils: was not plugged in
- tsup, esbuild-plugin-svgr: will look into that later
- Install Vite required deps, and remove craco/webpack deps
- Adjust SVG to work with Vite as components
- Fixed `Step.tsx`: I dont know if one should be swaped for the other,
but there should be no slash
- Initial formating and linting:
- removed empty object params
- sorting imports, etc..
* prettier: fix pattern
* coverage: sb coverage report isnt working
* Add missing pieces
* `yarn lint --fix`
* fix: scripts permissions
* tsc: cut errors in half
* fix: remove `react-app-env.d.ts`
* tsc: all fixed, except `react-data-grid` types issue
* eslint: ignore env-config.js
* eslint: Align ci with config
* msw: bypass testing warnings
ref: https://stackoverflow.com/questions/68024935/msw-logging-warnings-for-unhandled-supertest-requests
* rebase: and fix things
* Adjust to current `graphql-codegen` no ESM support
* Remove vite plugin and use built-in methods
* rebase: and some fixes
* quick fix + `corepack use yarn@1.22.19`
* Fix build errors
---------
Co-authored-by: Charles Bochet <charles@twenty.com>
106 lines
2.7 KiB
TypeScript
106 lines
2.7 KiB
TypeScript
import { ApolloLink, gql, Operation } from '@apollo/client';
|
|
|
|
import { logDebug } from '~/utils/logDebug';
|
|
import { logError } from '~/utils/logError';
|
|
|
|
import formatTitle from './format-title';
|
|
|
|
const getGroup = (collapsed: boolean) =>
|
|
collapsed
|
|
? console.groupCollapsed.bind(console)
|
|
: console.group.bind(console);
|
|
|
|
const parseQuery = (queryString: string) => {
|
|
const queryObj = gql`
|
|
${queryString}
|
|
`;
|
|
|
|
const { name } = queryObj.definitions[0] as any;
|
|
return [name ? name.value : 'Generic', queryString.trim()];
|
|
};
|
|
|
|
export const loggerLink = (getSchemaName: (operation: Operation) => string) =>
|
|
new ApolloLink((operation, forward) => {
|
|
const schemaName = getSchemaName(operation);
|
|
operation.setContext({ start: Date.now() });
|
|
|
|
const { variables } = operation;
|
|
|
|
const operationType = (operation.query.definitions[0] as any).operation;
|
|
const headers = operation.getContext().headers;
|
|
|
|
const [queryName, query] = parseQuery(operation.query.loc!.source.body);
|
|
|
|
if (operationType === 'subscription') {
|
|
const date = new Date().toLocaleTimeString();
|
|
|
|
const titleArgs = formatTitle(operationType, schemaName, queryName, date);
|
|
|
|
console.groupCollapsed(...titleArgs);
|
|
|
|
if (variables && Object.keys(variables).length !== 0) {
|
|
logDebug('VARIABLES', variables);
|
|
}
|
|
|
|
logDebug('QUERY', query);
|
|
|
|
console.groupEnd();
|
|
|
|
return forward(operation);
|
|
}
|
|
|
|
return forward(operation).map((result) => {
|
|
const time = Date.now() - operation.getContext().start;
|
|
const errors = result.errors ?? result.data?.[queryName]?.errors;
|
|
const hasError = Boolean(errors);
|
|
|
|
try {
|
|
const titleArgs = formatTitle(
|
|
operationType,
|
|
schemaName,
|
|
queryName,
|
|
time,
|
|
);
|
|
|
|
getGroup(!hasError)(...titleArgs);
|
|
|
|
if (errors) {
|
|
errors.forEach((err: any) => {
|
|
logDebug(
|
|
`%c${err.message}`,
|
|
// eslint-disable-next-line twenty/no-hardcoded-colors
|
|
'color: #F51818; font-weight: lighter',
|
|
);
|
|
});
|
|
}
|
|
|
|
logDebug('HEADERS: ', headers);
|
|
|
|
if (variables && Object.keys(variables).length !== 0) {
|
|
logDebug('VARIABLES', variables);
|
|
}
|
|
|
|
logDebug('QUERY', query);
|
|
|
|
if (result.data) {
|
|
logDebug('RESULT', result.data);
|
|
}
|
|
if (errors) {
|
|
logDebug('ERRORS', errors);
|
|
}
|
|
|
|
console.groupEnd();
|
|
} catch {
|
|
// this may happen if console group is not supported
|
|
logDebug(
|
|
`${operationType} ${schemaName}::${queryName} (in ${time} ms)`,
|
|
);
|
|
if (errors) {
|
|
logError(errors);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
});
|
|
});
|