bde148f286
* wip * some extra fixes * stuff kinda works? * need to figure out mocks * need to figure out mocks * fix db listener * gqlgen fix * minor gqlgen watch adjustment * lint fixes * delete old codegen file * converting migrations to ESM * getModuleDIrectory * vitest sort of works * added back ts-vitest * resolve gql double load * fixing test timeout configs * TSC lint fix * fix automate tests * moar debugging * debugging * more debugging * codegen update * server works * yargs migrated * chore(server): getting rid of global mocks for Server ESM (#5046) * got rid of email mock * got rid of comment mocks * got rid of multi region mocks * got rid of stripe mock * admin override mock updated * removed final mock * fixing import.meta.resolve calls * another import.meta.resolve fix * added requested test * nyc ESM fix * removed unneeded deps + linting * yarn lock forgot to commit * tryna fix flakyness * email capture util fix * sendEmail fix * fix TSX check * sender transporter fix + CR comments * merge main fix * test fixx * circleci fix * gqlgen bigint fix * error formatter fix * more error formatting improvements * esmloader added to Dockerfile * more dockerfile fixes * bg jobs fix
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
import { AuthContext } from '@/modules/shared/authz'
|
|
import DataLoader from 'dataloader'
|
|
import { ApolloServerErrorCode } from '@apollo/server/errors'
|
|
import { GraphQLError } from 'graphql'
|
|
import {
|
|
BadRequestError,
|
|
ForbiddenError,
|
|
InvalidArgumentError,
|
|
NotFoundError,
|
|
UnauthorizedError
|
|
} from '@/modules/shared/errors'
|
|
import { Optional } from '@speckle/shared'
|
|
import { Knex } from 'knex'
|
|
|
|
/**
|
|
* All dataloaders must at the very least follow this type
|
|
*/
|
|
export type ModularizedDataLoadersConstraint = {
|
|
[group: string]: Optional<{
|
|
[loader: string]: DataLoader<any, any> | { clearAll: () => unknown }
|
|
}>
|
|
}
|
|
|
|
export type RequestDataLoadersBuilder<T extends ModularizedDataLoadersConstraint> =
|
|
(params: {
|
|
ctx: AuthContext
|
|
createLoader: <K, V, C = K>(
|
|
batchLoadFn: DataLoader.BatchLoadFn<K, V>,
|
|
options?: DataLoader.Options<K, V, C>
|
|
) => DataLoader<K, V, C>
|
|
deps: {
|
|
db: Knex
|
|
}
|
|
}) => T
|
|
|
|
export const defineRequestDataloaders = <T extends ModularizedDataLoadersConstraint>(
|
|
builder: RequestDataLoadersBuilder<T>
|
|
): RequestDataLoadersBuilder<T> => {
|
|
return builder
|
|
}
|
|
|
|
export const simpleTupleCacheKey = (key: [string, string]) => `${key[0]}:${key[1]}`
|
|
|
|
/**
|
|
* Is a lower significance error, caused by user error (and thus - not a bug in our code)
|
|
*/
|
|
export const isUserGraphqlError = (error: GraphQLError): boolean => {
|
|
const userCodes = [
|
|
ForbiddenError.code,
|
|
UnauthorizedError.code,
|
|
BadRequestError.code,
|
|
NotFoundError.code,
|
|
InvalidArgumentError.code,
|
|
ApolloServerErrorCode.BAD_REQUEST,
|
|
ApolloServerErrorCode.BAD_USER_INPUT,
|
|
ApolloServerErrorCode.GRAPHQL_PARSE_FAILED,
|
|
ApolloServerErrorCode.GRAPHQL_VALIDATION_FAILED,
|
|
ApolloServerErrorCode.OPERATION_RESOLUTION_FAILURE,
|
|
ApolloServerErrorCode.PERSISTED_QUERY_NOT_FOUND,
|
|
ApolloServerErrorCode.PERSISTED_QUERY_NOT_SUPPORTED
|
|
]
|
|
const code = error.extensions?.code as string
|
|
return userCodes.includes(code)
|
|
}
|
|
|
|
export const isGraphQLError = (error: unknown): error is GraphQLError => {
|
|
return error instanceof GraphQLError
|
|
}
|