Files
speckle-server/packages/frontend-2/plugins/006-dataPreload.ts
T
Kristaps Fabians Geikins dd7409dcb2 feat(fe2): implementing various RUM tools for trialing (#2066)
* basic raygun setup

* testing seq logging

* minor fixes

* more accurate user identification

* logrocket adjustments

* speedcurve seems to work?

* added debugbear

* minor cleanup

* chore(helm chart): adds new web app analytics ids/keys to fe2 env vars
- assumes none are secrets

* Quote all secrets to prevent interpretation as digits

---------

Co-authored-by: Iain Sproat <68657+iainsproat@users.noreply.github.com>
2024-02-22 10:51:13 +02:00

49 lines
1.3 KiB
TypeScript

import type { Optional } from '@speckle/shared'
import { activeUserQuery } from '~/lib/auth/composables/activeUser'
import { usePreloadApolloQueries } from '~/lib/common/composables/graphql'
import { mainServerInfoDataQuery } from '~/lib/core/composables/server'
import { projectAccessCheckQuery } from '~/lib/projects/graphql/queries'
/**
* Prefetches data for specific routes to avoid the problem of serial API requests
* (e.g. in the case of multiple middlewares)
*/
export default defineNuxtPlugin(async (ctx) => {
const logger = useLogger()
const route = ctx._route
const preload = usePreloadApolloQueries()
if (!route) {
logger.info('No route obj found, skipping data preload...')
return
}
const path = route.path
const idParam = route.params.id as Optional<string>
const promises: Promise<unknown>[] = []
// Standard/global
promises.push(
preload({
queries: [{ query: activeUserQuery }, { query: mainServerInfoDataQuery }]
})
)
// Preload project data
if (idParam && path.startsWith('/projects/')) {
promises.push(
preload({
queries: [
{
query: projectAccessCheckQuery,
variables: { id: idParam },
context: { skipLoggingErrors: true }
}
]
})
)
}
await Promise.all(promises)
})