-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(server): multi region module base w/ a test (mocked) mutation #3406
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
type ServerRegionItem { | ||
id: String! | ||
key: String! | ||
name: String! | ||
description: String! | ||
} | ||
|
||
input CreateServerRegionInput { | ||
key: String! | ||
name: String! | ||
description: String! | ||
} | ||
|
||
type ServerRegionMutations { | ||
create(input: CreateServerRegionInput!): ServerRegionItem! | ||
} | ||
|
||
type ServerInfoMutations { | ||
multiRegion: ServerRegionMutations! | ||
} | ||
|
||
extend type Mutation { | ||
serverInfoMutations: ServerInfoMutations! | ||
@hasServerRole(role: SERVER_ADMIN) | ||
@hasScope(scope: "server:setup") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
|
||
import fs from 'fs' | ||
import path from 'path' | ||
import { appRoot, packageRoot } from '@/bootstrap' | ||
|
@@ -22,6 +22,7 @@ import { | |
} from '@/modules/core/graph/helpers/directiveHelper' | ||
import { AppMocksConfig } from '@/modules/mocks' | ||
import { SpeckleModuleMocksConfig } from '@/modules/shared/helpers/mocks' | ||
import { LogicError } from '@/modules/shared/errors' | ||
|
||
/** | ||
* Cached speckle module requires | ||
|
@@ -77,7 +78,8 @@ const getEnabledModuleNames = () => { | |
'serverinvites', | ||
'stats', | ||
'webhooks', | ||
'workspacesCore' | ||
'workspacesCore', | ||
'multiregion' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned before, the module itself is enabled always (for simplicity), but then functionality checks inside of it can use the feature flag |
||
] | ||
|
||
if (FF_AUTOMATE_MODULE_ENABLED) moduleNames.push('automate') | ||
|
@@ -93,7 +95,13 @@ async function getSpeckleModules() { | |
const moduleNames = getEnabledModuleNames() | ||
|
||
for (const dir of moduleNames) { | ||
loadedModules.push(require(`./${dir}`)) | ||
const moduleIndex = await import(`./${dir}/index`) | ||
const moduleDefinition = 'init' in moduleIndex ? moduleIndex : moduleIndex.default | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finally supporting |
||
if (!('init' in moduleDefinition)) { | ||
throw new LogicError(`Module ${dir} does not have an init function`) | ||
} | ||
|
||
loadedModules.push(moduleDefinition) | ||
} | ||
|
||
return loadedModules | ||
|
@@ -185,7 +193,10 @@ const graphComponents = (): Pick<ApolloServerOptions<any>, 'resolvers'> & { | |
// first pass load of resolvers | ||
const resolversPath = path.join(fullPath, 'graph', 'resolvers') | ||
if (fs.existsSync(resolversPath)) { | ||
resolverObjs = [...resolverObjs, ...values(autoloadFromDirectory(resolversPath))] | ||
const newResolverObjs = values(autoloadFromDirectory(resolversPath)).map((o) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly supporting |
||
'default' in o ? o.default : o | ||
) | ||
resolverObjs = [...resolverObjs, ...newResolverObjs] | ||
} | ||
|
||
// load directives | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { RegionServerConfig } from '@/modules/multiregion/domain/types' | ||
|
||
export type GetAvailableRegionConfigs = () => Promise<{ | ||
[key: string]: RegionServerConfig | ||
}> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export type RegionServerConfig = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated based on Iain's proposed schema |
||
postgres: { | ||
/** | ||
* Full Postgres connection URI (e.g. "postgres://user:password@host:port/dbname") | ||
*/ | ||
connectionUri: string | ||
/** | ||
* SSL cert, if any | ||
*/ | ||
publicTlsCertificate?: string | ||
iainsproat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { BaseError } from '@/modules/shared/errors' | ||
|
||
export class MultiRegionSupportDisabledError extends BaseError { | ||
static code = 'MULTI_REGION_SUPPORT_DISABLED' | ||
static defaultMessage = 'Multi region support is disabled' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { SpeckleModuleMocksConfig } from '@/modules/shared/helpers/mocks' | ||
import { faker } from '@faker-js/faker' | ||
|
||
export default { | ||
mocks: { | ||
ServerRegionItem: () => { | ||
const key = faker.string.uuid() | ||
return { | ||
id: key, | ||
key, | ||
name: faker.address.country(), | ||
description: faker.lorem.sentence() | ||
} | ||
} | ||
} | ||
} as SpeckleModuleMocksConfig |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Resolvers } from '@/modules/core/graph/generated/graphql' | ||
|
||
// TODO: Real implementation? Need to discuss questions regarding data model & region config first | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I got my answers earlier today, so I should be unblocked for this |
||
|
||
export default {} as Resolvers |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { getFeatureFlags } from '@/modules/shared/helpers/envHelper' | ||
|
||
export const isMultiRegionEnabled = () => { | ||
const { FF_WORKSPACES_MODULE_ENABLED, FF_WORKSPACES_MULTI_REGION_ENABLED } = | ||
getFeatureFlags() | ||
return !!(FF_WORKSPACES_MODULE_ENABLED && FF_WORKSPACES_MULTI_REGION_ENABLED) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GQL type no longer exists