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
91 lines
2.9 KiB
TypeScript
91 lines
2.9 KiB
TypeScript
import { getFeatureFlags } from '@/modules/shared/helpers/envHelper'
|
|
import { defineRequestDataloaders } from '@/modules/shared/helpers/graphqlHelper'
|
|
import {
|
|
getWorkspaceDomainsFactory,
|
|
getWorkspacesFactory,
|
|
getWorkspacesProjectsCountsFactory,
|
|
getWorkspacesRolesForUsersFactory
|
|
} from '@/modules/workspaces/repositories/workspaces'
|
|
import {
|
|
WorkspaceAcl,
|
|
WorkspaceDomain,
|
|
WorkspaceWithOptionalRole
|
|
} from '@/modules/workspacesCore/domain/types'
|
|
import { keyBy } from 'lodash-es'
|
|
|
|
const { FF_WORKSPACES_MODULE_ENABLED } = getFeatureFlags()
|
|
|
|
declare module '@/modules/core/loaders' {
|
|
interface ModularizedDataLoaders
|
|
extends Partial<ReturnType<typeof dataLoadersDefinition>> {}
|
|
}
|
|
|
|
const dataLoadersDefinition = defineRequestDataloaders(
|
|
({ ctx, createLoader, deps: { db } }) => {
|
|
const getWorkspaces = getWorkspacesFactory({ db })
|
|
const getWorkspaceDomains = getWorkspaceDomainsFactory({ db })
|
|
const getWorkspacesProjectsCounts = getWorkspacesProjectsCountsFactory({ db })
|
|
const getWorkspacesRolesForUsers = getWorkspacesRolesForUsersFactory({ db })
|
|
|
|
return {
|
|
workspaces: {
|
|
/**
|
|
* Get workspace, with the active user's role attached
|
|
*/
|
|
getWorkspace: createLoader<string, WorkspaceWithOptionalRole | null>(
|
|
async (ids) => {
|
|
const results = keyBy(
|
|
await getWorkspaces({ workspaceIds: ids.slice(), userId: ctx.userId }),
|
|
(w) => w.id
|
|
)
|
|
return ids.map((id) => results[id] || null)
|
|
}
|
|
),
|
|
/**
|
|
* Get workspace project count
|
|
*/
|
|
getProjectCount: createLoader<string, number | null>(async (ids) => {
|
|
const results = await getWorkspacesProjectsCounts({
|
|
workspaceIds: ids.slice()
|
|
})
|
|
return ids.map((id) => results[id])
|
|
}),
|
|
/**
|
|
* Get workspace role
|
|
*/
|
|
getWorkspaceRole: createLoader<
|
|
{ userId: string; workspaceId: string },
|
|
WorkspaceAcl | null,
|
|
string
|
|
>(
|
|
async (idPairs) => {
|
|
const results = await getWorkspacesRolesForUsers(idPairs.slice())
|
|
return idPairs.map(({ userId, workspaceId }) => {
|
|
return results[workspaceId]?.[userId] || null
|
|
})
|
|
},
|
|
{
|
|
cacheKeyFn: (args) => `${args.userId}-${args.workspaceId}`
|
|
}
|
|
)
|
|
},
|
|
workspaceDomains: {
|
|
/**
|
|
* Get workspace, with the active user's role attached
|
|
*/
|
|
getWorkspaceDomains: createLoader<string, WorkspaceDomain | null>(
|
|
async (ids) => {
|
|
const results = keyBy(
|
|
await getWorkspaceDomains({ workspaceIds: ids.slice() }),
|
|
(w) => w.id
|
|
)
|
|
return ids.map((id) => results[id] || null)
|
|
}
|
|
)
|
|
}
|
|
}
|
|
}
|
|
)
|
|
|
|
export default FF_WORKSPACES_MODULE_ENABLED ? dataLoadersDefinition : undefined
|