@contember/engine-http 1.3.4 → 1.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/common/Authorizator.d.ts +2 -1
- package/dist/src/common/Authorizator.d.ts.map +1 -1
- package/dist/src/common/Authorizator.js +3 -2
- package/dist/src/common/Authorizator.js.map +1 -1
- package/dist/src/config/configTemplate.d.ts.map +1 -1
- package/dist/src/config/configTemplate.js +8 -0
- package/dist/src/config/configTemplate.js.map +1 -1
- package/dist/src/content/ContentApiControllerFactory.js +1 -1
- package/dist/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/src/content/ContentGraphQLContextFactory.d.ts +3 -3
- package/dist/src/content/ContentGraphQLContextFactory.d.ts.map +1 -1
- package/dist/src/content/GraphQLSchemaContributor.d.ts +2 -2
- package/dist/src/content/GraphQLSchemaContributor.d.ts.map +1 -1
- package/dist/src/content/GraphQlSchemaFactory.d.ts.map +1 -1
- package/dist/src/content/GraphQlSchemaFactory.js +30 -16
- package/dist/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/src/project/ProjectContainer.d.ts +10 -3
- package/dist/src/project/ProjectContainer.d.ts.map +1 -1
- package/dist/src/project/ProjectContainer.js +6 -4
- package/dist/src/project/ProjectContainer.js.map +1 -1
- package/dist/src/project/ProjectDatabaseMetadataResolver.d.ts +4 -4
- package/dist/src/project/ProjectDatabaseMetadataResolver.d.ts.map +1 -1
- package/dist/src/project/ProjectDatabaseMetadataResolver.js +1 -1
- package/dist/src/project/ProjectDatabaseMetadataResolver.js.map +1 -1
- package/dist/src/project/ProjectSchemaResolver.js +1 -1
- package/dist/src/project/ProjectSchemaResolver.js.map +1 -1
- package/dist/src/projectGroup/ProjectGroupContainer.d.ts +1 -2
- package/dist/src/projectGroup/ProjectGroupContainer.d.ts.map +1 -1
- package/dist/src/projectGroup/ProjectGroupContainer.js +21 -5
- package/dist/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/src/system/SystemGraphQLContextFactory.d.ts.map +1 -1
- package/dist/src/system/SystemGraphQLContextFactory.js +1 -2
- package/dist/src/system/SystemGraphQLContextFactory.js.map +1 -1
- package/dist/src/transfer/ExportApiControllerFactory.js +1 -1
- package/dist/src/transfer/ExportApiControllerFactory.js.map +1 -1
- package/dist/src/transfer/ExportExecutor.js +1 -1
- package/dist/src/transfer/ExportExecutor.js.map +1 -1
- package/dist/src/transfer/ImportExecutor.d.ts.map +1 -1
- package/dist/src/transfer/ImportExecutor.js +9 -7
- package/dist/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/tests/cases/unit/configResolver.test.js +10 -4
- package/dist/tests/cases/unit/configResolver.test.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/common/Authorizator.ts +2 -1
- package/src/config/configTemplate.ts +8 -0
- package/src/content/ContentApiControllerFactory.ts +1 -1
- package/src/content/ContentGraphQLContextFactory.ts +3 -3
- package/src/content/GraphQLSchemaContributor.ts +2 -2
- package/src/content/GraphQlSchemaFactory.ts +33 -17
- package/src/project/ProjectContainer.ts +17 -7
- package/src/project/ProjectDatabaseMetadataResolver.ts +6 -6
- package/src/project/ProjectSchemaResolver.ts +1 -1
- package/src/projectGroup/ProjectGroupContainer.ts +25 -9
- package/src/system/SystemGraphQLContextFactory.ts +1 -2
- package/src/transfer/ExportApiControllerFactory.ts +1 -1
- package/src/transfer/ExportExecutor.ts +1 -1
- package/src/transfer/ImportExecutor.ts +9 -7
- package/tests/cases/unit/configResolver.test.ts +10 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-http",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0-alpha.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"typings": "dist/src/index.d.ts",
|
|
@@ -13,22 +13,22 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@apollographql/graphql-playground-html": "^1.6.24",
|
|
16
|
-
"@contember/config-loader": "1.
|
|
17
|
-
"@contember/database": "1.
|
|
18
|
-
"@contember/database-migrations": "1.
|
|
19
|
-
"@contember/dic": "1.
|
|
20
|
-
"@contember/engine-common": "1.
|
|
21
|
-
"@contember/engine-content-api": "1.
|
|
22
|
-
"@contember/engine-system-api": "1.
|
|
23
|
-
"@contember/engine-tenant-api": "1.
|
|
24
|
-
"@contember/graphql-utils": "1.
|
|
25
|
-
"@contember/logger": "1.
|
|
26
|
-
"@contember/schema": "1.
|
|
27
|
-
"@contember/schema-migrations": "1.
|
|
28
|
-
"@contember/schema-utils": "1.
|
|
29
|
-
"@contember/typesafe": "1.
|
|
30
|
-
"@graphql-tools/merge": "^
|
|
31
|
-
"@graphql-tools/schema": "^
|
|
16
|
+
"@contember/config-loader": "1.4.0-alpha.1",
|
|
17
|
+
"@contember/database": "1.4.0-alpha.1",
|
|
18
|
+
"@contember/database-migrations": "1.4.0-alpha.1",
|
|
19
|
+
"@contember/dic": "1.4.0-alpha.1",
|
|
20
|
+
"@contember/engine-common": "1.4.0-alpha.1",
|
|
21
|
+
"@contember/engine-content-api": "1.4.0-alpha.1",
|
|
22
|
+
"@contember/engine-system-api": "1.4.0-alpha.1",
|
|
23
|
+
"@contember/engine-tenant-api": "1.4.0-alpha.1",
|
|
24
|
+
"@contember/graphql-utils": "1.4.0-alpha.1",
|
|
25
|
+
"@contember/logger": "1.4.0-alpha.1",
|
|
26
|
+
"@contember/schema": "1.4.0-alpha.1",
|
|
27
|
+
"@contember/schema-migrations": "1.4.0-alpha.1",
|
|
28
|
+
"@contember/schema-utils": "1.4.0-alpha.1",
|
|
29
|
+
"@contember/typesafe": "1.4.0-alpha.1",
|
|
30
|
+
"@graphql-tools/merge": "^9.0.0",
|
|
31
|
+
"@graphql-tools/schema": "^10.0.0",
|
|
32
32
|
"@koa/cors": "^3.1.0",
|
|
33
33
|
"@sentry/node": "^7.1.1",
|
|
34
34
|
"bcryptjs": "^2.4.3",
|
|
@@ -14,6 +14,7 @@ export class Authenticator {
|
|
|
14
14
|
|
|
15
15
|
constructor(
|
|
16
16
|
private readonly tenantDatabase: DatabaseContext,
|
|
17
|
+
private readonly tenantReadDatabase: DatabaseContext,
|
|
17
18
|
private readonly apiKeyManager: ApiKeyManager,
|
|
18
19
|
) {
|
|
19
20
|
}
|
|
@@ -31,7 +32,7 @@ export class Authenticator {
|
|
|
31
32
|
throw this.createAuthError(`invalid Authorization header format`)
|
|
32
33
|
}
|
|
33
34
|
const [, token] = match
|
|
34
|
-
const authResult = await timer('Auth', () => this.apiKeyManager.verifyAndProlong(this.tenantDatabase, token))
|
|
35
|
+
const authResult = await timer('Auth', () => this.apiKeyManager.verifyAndProlong(this.tenantDatabase, this.tenantReadDatabase, token))
|
|
35
36
|
if (!authResult.ok) {
|
|
36
37
|
throw this.createAuthError(authResult.errorMessage)
|
|
37
38
|
}
|
|
@@ -27,6 +27,14 @@ export const configTemplate: any = {
|
|
|
27
27
|
password: `%tenant.env.DB_PASSWORD%`,
|
|
28
28
|
database: `%tenant.env.DB_NAME%`,
|
|
29
29
|
...createDbConfigTemplate('tenant.env.DB'),
|
|
30
|
+
read: {
|
|
31
|
+
host: `%?tenant.env.DB_READ_HOST%`,
|
|
32
|
+
port: `%?tenant.env.DB_READ_PORT::number%`,
|
|
33
|
+
user: `%?tenant.env.DB_READ_USER%`,
|
|
34
|
+
password: `%?tenant.env.DB_READ_PASSWORD%`,
|
|
35
|
+
database: `%?tenant.env.DB_READ_NAME%`,
|
|
36
|
+
...createDbConfigTemplate('tenant.env.DB_READ'),
|
|
37
|
+
},
|
|
30
38
|
},
|
|
31
39
|
mailer: {
|
|
32
40
|
from: '%?tenant.env.MAILER_FROM%',
|
|
@@ -31,7 +31,7 @@ export class ContentApiControllerFactory {
|
|
|
31
31
|
project: project.slug,
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
const systemDatabase = projectContainer.
|
|
34
|
+
const systemDatabase = projectContainer.systemReadDatabaseContext
|
|
35
35
|
const stage = await systemDatabase.queryHandler.fetch(new StageBySlugQuery(params.stageSlug))
|
|
36
36
|
if (!stage) {
|
|
37
37
|
return new HttpErrorResponse(404, `Stage ${params.stageSlug} NOT found`)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Context, createAclVariables, ExecutionContainerFactory } from '@contember/engine-content-api'
|
|
2
|
-
import { Client } from '@contember/database'
|
|
2
|
+
import { Client, DatabaseMetadata } from '@contember/database'
|
|
3
3
|
import { Acl, Schema } from '@contember/schema'
|
|
4
4
|
|
|
5
5
|
import { AuthResult } from '../common'
|
|
6
6
|
import { KoaContext, Timer } from '../application'
|
|
7
7
|
import { Providers } from '../providers'
|
|
8
8
|
import { GraphQLKoaState } from '../graphql'
|
|
9
|
-
import { ParsedMembership
|
|
9
|
+
import { ParsedMembership } from '@contember/schema-utils'
|
|
10
10
|
import { Stage } from '@contember/engine-system-api'
|
|
11
11
|
import { ProjectConfig } from '../project/config'
|
|
12
12
|
|
|
@@ -26,7 +26,7 @@ export class ContentGraphQLContextFactory {
|
|
|
26
26
|
create({ db, schema, schemaDatabaseMetadata, authResult, memberships, permissions, timer, koaContext, requestDebug, systemSchema, stage, project }: {
|
|
27
27
|
db: Client
|
|
28
28
|
schema: Schema & { id: number }
|
|
29
|
-
schemaDatabaseMetadata:
|
|
29
|
+
schemaDatabaseMetadata: DatabaseMetadata
|
|
30
30
|
permissions: Acl.Permissions
|
|
31
31
|
authResult: AuthResult
|
|
32
32
|
memberships: readonly ParsedMembership[]
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Schema } from '@contember/schema'
|
|
2
|
-
import { GraphQLSchema } from 'graphql'
|
|
2
|
+
import { GraphQLSchema, GraphQLSchemaConfig } from 'graphql'
|
|
3
3
|
import { Identity } from './Identity'
|
|
4
4
|
|
|
5
5
|
export type GraphQLSchemaContributorContext = { schema: Schema; identity: Identity }
|
|
6
6
|
|
|
7
7
|
export interface GraphQLSchemaContributor {
|
|
8
|
-
createSchema(context: GraphQLSchemaContributorContext): undefined | GraphQLSchema
|
|
8
|
+
createSchema(context: GraphQLSchemaContributorContext): undefined | GraphQLSchema | GraphQLSchemaConfig
|
|
9
9
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Authorizator,
|
|
3
|
+
Context,
|
|
3
4
|
EntityRulesResolver,
|
|
4
5
|
GraphQlSchemaBuilderFactory,
|
|
5
6
|
IntrospectionSchemaDefinitionFactory,
|
|
@@ -7,10 +8,8 @@ import {
|
|
|
7
8
|
PermissionFactory,
|
|
8
9
|
} from '@contember/engine-content-api'
|
|
9
10
|
import { Acl, Schema } from '@contember/schema'
|
|
10
|
-
import { GraphQLSchema } from 'graphql'
|
|
11
|
-
import { makeExecutableSchema, mergeSchemas } from '@graphql-tools/schema'
|
|
11
|
+
import { GraphQLFieldConfig, GraphQLNamedType, GraphQLSchema } from 'graphql'
|
|
12
12
|
import { GraphQLSchemaContributor } from './GraphQLSchemaContributor'
|
|
13
|
-
import { JSONType } from '@contember/graphql-utils'
|
|
14
13
|
import { Identity } from './Identity'
|
|
15
14
|
import { ContentApiSpecificCache } from './ContentApiSpecificCache'
|
|
16
15
|
|
|
@@ -36,29 +35,46 @@ export class GraphQlSchemaFactory {
|
|
|
36
35
|
|
|
37
36
|
const authorizator = new Authorizator(permissions, schema.acl.customPrimary ?? false)
|
|
38
37
|
const dataSchemaBuilder = this.graphqlSchemaBuilderFactory.create(schema.model, authorizator)
|
|
39
|
-
const
|
|
38
|
+
const introspectionSchemaFactory = new IntrospectionSchemaDefinitionFactory(
|
|
40
39
|
new IntrospectionSchemaFactory(
|
|
41
40
|
schema.model,
|
|
42
41
|
new EntityRulesResolver(schema.validation, schema.model),
|
|
43
42
|
authorizator,
|
|
44
43
|
),
|
|
45
44
|
)
|
|
46
|
-
const
|
|
47
|
-
const contentSchema = makeExecutableSchema({
|
|
48
|
-
...contentSchemaFactory.create(),
|
|
49
|
-
resolverValidationOptions: {
|
|
50
|
-
requireResolversForResolveType: 'ignore',
|
|
51
|
-
},
|
|
52
|
-
})
|
|
45
|
+
const introspectionSchema = introspectionSchemaFactory.createConfig()
|
|
53
46
|
|
|
54
47
|
const otherSchemas = this.schemaContributors
|
|
55
48
|
.map(it => it.createSchema({ schema, identity }))
|
|
56
|
-
.filter((it): it is
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
49
|
+
.filter(<T>(it: T | undefined): it is T => it !== undefined)
|
|
50
|
+
|
|
51
|
+
const queries = new Map<string, GraphQLFieldConfig<any, Context, any>>()
|
|
52
|
+
const mutations = new Map<string, GraphQLFieldConfig<any, Context, any>>()
|
|
53
|
+
const types: GraphQLNamedType[] = []
|
|
54
|
+
|
|
55
|
+
for (const schema of [introspectionSchema, ...otherSchemas]) {
|
|
56
|
+
if (schema instanceof GraphQLSchema) {
|
|
57
|
+
for (const [field, config] of Object.entries(schema.getQueryType()?.toConfig().fields ?? {})) {
|
|
58
|
+
queries.set(field, config)
|
|
59
|
+
}
|
|
60
|
+
for (const [field, config] of Object.entries(schema.getQueryType()?.toConfig().fields ?? {})) {
|
|
61
|
+
mutations.set(field, config)
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
for (const [field, config] of Object.entries(schema.query?.toConfig().fields ?? {})) {
|
|
65
|
+
queries.set(field, config)
|
|
66
|
+
}
|
|
67
|
+
for (const [field, config] of Object.entries(schema.mutation?.toConfig().fields ?? {})) {
|
|
68
|
+
mutations.set(field, config)
|
|
69
|
+
}
|
|
70
|
+
types.push(...(schema.types ?? []))
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const graphQlSchema = dataSchemaBuilder.build({
|
|
75
|
+
mutations,
|
|
76
|
+
queries,
|
|
77
|
+
types,
|
|
62
78
|
})
|
|
63
79
|
|
|
64
80
|
return { schema: graphQlSchema, permissions }
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Builder } from '@contember/dic'
|
|
2
|
-
import { Connection } from '@contember/database'
|
|
2
|
+
import { Connection, DatabaseMetadataResolver } from '@contember/database'
|
|
3
3
|
import {
|
|
4
4
|
DatabaseContextFactory,
|
|
5
5
|
ProjectInitializer,
|
|
6
|
-
SchemaDatabaseMetadataResolver,
|
|
7
6
|
SchemaVersionBuilder,
|
|
8
7
|
StageCreator,
|
|
9
8
|
SystemMigrationsRunner,
|
|
9
|
+
DatabaseContext,
|
|
10
10
|
} from '@contember/engine-system-api'
|
|
11
11
|
import { GraphQlSchemaBuilderFactory, PermissionFactory } from '@contember/engine-content-api'
|
|
12
12
|
import { Logger } from '@contember/logger'
|
|
@@ -26,6 +26,8 @@ import { ProjectDatabaseMetadataResolver } from './ProjectDatabaseMetadataResolv
|
|
|
26
26
|
|
|
27
27
|
export interface ProjectContainer {
|
|
28
28
|
systemDatabaseContextFactory: DatabaseContextFactory
|
|
29
|
+
systemDatabaseContext: DatabaseContext
|
|
30
|
+
systemReadDatabaseContext: DatabaseContext
|
|
29
31
|
project: ProjectConfig
|
|
30
32
|
logger: Logger
|
|
31
33
|
connection: Connection
|
|
@@ -34,6 +36,7 @@ export interface ProjectContainer {
|
|
|
34
36
|
contentSchemaResolver: ContentSchemaResolver
|
|
35
37
|
projectInitializer: ProjectInitializer
|
|
36
38
|
projectDatabaseMetadataResolver: ProjectDatabaseMetadataResolver
|
|
39
|
+
databaseMetadataResolver: DatabaseMetadataResolver
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
export class ProjectContainerFactoryFactory {
|
|
@@ -79,11 +82,14 @@ export class ProjectContainerFactory {
|
|
|
79
82
|
'connection',
|
|
80
83
|
'readConnection',
|
|
81
84
|
'systemDatabaseContextFactory',
|
|
85
|
+
'systemDatabaseContext',
|
|
86
|
+
'systemReadDatabaseContext',
|
|
82
87
|
'contentSchemaResolver',
|
|
83
88
|
'graphQlSchemaFactory',
|
|
84
89
|
'projectInitializer',
|
|
85
90
|
'logger',
|
|
86
91
|
'projectDatabaseMetadataResolver',
|
|
92
|
+
'databaseMetadataResolver',
|
|
87
93
|
)
|
|
88
94
|
}
|
|
89
95
|
|
|
@@ -135,16 +141,20 @@ export class ProjectContainerFactory {
|
|
|
135
141
|
new ContentSchemaResolver(schemaVersionBuilder))
|
|
136
142
|
.addService('systemSchemaName', ({ project }) =>
|
|
137
143
|
project.db.systemSchema ?? 'system')
|
|
138
|
-
.addService('systemDatabaseContextFactory', ({
|
|
139
|
-
new DatabaseContextFactory(systemSchemaName,
|
|
144
|
+
.addService('systemDatabaseContextFactory', ({ providers, systemSchemaName }) =>
|
|
145
|
+
new DatabaseContextFactory(systemSchemaName, providers))
|
|
146
|
+
.addService('systemDatabaseContext', ({ connection, systemDatabaseContextFactory }) =>
|
|
147
|
+
systemDatabaseContextFactory.create(connection))
|
|
148
|
+
.addService('systemReadDatabaseContext', ({ readConnection, systemDatabaseContextFactory }) =>
|
|
149
|
+
systemDatabaseContextFactory.create(readConnection))
|
|
140
150
|
.addService('systemMigrationGroups', () =>
|
|
141
151
|
Object.fromEntries(this.plugins.flatMap(it => it.getSystemMigrations ? [[it.name, it.getSystemMigrations()]] : [])))
|
|
142
152
|
.addService('databaseMetadataResolver', () =>
|
|
143
|
-
new
|
|
153
|
+
new DatabaseMetadataResolver())
|
|
144
154
|
.addService('systemMigrationsRunner', ({ systemDatabaseContextFactory, project, systemSchemaName, systemMigrationGroups, databaseMetadataResolver }) =>
|
|
145
155
|
new SystemMigrationsRunner(systemDatabaseContextFactory, project, systemSchemaName, this.schemaVersionBuilder, systemMigrationGroups, databaseMetadataResolver))
|
|
146
|
-
.addService('projectInitializer', ({ systemMigrationsRunner,
|
|
147
|
-
new ProjectInitializer(new StageCreator(), systemMigrationsRunner,
|
|
156
|
+
.addService('projectInitializer', ({ systemMigrationsRunner, systemDatabaseContext, project }) =>
|
|
157
|
+
new ProjectInitializer(new StageCreator(), systemMigrationsRunner, systemDatabaseContext, project))
|
|
148
158
|
.addService('projectDatabaseMetadataResolver', ({ databaseMetadataResolver }) =>
|
|
149
159
|
new ProjectDatabaseMetadataResolver(databaseMetadataResolver))
|
|
150
160
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DatabaseMetadata, DatabaseMetadataResolver } from '@contember/database'
|
|
2
|
+
import { DatabaseContext } from '@contember/engine-system-api'
|
|
2
3
|
import { Schema } from '@contember/schema'
|
|
3
|
-
import { SchemaDatabaseMetadata } from '@contember/schema-utils'
|
|
4
4
|
|
|
5
5
|
export class ProjectDatabaseMetadataResolver {
|
|
6
6
|
|
|
7
|
-
private cache: WeakMap<Schema, Map<string,
|
|
7
|
+
private cache: WeakMap<Schema, Map<string, DatabaseMetadata>> = new WeakMap()
|
|
8
8
|
|
|
9
9
|
constructor(
|
|
10
|
-
private resolver:
|
|
10
|
+
private resolver: DatabaseMetadataResolver,
|
|
11
11
|
) {
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
async resolveDatabaseMetadata(db: DatabaseContext, schema: Schema, stageSchema: string): Promise<
|
|
14
|
+
async resolveDatabaseMetadata(db: DatabaseContext, schema: Schema, stageSchema: string): Promise<DatabaseMetadata> {
|
|
15
15
|
let schemaCache = this.cache.get(schema)
|
|
16
16
|
if (!schemaCache) {
|
|
17
17
|
schemaCache = new Map()
|
|
@@ -21,7 +21,7 @@ export class ProjectDatabaseMetadataResolver {
|
|
|
21
21
|
if (cachedMeta) {
|
|
22
22
|
return cachedMeta
|
|
23
23
|
}
|
|
24
|
-
const metadata = await this.resolver.resolveMetadata(db, stageSchema)
|
|
24
|
+
const metadata = await this.resolver.resolveMetadata(db.client, stageSchema)
|
|
25
25
|
schemaCache.set(stageSchema, metadata)
|
|
26
26
|
|
|
27
27
|
return metadata
|
|
@@ -12,7 +12,7 @@ export class ProjectSchemaResolver implements ProjectSchemaResolverInterface {
|
|
|
12
12
|
if (!container) {
|
|
13
13
|
return undefined
|
|
14
14
|
}
|
|
15
|
-
const db = container.
|
|
15
|
+
const db = container.systemReadDatabaseContext
|
|
16
16
|
return container.contentSchemaResolver.getSchema(db)
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -30,7 +30,6 @@ export interface ProjectGroupContainer {
|
|
|
30
30
|
projectInitializer: ProjectInitializerInterface
|
|
31
31
|
|
|
32
32
|
tenantContainer: TenantContainer
|
|
33
|
-
tenantDatabase: DatabaseContext
|
|
34
33
|
tenantGraphQLHandler: TenantGraphQLHandler
|
|
35
34
|
|
|
36
35
|
systemContainer: SystemContainer
|
|
@@ -69,11 +68,24 @@ export class ProjectGroupContainerFactory {
|
|
|
69
68
|
config.db)
|
|
70
69
|
.addService('tenantConnection', ({ tenantDbCredentials, logger }): Connection.ConnectionType =>
|
|
71
70
|
Connection.create(tenantDbCredentials, err => logger.error(err)))
|
|
71
|
+
.addService('tenantReadConnection', ({ tenantDbCredentials, logger, tenantConnection }) => {
|
|
72
|
+
if (!tenantDbCredentials.read) {
|
|
73
|
+
return tenantConnection
|
|
74
|
+
}
|
|
75
|
+
return Connection.create({
|
|
76
|
+
...tenantDbCredentials,
|
|
77
|
+
...tenantDbCredentials.read,
|
|
78
|
+
pool: {
|
|
79
|
+
...tenantDbCredentials.pool,
|
|
80
|
+
...tenantDbCredentials.read.pool,
|
|
81
|
+
},
|
|
82
|
+
}, err => logger.error(err))
|
|
83
|
+
})
|
|
72
84
|
.addService('projectSchemaResolver', () =>
|
|
73
85
|
new ProjectSchemaResolverProxy())
|
|
74
86
|
.addService('projectInitializer', () =>
|
|
75
87
|
new ProjectInitializerProxy())
|
|
76
|
-
.addService('tenantContainer', ({ tenantConnection, tenantDbCredentials, projectSchemaResolver, projectInitializer }) => {
|
|
88
|
+
.addService('tenantContainer', ({ tenantConnection, tenantReadConnection, tenantDbCredentials, projectSchemaResolver, projectInitializer }) => {
|
|
77
89
|
const encryptionKey = config.secrets.encryptionKey
|
|
78
90
|
? createSecretKey(Buffer.from(config.secrets.encryptionKey, 'hex'))
|
|
79
91
|
: undefined
|
|
@@ -81,6 +93,7 @@ export class ProjectGroupContainerFactory {
|
|
|
81
93
|
const cryptoWrapper = new CryptoWrapper(encryptionKey)
|
|
82
94
|
return this.tenantContainerFactory.create({
|
|
83
95
|
connection: tenantConnection,
|
|
96
|
+
readConnection: tenantReadConnection,
|
|
84
97
|
dbCredentials: tenantDbCredentials,
|
|
85
98
|
mailOptions: config.mailer,
|
|
86
99
|
tenantCredentials: config.credentials,
|
|
@@ -94,6 +107,8 @@ export class ProjectGroupContainerFactory {
|
|
|
94
107
|
})
|
|
95
108
|
.addService('tenantDatabase', ({ tenantContainer }) =>
|
|
96
109
|
tenantContainer.databaseContext)
|
|
110
|
+
.addService('tenantReadDatabase', ({ tenantContainer }) =>
|
|
111
|
+
tenantContainer.readDatabaseContext)
|
|
97
112
|
.addService('identityFetcher', ({ tenantContainer: { identityFetcher } }) =>
|
|
98
113
|
identityFetcher)
|
|
99
114
|
.addService('systemContainer', ({ identityFetcher }) =>
|
|
@@ -104,12 +119,14 @@ export class ProjectGroupContainerFactory {
|
|
|
104
119
|
this.projectContainerFactoryFactory.create(schemaVersionBuilder, logger))
|
|
105
120
|
.addService('tenantProjectManager', ({ tenantContainer }) =>
|
|
106
121
|
tenantContainer.projectManager)
|
|
107
|
-
.addService('
|
|
122
|
+
.addService('tenantProjectMemberManager', ({ tenantContainer }) =>
|
|
123
|
+
tenantContainer.projectMemberManager)
|
|
124
|
+
.addService('projectContainerResolver', ({ projectContainerFactory, tenantProjectManager, tenantReadDatabase }) =>
|
|
108
125
|
new ProjectContainerResolver(
|
|
109
126
|
projectContainerFactory,
|
|
110
127
|
this.projectConfigResolver,
|
|
111
128
|
tenantProjectManager,
|
|
112
|
-
|
|
129
|
+
tenantReadDatabase,
|
|
113
130
|
config,
|
|
114
131
|
))
|
|
115
132
|
|
|
@@ -123,10 +140,10 @@ export class ProjectGroupContainerFactory {
|
|
|
123
140
|
this.tenantGraphQLHandlerFactory.create(tenantContainer.resolvers))
|
|
124
141
|
.addService('systemGraphQLHandler', ({ systemContainer }) =>
|
|
125
142
|
this.systemGraphQLHandlerFactory.create(systemContainer.systemResolversFactory))
|
|
126
|
-
.addService('authenticator', ({ tenantDatabase, tenantContainer }) =>
|
|
127
|
-
new Authenticator(tenantDatabase, tenantContainer.apiKeyManager))
|
|
128
|
-
.addService('projectMembershipResolver', ({
|
|
129
|
-
new ProjectMembershipResolver(this.debug, new ProjectMembershipFetcher(
|
|
143
|
+
.addService('authenticator', ({ tenantDatabase, tenantReadDatabase, tenantContainer }) =>
|
|
144
|
+
new Authenticator(tenantDatabase, tenantReadDatabase, tenantContainer.apiKeyManager))
|
|
145
|
+
.addService('projectMembershipResolver', ({ tenantProjectMemberManager, tenantReadDatabase }) =>
|
|
146
|
+
new ProjectMembershipResolver(this.debug, new ProjectMembershipFetcher(tenantProjectMemberManager, tenantReadDatabase)))
|
|
130
147
|
.build()
|
|
131
148
|
.pick(
|
|
132
149
|
'projectContainerResolver',
|
|
@@ -135,7 +152,6 @@ export class ProjectGroupContainerFactory {
|
|
|
135
152
|
'systemContainer',
|
|
136
153
|
'systemGraphQLHandler',
|
|
137
154
|
'tenantContainer',
|
|
138
|
-
'tenantDatabase',
|
|
139
155
|
'authenticator',
|
|
140
156
|
'projectMembershipResolver',
|
|
141
157
|
'tenantGraphQLHandler',
|
|
@@ -19,9 +19,8 @@ export class SystemGraphQLContextFactory {
|
|
|
19
19
|
authResult.identityId,
|
|
20
20
|
memberships.map(it => it.role),
|
|
21
21
|
)
|
|
22
|
-
const dbContextFactory = projectContainer.systemDatabaseContextFactory
|
|
23
22
|
|
|
24
|
-
const dbContext =
|
|
23
|
+
const dbContext = projectContainer.systemDatabaseContext
|
|
25
24
|
const schema = await projectContainer.contentSchemaResolver.getSchema(dbContext)
|
|
26
25
|
const systemContext = await systemContainer.resolverContextFactory.create(
|
|
27
26
|
schema,
|
|
@@ -44,7 +44,7 @@ export class ExportApiControllerFactory {
|
|
|
44
44
|
throw new HttpErrorResponse(400, `Project ${project.slug} NOT found`)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
const systemContext = projectContainer.
|
|
47
|
+
const systemContext = projectContainer.systemReadDatabaseContext
|
|
48
48
|
const schema = await projectContainer.contentSchemaResolver.getSchema(systemContext, project.slug)
|
|
49
49
|
const { effective: memberships } = await timer('MembershipFetch', () => projectGroup.projectMembershipResolver.resolveMemberships({
|
|
50
50
|
request: { get: () => '' },
|
|
@@ -32,7 +32,7 @@ export class ExportExecutor {
|
|
|
32
32
|
async* export(request: ExportRequest, projectContainers: Record<string, ProjectContainer>): AsyncIterable<Command> {
|
|
33
33
|
for (const project of request.projects) {
|
|
34
34
|
const projectContainer = projectContainers[project.slug]
|
|
35
|
-
const systemContext = projectContainer.
|
|
35
|
+
const systemContext = projectContainer.systemDatabaseContext
|
|
36
36
|
|
|
37
37
|
if (project.system) {
|
|
38
38
|
const systemMapping = this.systemSchemaTransferMappingFactory.build()
|
|
@@ -100,7 +100,7 @@ export class ImportExecutor {
|
|
|
100
100
|
private async importContentSchemaBegin(groupContainer: ProjectGroupContainer, authResult: AuthResult, it: CommandIterator<'importContentSchemaBegin'>) {
|
|
101
101
|
const [options] = it.commandArgs
|
|
102
102
|
const projectContainer = await this.createProjectContainer(groupContainer, options.project)
|
|
103
|
-
const systemDatabaseContext = projectContainer.
|
|
103
|
+
const systemDatabaseContext = projectContainer.systemDatabaseContext
|
|
104
104
|
const stage = await this.fetchStageBySlug(systemDatabaseContext, options.project, options.stage)
|
|
105
105
|
|
|
106
106
|
const contentSchema = await projectContainer.contentSchemaResolver.getSchema(systemDatabaseContext, stage.slug)
|
|
@@ -118,15 +118,16 @@ export class ImportExecutor {
|
|
|
118
118
|
await this.lockTables(db, options.tables)
|
|
119
119
|
await this.truncateTables(db, options.tables)
|
|
120
120
|
|
|
121
|
-
const
|
|
122
|
-
|
|
121
|
+
const metadata = await projectContainer.databaseMetadataResolver.resolveMetadata(db, db.schema)
|
|
122
|
+
const constraintHelper = new ConstraintHelper(db, metadata)
|
|
123
|
+
await constraintHelper.setConstraintsDeferred('foreignKey')
|
|
123
124
|
|
|
124
125
|
const result = await this.match(await it.next(), {
|
|
125
126
|
importSequence: it => this.importSequence(db, mapping, it),
|
|
126
127
|
insertBegin: it => this.insertBegin(db, mapping, it),
|
|
127
128
|
})
|
|
128
129
|
|
|
129
|
-
await constraintHelper.
|
|
130
|
+
await constraintHelper.setConstraintsImmediate('foreignKey')
|
|
130
131
|
await this.enableTriggers(db, options.tables)
|
|
131
132
|
|
|
132
133
|
return result
|
|
@@ -143,14 +144,15 @@ export class ImportExecutor {
|
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
await this.requireImportAccess(groupContainer, schema, authResult, options.project, 'system')
|
|
146
|
-
const systemDatabaseContext = projectContainer.
|
|
147
|
+
const systemDatabaseContext = projectContainer.systemDatabaseContext
|
|
147
148
|
const mapping = this.systemSchemaTransferMappingFactory.build()
|
|
148
149
|
|
|
149
150
|
return await systemDatabaseContext.client.transaction(async db => {
|
|
150
151
|
await this.truncateTables(db, options.tables)
|
|
151
152
|
|
|
152
|
-
const
|
|
153
|
-
|
|
153
|
+
const metadata = await projectContainer.databaseMetadataResolver.resolveMetadata(db, db.schema)
|
|
154
|
+
const constraintHelper = new ConstraintHelper(db, metadata)
|
|
155
|
+
await constraintHelper.setConstraintsDeferred('foreignKey')
|
|
154
156
|
|
|
155
157
|
return await this.match(await it.next(), {
|
|
156
158
|
insertBegin: it => this.insertBegin(db, mapping, it),
|
|
@@ -19,7 +19,7 @@ const tenantConfig = {
|
|
|
19
19
|
read: { host: 'c0.cluster-ro-abc.eu-west-1.rds.amazonaws.com' },
|
|
20
20
|
},
|
|
21
21
|
}
|
|
22
|
-
it('resolves tenant config
|
|
22
|
+
it('resolves tenant config', () => {
|
|
23
23
|
const tenantResolver = createTenantConfigResolver(env, configTemplate.tenant)
|
|
24
24
|
const resolvedTenantConfig = tenantResolver('test', tenantConfig)
|
|
25
25
|
assert.deepEqual(resolvedTenantConfig, {
|
|
@@ -31,11 +31,14 @@ it('resolves tenant config config', () => {
|
|
|
31
31
|
database: 'p_test_e',
|
|
32
32
|
connectionTimeoutMs: 5000,
|
|
33
33
|
pool: { maxConnections: 1000, maxConnecting: 10, idleTimeoutMs: 60000 },
|
|
34
|
-
read: {
|
|
34
|
+
read: {
|
|
35
|
+
host: 'c0.cluster-ro-abc.eu-west-1.rds.amazonaws.com',
|
|
36
|
+
pool: {},
|
|
37
|
+
},
|
|
35
38
|
}, mailer: {}, credentials: {}, secrets: {},
|
|
36
39
|
})
|
|
37
40
|
})
|
|
38
|
-
it('resolves project config
|
|
41
|
+
it('resolves project config', () => {
|
|
39
42
|
const tenantResolver = createTenantConfigResolver(env, configTemplate.tenant)
|
|
40
43
|
const resolvedTenantConfig = tenantResolver('test', tenantConfig)
|
|
41
44
|
|
|
@@ -59,7 +62,10 @@ it('resolves project config config', () => {
|
|
|
59
62
|
database: 'p_test_e',
|
|
60
63
|
connectionTimeoutMs: 5000,
|
|
61
64
|
pool: { maxConnections: 1000, maxConnecting: 10, idleTimeoutMs: 60000 },
|
|
62
|
-
read: {
|
|
65
|
+
read: {
|
|
66
|
+
host: 'c0.cluster-ro-abc.eu-west-1.rds.amazonaws.com',
|
|
67
|
+
pool: {},
|
|
68
|
+
},
|
|
63
69
|
useTenantDb: true,
|
|
64
70
|
systemSchema: 'system_test_e',
|
|
65
71
|
},
|