@contember/engine-http 1.4.0-alpha.2 → 1.4.0-alpha.3
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/MasterContainer.d.ts +14 -3
- package/dist/src/MasterContainer.d.ts.map +1 -1
- package/dist/src/MasterContainer.js +14 -4
- package/dist/src/MasterContainer.js.map +1 -1
- package/dist/src/application/application.d.ts +26 -10
- package/dist/src/application/application.d.ts.map +1 -1
- package/dist/src/application/application.js +53 -8
- package/dist/src/application/application.js.map +1 -1
- package/dist/src/config/configSchema.d.ts +1 -0
- package/dist/src/config/configSchema.d.ts.map +1 -1
- package/dist/src/config/configSchema.js +15 -0
- package/dist/src/config/configSchema.js.map +1 -1
- package/dist/src/config/configTemplate.d.ts.map +1 -1
- package/dist/src/config/configTemplate.js +1 -0
- package/dist/src/config/configTemplate.js.map +1 -1
- package/dist/src/content/ContentApiControllerFactory.d.ts.map +1 -1
- package/dist/src/content/ContentApiControllerFactory.js +3 -1
- package/dist/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/src/content/ContentGraphQLContextFactory.d.ts +2 -5
- package/dist/src/content/ContentGraphQLContextFactory.d.ts.map +1 -1
- package/dist/src/content/ContentGraphQLContextFactory.js +1 -2
- package/dist/src/content/ContentGraphQLContextFactory.js.map +1 -1
- package/dist/src/content/ContentQueryHandlerFactory.d.ts.map +1 -1
- package/dist/src/content/ContentQueryHandlerFactory.js +1 -3
- package/dist/src/content/ContentQueryHandlerFactory.js.map +1 -1
- package/dist/src/graphql/execution.d.ts +1 -0
- package/dist/src/graphql/execution.d.ts.map +1 -1
- package/dist/src/graphql/execution.js +9 -11
- package/dist/src/graphql/execution.js.map +1 -1
- package/dist/src/graphql/state.d.ts +0 -5
- package/dist/src/graphql/state.d.ts.map +1 -1
- package/dist/src/graphql/state.js +0 -9
- package/dist/src/graphql/state.js.map +1 -1
- package/dist/src/project/ProjectContainer.d.ts +8 -24
- package/dist/src/project/ProjectContainer.d.ts.map +1 -1
- package/dist/src/project/ProjectContainer.js +18 -20
- package/dist/src/project/ProjectContainer.js.map +1 -1
- package/dist/src/system/ContentQueryExecutor.d.ts +9 -0
- package/dist/src/system/ContentQueryExecutor.d.ts.map +1 -0
- package/dist/src/system/ContentQueryExecutor.js +69 -0
- package/dist/src/system/ContentQueryExecutor.js.map +1 -0
- package/dist/src/system/SystemApiMiddlewareFactory.d.ts.map +1 -1
- package/dist/src/system/SystemApiMiddlewareFactory.js +6 -2
- package/dist/src/system/SystemApiMiddlewareFactory.js.map +1 -1
- package/dist/src/system/SystemGraphQLContextFactory.d.ts +1 -4
- package/dist/src/system/SystemGraphQLContextFactory.d.ts.map +1 -1
- package/dist/src/system/SystemGraphQLContextFactory.js +2 -3
- package/dist/src/system/SystemGraphQLContextFactory.js.map +1 -1
- package/dist/src/system/SystemGraphQLHandlerFactory.d.ts +1 -5
- package/dist/src/system/SystemGraphQLHandlerFactory.d.ts.map +1 -1
- package/dist/src/system/SystemGraphQLHandlerFactory.js +1 -3
- package/dist/src/system/SystemGraphQLHandlerFactory.js.map +1 -1
- package/dist/src/tenant/TenantApiMiddlewareFactory.d.ts.map +1 -1
- package/dist/src/tenant/TenantApiMiddlewareFactory.js +6 -2
- package/dist/src/tenant/TenantApiMiddlewareFactory.js.map +1 -1
- package/dist/src/tenant/TenantGraphQLContextFactory.d.ts +1 -4
- package/dist/src/tenant/TenantGraphQLContextFactory.d.ts.map +1 -1
- package/dist/src/tenant/TenantGraphQLContextFactory.js +1 -2
- package/dist/src/tenant/TenantGraphQLContextFactory.js.map +1 -1
- package/dist/src/tenant/TenantGraphQLHandlerFactory.d.ts +1 -3
- package/dist/src/tenant/TenantGraphQLHandlerFactory.d.ts.map +1 -1
- package/dist/src/tenant/TenantGraphQLHandlerFactory.js +1 -3
- package/dist/src/tenant/TenantGraphQLHandlerFactory.js.map +1 -1
- package/dist/src/transfer/ImportExecutor.d.ts +3 -1
- package/dist/src/transfer/ImportExecutor.d.ts.map +1 -1
- package/dist/src/transfer/ImportExecutor.js +4 -3
- package/dist/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/utils/serverStartup.d.ts +1 -0
- package/dist/src/utils/serverStartup.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -34
- package/src/MasterContainer.ts +24 -9
- package/src/application/application.ts +93 -23
- package/src/config/configSchema.ts +15 -0
- package/src/config/configTemplate.ts +1 -0
- package/src/content/ContentApiControllerFactory.ts +5 -1
- package/src/content/ContentGraphQLContextFactory.ts +2 -7
- package/src/content/ContentQueryHandlerFactory.ts +2 -10
- package/src/graphql/execution.ts +3 -3
- package/src/graphql/state.ts +0 -13
- package/src/project/ProjectContainer.ts +25 -35
- package/src/system/ContentQueryExecutor.ts +79 -0
- package/src/system/SystemApiMiddlewareFactory.ts +8 -2
- package/src/system/SystemGraphQLContextFactory.ts +2 -6
- package/src/system/SystemGraphQLHandlerFactory.ts +2 -16
- package/src/tenant/TenantApiMiddlewareFactory.ts +8 -3
- package/src/tenant/TenantGraphQLContextFactory.ts +1 -5
- package/src/tenant/TenantGraphQLHandlerFactory.ts +3 -11
- package/src/transfer/ImportExecutor.ts +4 -3
|
@@ -11,12 +11,7 @@ import {
|
|
|
11
11
|
import { GraphQlSchemaBuilderFactory, PermissionFactory } from '@contember/engine-content-api'
|
|
12
12
|
import { Logger } from '@contember/logger'
|
|
13
13
|
import { ProjectConfig } from './config'
|
|
14
|
-
import {
|
|
15
|
-
ContentSchemaResolver,
|
|
16
|
-
GraphQLSchemaContributor,
|
|
17
|
-
GraphQlSchemaFactory,
|
|
18
|
-
GraphQLSchemaFactoryResult,
|
|
19
|
-
} from '../content'
|
|
14
|
+
import { ContentSchemaResolver, GraphQLSchemaContributor, GraphQlSchemaFactory, GraphQLSchemaFactoryResult } from '../content'
|
|
20
15
|
import { Providers } from '../providers'
|
|
21
16
|
import { Plugin } from '../plugin/Plugin'
|
|
22
17
|
import { ServerConfig } from '../config/config'
|
|
@@ -36,26 +31,29 @@ export interface ProjectContainer {
|
|
|
36
31
|
contentSchemaResolver: ContentSchemaResolver
|
|
37
32
|
projectInitializer: ProjectInitializer
|
|
38
33
|
projectDatabaseMetadataResolver: ProjectDatabaseMetadataResolver
|
|
39
|
-
databaseMetadataResolver: DatabaseMetadataResolver
|
|
40
34
|
}
|
|
41
35
|
|
|
42
36
|
export class ProjectContainerFactoryFactory {
|
|
43
37
|
constructor(
|
|
44
|
-
private readonly debug: boolean,
|
|
45
38
|
private readonly plugins: Plugin[],
|
|
46
39
|
private readonly providers: Providers,
|
|
47
40
|
private readonly serverConfig: ServerConfig,
|
|
41
|
+
private readonly graphQlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,
|
|
42
|
+
private readonly permissionFactory: PermissionFactory,
|
|
43
|
+
private readonly databaseMetadataResolver: DatabaseMetadataResolver,
|
|
48
44
|
) {
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
create(schemaVersionBuilder: SchemaVersionBuilder, logger: Logger): ProjectContainerFactory {
|
|
52
48
|
return new ProjectContainerFactory(
|
|
53
|
-
this.debug,
|
|
54
49
|
this.plugins,
|
|
55
50
|
schemaVersionBuilder,
|
|
56
51
|
this.providers,
|
|
57
52
|
logger,
|
|
58
53
|
this.serverConfig,
|
|
54
|
+
this.graphQlSchemaBuilderFactory,
|
|
55
|
+
this.permissionFactory,
|
|
56
|
+
this.databaseMetadataResolver,
|
|
59
57
|
)
|
|
60
58
|
}
|
|
61
59
|
}
|
|
@@ -66,12 +64,14 @@ interface ProjectContainerFactoryArgs {
|
|
|
66
64
|
|
|
67
65
|
export class ProjectContainerFactory {
|
|
68
66
|
constructor(
|
|
69
|
-
private readonly debug: boolean,
|
|
70
67
|
private readonly plugins: Plugin<any>[],
|
|
71
68
|
private readonly schemaVersionBuilder: SchemaVersionBuilder,
|
|
72
69
|
private readonly providers: Providers,
|
|
73
70
|
private readonly logger: Logger,
|
|
74
71
|
private readonly serverConfig: ServerConfig,
|
|
72
|
+
private readonly graphQlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,
|
|
73
|
+
private readonly permissionFactory: PermissionFactory,
|
|
74
|
+
private readonly databaseMetadataResolver: DatabaseMetadataResolver,
|
|
75
75
|
) {}
|
|
76
76
|
|
|
77
77
|
public createContainer(args: ProjectContainerFactoryArgs): ProjectContainer {
|
|
@@ -89,16 +89,11 @@ export class ProjectContainerFactory {
|
|
|
89
89
|
'projectInitializer',
|
|
90
90
|
'logger',
|
|
91
91
|
'projectDatabaseMetadataResolver',
|
|
92
|
-
'databaseMetadataResolver',
|
|
93
92
|
)
|
|
94
93
|
}
|
|
95
94
|
|
|
96
95
|
protected createBuilder({ project }: ProjectContainerFactoryArgs) {
|
|
97
96
|
return new Builder({})
|
|
98
|
-
.addService('providers', () =>
|
|
99
|
-
this.providers)
|
|
100
|
-
.addService('schemaVersionBuilder', () =>
|
|
101
|
-
this.schemaVersionBuilder)
|
|
102
97
|
.addService('logger', () =>
|
|
103
98
|
this.logger.child({ project: project.slug }))
|
|
104
99
|
.addService('project', () =>
|
|
@@ -118,44 +113,39 @@ export class ProjectContainerFactory {
|
|
|
118
113
|
},
|
|
119
114
|
}, err => logger.error(err))
|
|
120
115
|
})
|
|
121
|
-
|
|
122
|
-
new GraphQlSchemaBuilderFactory())
|
|
123
|
-
.addService('permissionFactory', ({}) =>
|
|
124
|
-
new PermissionFactory())
|
|
116
|
+
|
|
125
117
|
.addService('graphqlSchemaCache', () =>
|
|
126
118
|
new ContentApiSpecificCache<Schema, GraphQLSchemaFactoryResult>({
|
|
127
119
|
ttlSeconds: this.serverConfig.contentApi.schemaCacheTtlSeconds,
|
|
128
120
|
}))
|
|
129
|
-
.addService('graphQlSchemaFactory', ({ project,
|
|
121
|
+
.addService('graphQlSchemaFactory', ({ project, graphqlSchemaCache }) => {
|
|
130
122
|
const contributors = this.plugins
|
|
131
|
-
.map(it => (it.getSchemaContributor ? it.getSchemaContributor({ project, providers }) : null))
|
|
123
|
+
.map(it => (it.getSchemaContributor ? it.getSchemaContributor({ project, providers: this.providers }) : null))
|
|
132
124
|
.filter((it): it is GraphQLSchemaContributor => !!it)
|
|
133
125
|
return new GraphQlSchemaFactory(
|
|
134
126
|
graphqlSchemaCache,
|
|
135
|
-
graphQlSchemaBuilderFactory,
|
|
136
|
-
permissionFactory,
|
|
127
|
+
this.graphQlSchemaBuilderFactory,
|
|
128
|
+
this.permissionFactory,
|
|
137
129
|
contributors,
|
|
138
130
|
)
|
|
139
131
|
})
|
|
140
|
-
.addService('contentSchemaResolver', (
|
|
141
|
-
new ContentSchemaResolver(schemaVersionBuilder))
|
|
132
|
+
.addService('contentSchemaResolver', () =>
|
|
133
|
+
new ContentSchemaResolver(this.schemaVersionBuilder))
|
|
142
134
|
.addService('systemSchemaName', ({ project }) =>
|
|
143
135
|
project.db.systemSchema ?? 'system')
|
|
144
|
-
.addService('systemDatabaseContextFactory', ({
|
|
145
|
-
new DatabaseContextFactory(systemSchemaName, providers))
|
|
136
|
+
.addService('systemDatabaseContextFactory', ({ systemSchemaName }) =>
|
|
137
|
+
new DatabaseContextFactory(systemSchemaName, this.providers))
|
|
146
138
|
.addService('systemDatabaseContext', ({ connection, systemDatabaseContextFactory }) =>
|
|
147
139
|
systemDatabaseContextFactory.create(connection))
|
|
148
140
|
.addService('systemReadDatabaseContext', ({ readConnection, systemDatabaseContextFactory }) =>
|
|
149
141
|
systemDatabaseContextFactory.create(readConnection))
|
|
150
142
|
.addService('systemMigrationGroups', () =>
|
|
151
143
|
Object.fromEntries(this.plugins.flatMap(it => it.getSystemMigrations ? [[it.name, it.getSystemMigrations()]] : [])))
|
|
152
|
-
.addService('
|
|
153
|
-
new
|
|
154
|
-
.addService('
|
|
155
|
-
new
|
|
156
|
-
.addService('
|
|
157
|
-
new
|
|
158
|
-
.addService('projectDatabaseMetadataResolver', ({ databaseMetadataResolver }) =>
|
|
159
|
-
new ProjectDatabaseMetadataResolver(databaseMetadataResolver))
|
|
144
|
+
.addService('systemMigrationsRunner', ({ systemDatabaseContextFactory, project, systemSchemaName, systemMigrationGroups }) =>
|
|
145
|
+
new SystemMigrationsRunner(systemDatabaseContextFactory, { ...project, systemSchema: systemSchemaName }, this.schemaVersionBuilder, systemMigrationGroups, this.databaseMetadataResolver))
|
|
146
|
+
.addService('projectInitializer', ({ systemMigrationsRunner, systemDatabaseContext, project, systemSchemaName }) =>
|
|
147
|
+
new ProjectInitializer(new StageCreator(), systemMigrationsRunner, systemDatabaseContext, { ...project, systemSchema: systemSchemaName }))
|
|
148
|
+
.addService('projectDatabaseMetadataResolver', () =>
|
|
149
|
+
new ProjectDatabaseMetadataResolver(this.databaseMetadataResolver))
|
|
160
150
|
}
|
|
161
151
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContentQueryExecutor,
|
|
3
|
+
ContentQueryExecutorContext,
|
|
4
|
+
ContentQueryExecutorQuery,
|
|
5
|
+
ContentQueryExecutorResult,
|
|
6
|
+
} from '@contember/engine-system-api'
|
|
7
|
+
import { Authorizator, ExecutionContainerFactory, GraphQlSchemaBuilderFactory } from '@contember/engine-content-api'
|
|
8
|
+
import { AllowAllPermissionFactory } from '@contember/schema-utils'
|
|
9
|
+
import { graphql, GraphQLError } from 'graphql'
|
|
10
|
+
import { ExtendedGraphqlContext } from '../content'
|
|
11
|
+
import { extractOriginalError } from '../graphql'
|
|
12
|
+
import { logger } from '@contember/logger'
|
|
13
|
+
|
|
14
|
+
export class ContentQueryExecutorImpl implements ContentQueryExecutor {
|
|
15
|
+
constructor(
|
|
16
|
+
private readonly executionContainerFactory: ExecutionContainerFactory,
|
|
17
|
+
private readonly graphqlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,
|
|
18
|
+
) {
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public async execute({ db, schema, databaseMetadata, stage, project, identity }: ContentQueryExecutorContext, { query, variables }: ContentQueryExecutorQuery): Promise<ContentQueryExecutorResult> {
|
|
22
|
+
const permissions = new AllowAllPermissionFactory().create(schema.model, true)
|
|
23
|
+
const authorizator = new Authorizator(permissions, true)
|
|
24
|
+
const dataSchemaBuilder = this.graphqlSchemaBuilderFactory.create(schema.model, authorizator)
|
|
25
|
+
const dataSchema = dataSchemaBuilder.build()
|
|
26
|
+
|
|
27
|
+
const identityId = identity.id
|
|
28
|
+
|
|
29
|
+
const executionContainer = this.executionContainerFactory.create({
|
|
30
|
+
db: db.client.forSchema(stage.schema),
|
|
31
|
+
identityVariables: {},
|
|
32
|
+
identityId,
|
|
33
|
+
schema,
|
|
34
|
+
schemaDatabaseMetadata: databaseMetadata,
|
|
35
|
+
permissions,
|
|
36
|
+
systemSchema: project.systemSchema,
|
|
37
|
+
stage,
|
|
38
|
+
project: project,
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const ctx: ExtendedGraphqlContext = {
|
|
42
|
+
db: db.client.forSchema(stage.schema),
|
|
43
|
+
identityVariables: {},
|
|
44
|
+
identityId,
|
|
45
|
+
requestDebug: false,
|
|
46
|
+
executionContainer,
|
|
47
|
+
timer: (label, cb) => cb(),
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const result = await graphql({
|
|
52
|
+
schema: dataSchema,
|
|
53
|
+
source: query,
|
|
54
|
+
variableValues: variables,
|
|
55
|
+
contextValue: ctx,
|
|
56
|
+
})
|
|
57
|
+
if (result.errors?.length) {
|
|
58
|
+
return { ok: false, errors: result.errors.map(formatErrorMessage) }
|
|
59
|
+
}
|
|
60
|
+
return { ok: true, result }
|
|
61
|
+
} catch (e) {
|
|
62
|
+
return { ok: false, errors: [formatErrorMessage(e)] }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const formatErrorMessage = (e: any): string => {
|
|
68
|
+
const originalError = extractOriginalError(e)
|
|
69
|
+
if (originalError instanceof GraphQLError) {
|
|
70
|
+
return originalError.message
|
|
71
|
+
}
|
|
72
|
+
const errorDetails = typeof originalError === 'object'
|
|
73
|
+
&& originalError !== null
|
|
74
|
+
&& 'message' in originalError ? `: ${originalError.message}` : ''
|
|
75
|
+
|
|
76
|
+
logger.error(e)
|
|
77
|
+
|
|
78
|
+
return `Internal error${errorDetails}`
|
|
79
|
+
}
|
|
@@ -2,6 +2,7 @@ import { HttpController } from '../application'
|
|
|
2
2
|
import { ProjectContextResolver } from '../project-common'
|
|
3
3
|
import { HttpErrorResponse } from '../common'
|
|
4
4
|
import { SystemGraphQLContextFactory } from './SystemGraphQLContextFactory'
|
|
5
|
+
import { GraphQLKoaState } from '../graphql'
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
export class SystemApiMiddlewareFactory {
|
|
@@ -48,7 +49,6 @@ export class SystemApiMiddlewareFactory {
|
|
|
48
49
|
const graphqlContext = await this.systemGraphqlContextFactory.create({
|
|
49
50
|
authResult,
|
|
50
51
|
memberships,
|
|
51
|
-
koaContext: koa,
|
|
52
52
|
projectContainer,
|
|
53
53
|
systemContainer: projectGroup.systemContainer,
|
|
54
54
|
onClearCache: () => {
|
|
@@ -60,7 +60,13 @@ export class SystemApiMiddlewareFactory {
|
|
|
60
60
|
await timer('GraphQL', () => handler({
|
|
61
61
|
request: koa.request,
|
|
62
62
|
response: koa.response,
|
|
63
|
-
createContext: () =>
|
|
63
|
+
createContext: ({ operation }) => {
|
|
64
|
+
(koa.state as GraphQLKoaState).graphql = {
|
|
65
|
+
operationName: operation,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return graphqlContext
|
|
69
|
+
},
|
|
64
70
|
}))
|
|
65
71
|
logger.debug('System query finished')
|
|
66
72
|
})
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { Identity, SystemContainer } from '@contember/engine-system-api'
|
|
2
2
|
import { SystemGraphQLContext } from './SystemGraphQLHandlerFactory'
|
|
3
3
|
import { AuthResult } from '../common'
|
|
4
|
-
import { KoaContext } from '../application'
|
|
5
|
-
import { GraphQLKoaState } from '../graphql'
|
|
6
4
|
import { Acl } from '@contember/schema'
|
|
7
5
|
import { ProjectContainer } from '../project'
|
|
8
6
|
|
|
9
7
|
export class SystemGraphQLContextFactory {
|
|
10
|
-
public async create({ authResult, memberships,
|
|
8
|
+
public async create({ authResult, memberships, projectContainer, systemContainer, onClearCache }: {
|
|
11
9
|
authResult: AuthResult
|
|
12
10
|
memberships: readonly Acl.Membership[]
|
|
13
|
-
koaContext: KoaContext<GraphQLKoaState>
|
|
14
11
|
projectContainer: ProjectContainer
|
|
15
12
|
systemContainer: SystemContainer
|
|
16
13
|
onClearCache: () => void
|
|
@@ -25,13 +22,12 @@ export class SystemGraphQLContextFactory {
|
|
|
25
22
|
const systemContext = await systemContainer.resolverContextFactory.create(
|
|
26
23
|
schema,
|
|
27
24
|
dbContext,
|
|
28
|
-
projectContainer.project,
|
|
25
|
+
{ ...projectContainer.project, systemSchema: dbContext.client.schema },
|
|
29
26
|
identity,
|
|
30
27
|
)
|
|
31
28
|
return {
|
|
32
29
|
...systemContext,
|
|
33
30
|
onClearCache,
|
|
34
|
-
koaContext,
|
|
35
31
|
}
|
|
36
32
|
}
|
|
37
33
|
}
|
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
import { devTypeDefs, ResolverFactory, SystemResolverContext, typeDefs } from '@contember/engine-system-api'
|
|
2
|
-
import {
|
|
3
|
-
createDbQueriesListener,
|
|
4
|
-
createGraphQLQueryHandler,
|
|
5
|
-
createGraphqlRequestInfoProviderListener,
|
|
6
|
-
GraphQLKoaState,
|
|
7
|
-
GraphQLListener,
|
|
8
|
-
GraphQLQueryHandler,
|
|
9
|
-
} from '../graphql'
|
|
10
|
-
import { KoaContext } from '../application'
|
|
2
|
+
import { createDbQueriesListener, createGraphQLQueryHandler, GraphQLListener, GraphQLQueryHandler } from '../graphql'
|
|
11
3
|
import { DocumentNode } from 'graphql'
|
|
12
4
|
import { mergeTypeDefs } from '@graphql-tools/merge'
|
|
13
5
|
import { makeExecutableSchema } from '@graphql-tools/schema'
|
|
14
6
|
|
|
15
|
-
type KoaState =
|
|
16
|
-
& GraphQLKoaState
|
|
17
|
-
|
|
18
7
|
export type SystemGraphQLContext = SystemResolverContext & {
|
|
19
|
-
koaContext: KoaContext<KoaState>
|
|
20
8
|
onClearCache: () => void
|
|
21
9
|
}
|
|
22
10
|
|
|
@@ -40,9 +28,7 @@ export class SystemGraphQLHandlerFactory {
|
|
|
40
28
|
resolvers,
|
|
41
29
|
})
|
|
42
30
|
|
|
43
|
-
const listeners: GraphQLListener<SystemGraphQLContext>[] = [
|
|
44
|
-
createGraphqlRequestInfoProviderListener(),
|
|
45
|
-
]
|
|
31
|
+
const listeners: GraphQLListener<SystemGraphQLContext>[] = []
|
|
46
32
|
if (this.debugMode) {
|
|
47
33
|
listeners.push({
|
|
48
34
|
onResponse: ({ context }) => {
|
|
@@ -2,6 +2,7 @@ import { HttpController } from '../application'
|
|
|
2
2
|
import { HttpErrorResponse } from '../common'
|
|
3
3
|
import { TenantGraphQLContextFactory } from './TenantGraphQLContextFactory'
|
|
4
4
|
import { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver'
|
|
5
|
+
import { GraphQLKoaState } from '../graphql'
|
|
5
6
|
|
|
6
7
|
export class TenantApiMiddlewareFactory {
|
|
7
8
|
constructor(
|
|
@@ -20,12 +21,16 @@ export class TenantApiMiddlewareFactory {
|
|
|
20
21
|
const tenantContainer = projectGroup.tenantContainer
|
|
21
22
|
await logger.scope(async logger => {
|
|
22
23
|
logger.debug('Tenant query processing started')
|
|
23
|
-
const context = this.tenantGraphQLContextFactory.create({ authResult, tenantContainer, koaContext: koa, logger })
|
|
24
|
-
|
|
25
24
|
await timer('GraphQL', () => projectGroup.tenantGraphQLHandler({
|
|
26
25
|
request: koa.request,
|
|
27
26
|
response: koa.response,
|
|
28
|
-
createContext: () =>
|
|
27
|
+
createContext: ({ operation }) => {
|
|
28
|
+
(koa.state as GraphQLKoaState).graphql = {
|
|
29
|
+
operationName: operation,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return this.tenantGraphQLContextFactory.create({ authResult, tenantContainer, logger })
|
|
33
|
+
},
|
|
29
34
|
}))
|
|
30
35
|
logger.debug('Tenant query finished')
|
|
31
36
|
})
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { TenantGraphQLContext } from './TenantGraphQLHandlerFactory'
|
|
2
2
|
import { AuthResult } from '../common'
|
|
3
3
|
import { TenantContainer } from '@contember/engine-tenant-api'
|
|
4
|
-
import { KoaContext } from '../application'
|
|
5
|
-
import { GraphQLKoaState } from '../graphql'
|
|
6
4
|
import { Logger } from '@contember/logger'
|
|
7
5
|
|
|
8
6
|
export class TenantGraphQLContextFactory {
|
|
9
|
-
public create({ authResult, tenantContainer,
|
|
7
|
+
public create({ authResult, tenantContainer, logger }: {
|
|
10
8
|
tenantContainer: TenantContainer
|
|
11
9
|
authResult: AuthResult
|
|
12
|
-
koaContext: KoaContext<GraphQLKoaState>
|
|
13
10
|
logger: Logger
|
|
14
11
|
}): TenantGraphQLContext {
|
|
15
12
|
const resolverContextFactory = tenantContainer.resolverContextFactory
|
|
@@ -22,7 +19,6 @@ export class TenantGraphQLContextFactory {
|
|
|
22
19
|
return {
|
|
23
20
|
...context,
|
|
24
21
|
identityId: authResult.identityId,
|
|
25
|
-
koaContext,
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
24
|
}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { makeExecutableSchema } from '@graphql-tools/schema'
|
|
2
2
|
import { Schema, TenantResolverContext, typeDefs } from '@contember/engine-tenant-api'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
createGraphQLQueryHandler,
|
|
6
|
-
createGraphqlRequestInfoProviderListener,
|
|
7
|
-
GraphQLKoaState,
|
|
8
|
-
GraphQLQueryHandler,
|
|
9
|
-
} from '../graphql'
|
|
3
|
+
import { createGraphQLQueryHandler, GraphQLQueryHandler } from '../graphql'
|
|
10
4
|
|
|
11
|
-
export type TenantGraphQLContext = TenantResolverContext & { identityId: string
|
|
5
|
+
export type TenantGraphQLContext = TenantResolverContext & { identityId: string }
|
|
12
6
|
|
|
13
7
|
export type TenantGraphQLHandler = GraphQLQueryHandler<TenantGraphQLContext>
|
|
14
8
|
|
|
@@ -24,9 +18,7 @@ export class TenantGraphQLHandlerFactory {
|
|
|
24
18
|
})
|
|
25
19
|
return createGraphQLQueryHandler<TenantGraphQLContext>({
|
|
26
20
|
schema,
|
|
27
|
-
listeners: [
|
|
28
|
-
createGraphqlRequestInfoProviderListener(),
|
|
29
|
-
],
|
|
21
|
+
listeners: [],
|
|
30
22
|
})
|
|
31
23
|
}
|
|
32
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client, Connection, ConstraintHelper, wrapIdentifier } from '@contember/database'
|
|
1
|
+
import { Client, Connection, ConstraintHelper, DatabaseMetadataResolver, wrapIdentifier } from '@contember/database'
|
|
2
2
|
import { Model, Schema } from '@contember/schema'
|
|
3
3
|
import * as Typesafe from '@contember/typesafe'
|
|
4
4
|
import { ParseError } from '@contember/typesafe'
|
|
@@ -64,6 +64,7 @@ export class ImportExecutor {
|
|
|
64
64
|
constructor(
|
|
65
65
|
private readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,
|
|
66
66
|
private readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,
|
|
67
|
+
private readonly databaseMetadataResolver: DatabaseMetadataResolver,
|
|
67
68
|
) {
|
|
68
69
|
}
|
|
69
70
|
|
|
@@ -118,7 +119,7 @@ export class ImportExecutor {
|
|
|
118
119
|
await this.lockTables(db, options.tables)
|
|
119
120
|
await this.truncateTables(db, options.tables)
|
|
120
121
|
|
|
121
|
-
const metadata = await
|
|
122
|
+
const metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)
|
|
122
123
|
const constraintHelper = new ConstraintHelper(db, metadata)
|
|
123
124
|
await constraintHelper.setConstraintsDeferred('foreignKey')
|
|
124
125
|
|
|
@@ -150,7 +151,7 @@ export class ImportExecutor {
|
|
|
150
151
|
return await systemDatabaseContext.client.transaction(async db => {
|
|
151
152
|
await this.truncateTables(db, options.tables)
|
|
152
153
|
|
|
153
|
-
const metadata = await
|
|
154
|
+
const metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)
|
|
154
155
|
const constraintHelper = new ConstraintHelper(db, metadata)
|
|
155
156
|
await constraintHelper.setConstraintsDeferred('foreignKey')
|
|
156
157
|
|