Files
speckle-server/packages/server/modules/acc/graph/dataloaders/acc.ts
T
Oğuzhan Koral 05e00d2c5c feat(acc): revamp (#5501)
* chore(acc): put permission gql in correct place

* feat(acc): swap to new rvt import

* fix(acc): add oda secrets

* feat(acc): auth cookies

* feat(acc): introduce integrations as workspace setting

* feat(acc): create sync item from models

* fix(acc): bump

* fix(acc): naming lost in merge

* feat(acc): no acc tab - table under settings

* chore(acc): new sync but will disapper

* feat(acc): see statuses over model list

* chore(acc): fix return type

* chore(acc): type saga

* chore(acc): status badge

* chore(acc): refactor acc gql (#5556)

* checkpoint

* fix(acc): refactor gql items

* feat(acc): double button

* chore(acc): gqlgen

* fix(acc): model ids are not project ids

* chore(acc): bump function version

* chore(acc): split up clients

* feat(acc): more-optimised gql folder fetching schema

* feat(acc): acc folder contents gql impl

* feat(acc): apollo cache optimisations

* chore(acc): gqlgen

* fix(acc): return something for

* fix(acc): handle null values correctly

* chore(acc): specify prod functions

---------

Co-authored-by: Chuck Driesler <chuck@speckle.systems>
2025-10-03 13:54:17 +01:00

95 lines
3.1 KiB
TypeScript

import { getFolderContents } from '@/modules/acc/clients/autodesk/acc'
import type {
AccSyncItem,
DataManagementFolderContentsFolder,
DataManagementFolderContentsItem
} from '@/modules/acc/domain/acc/types'
import {
getAccSyncItemsByIdFactory,
getAccSyncItemsByModelIdFactory
} from '@/modules/acc/repositories/accSyncItems'
import { defineRequestDataloaders } from '@/modules/shared/helpers/graphqlHelper'
import type { Nullable } from '@speckle/shared'
import { keyBy } from 'lodash-es'
declare module '@/modules/core/loaders' {
interface ModularizedDataLoaders
extends Partial<ReturnType<typeof dataLoadersDefinition>> {}
}
const dataLoadersDefinition = defineRequestDataloaders(
({ createLoader, deps: { db } }) => {
const getAccSyncItemsById = getAccSyncItemsByIdFactory({ db })
const getAccSyncItemsByModelId = getAccSyncItemsByModelIdFactory({ db })
return {
acc: {
getFolderChildren: createLoader<
{ projectId: string; folderId: string; token: string },
DataManagementFolderContentsFolder[],
string
>(
async (folderIds) => {
return await Promise.all(
folderIds.map(async ({ projectId, folderId, token }) => {
const items = await getFolderContents(
{ projectId, folderId, type: 'folders' },
{ token }
)
return items.filter(
(item): item is DataManagementFolderContentsFolder =>
item.type === 'folders'
)
})
)
},
{
cacheKeyFn: (args) => `${args.projectId}-${args.projectId}`
}
),
getFolderContents: createLoader<
{ projectId: string; folderId: string; token: string },
DataManagementFolderContentsItem[],
string
>(
async (folderIds) => {
return await Promise.all(
folderIds.map(async ({ projectId, folderId, token }) => {
const items = await getFolderContents(
{ projectId, folderId, type: 'items' },
{ token }
)
return items.filter(
(item): item is DataManagementFolderContentsItem =>
item.type === 'items'
)
})
)
},
{
cacheKeyFn: (args) => `${args.projectId}-${args.projectId}`
}
),
getAccSyncItem: createLoader<string, Nullable<AccSyncItem>>(async (ids) => {
const results = keyBy(
await getAccSyncItemsById({ ids: ids.slice() }),
(i) => i.id
)
return ids.map((i) => results[i] || null)
}),
getAccSyncItemByModelId: createLoader<string, Nullable<AccSyncItem>>(
async (ids) => {
const results = keyBy(
await getAccSyncItemsByModelId({ ids: ids.slice() }),
(i) => i.modelId
)
return ids.map((i) => results[i] || null)
}
)
}
}
}
)
export default dataLoadersDefinition