Skip to content

Commit

Permalink
fix: nuxt public feature flag env var (#2270)
Browse files Browse the repository at this point in the history
* fix: nuxt public feature flag env var

* fix: only load graphql resolvers for modules, that are enabled

* fix: disable automation subs on the frontend if the module is not enabled

* fix: enable the stats module, its was missing
  • Loading branch information
gjedlicska authored May 18, 2024
1 parent 3f9e274 commit 0c502d0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ export const useProjectTriggeredAutomationsStatusUpdateTracking = (params: {
() => `useProjectTriggeredAutomationsStatusUpdateTracking-${unref(projectId)}`
)
)
const isEnabled = computed(() => !!(hasLock.value || handler))
// const isEnabled = computed(() => !!(hasLock.value || handler))

const isAutomateModuleEnabled = useIsAutomateModuleEnabled()
const isEnabled = computed(
() => isAutomateModuleEnabled.value && !!(hasLock.value || handler)
)

const { onResult } = useSubscription(
onProjectTriggeredAutomationsStatusUpdatedSubscription,
Expand Down Expand Up @@ -276,7 +281,12 @@ export const useProjectAutomationsUpdateTracking = (params: {
const { hasLock } = useLock(
computed(() => `useProjectAutomationsUpdateTracking-${unref(projectId)}`)
)
const isEnabled = computed(() => !!(hasLock.value || handler))
// const isEnabled = computed(() => !!(hasLock.value || handler))

const isAutomateModuleEnabled = useIsAutomateModuleEnabled()
const isEnabled = computed(
() => isAutomateModuleEnabled.value && !!(hasLock.value || handler)
)

const { onResult } = useSubscription(
onProjectAutomationsUpdatedSubscription,
Expand Down
57 changes: 36 additions & 21 deletions packages/server/modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { scalarResolvers } = require('./core/graph/scalars')
const { makeExecutableSchema } = require('@graphql-tools/schema')
const { moduleLogger } = require('@/logging/logging')
const { addMocksToSchema } = require('@graphql-tools/mock')
const { Environment } = require('@speckle/shared')

/**
* Cached speckle module requires
Expand Down Expand Up @@ -40,31 +41,39 @@ function autoloadFromDirectory(dirPath) {
return results
}

const getEnabledModuleNames = () => {
const { FF_AUTOMATE_MODULE_ENABLED } = Environment.getFeatureFlags()
const moduleNames = [
'accessrequests',
'activitystream',
'apiexplorer',
'auth',
'betaAutomations',
'blobstorage',
'comments',
'core',
'cross-server-sync',
'emails',
'fileuploads',
'notifications',
'previews',
'pwdreset',
'serverinvites',
'stats',
'webhooks'
]

if (FF_AUTOMATE_MODULE_ENABLED) moduleNames.push('automate')
return moduleNames
}

async function getSpeckleModules() {
if (loadedModules.length) return loadedModules

const moduleDirs = [
'./core',
'./auth',
'./apiexplorer',
'./emails',
'./pwdreset',
'./serverinvites',
'./previews',
'./fileuploads',
'./comments',
'./blobstorage',
'./notifications',
'./activitystream',
'./accessrequests',
'./webhooks',
'./cross-server-sync',
'./betaAutomations',
'./automate'
]
const moduleNames = getEnabledModuleNames()

for (const dir of moduleDirs) {
loadedModules.push(require(dir))
for (const dir of moduleNames) {
loadedModules.push(require(`./${dir}`))
}

return loadedModules
Expand Down Expand Up @@ -107,9 +116,13 @@ const graphComponents = () => {
let resolverObjs = []
let directiveBuilders = {}

const enabledModules = getEnabledModuleNames()

// load typedefs from /assets
const assetModuleDirs = fs.readdirSync(`${packageRoot}/assets`)
assetModuleDirs.forEach((dir) => {
// if module is not in the enabled modules list, skip loading the gql schema
// if (!enabledModules.includes(dir)) return
const typeDefDirPath = path.join(`${packageRoot}/assets`, dir, 'typedefs')
if (fs.existsSync(typeDefDirPath)) {
const moduleSchemas = fs.readdirSync(typeDefDirPath)
Expand All @@ -122,6 +135,8 @@ const graphComponents = () => {
// load code modules from /modules
const codeModuleDirs = fs.readdirSync(`${appRoot}/modules`)
codeModuleDirs.forEach((file) => {
// if module is not in the enabled modules list, skip loading the gql resolvers
if (!enabledModules.includes(file)) return
const fullPath = path.join(`${appRoot}/modules`, file)

// first pass load of resolvers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ spec:
- name: NUXT_PUBLIC_DATADOG_ENV
value: {{ .Values.analytics.datadog_env | quote }}
{{- end }}
- name: FF_AUTOMATE_MODULE_ENABLED
- name: NUXT_PUBLIC_FF_AUTOMATE_MODULE_ENABLED
value: {{ .Values.featureFlags.automateModuleEnabled | quote }}
{{- if .Values.analytics.survicate_workspace_key }}
- name: NUXT_PUBLIC_SURVICATE_WORKSPACE_KEY
Expand Down

0 comments on commit 0c502d0

Please sign in to comment.