@contember/engine-http 2.0.0-alpha.35 → 2.0.0-alpha.37
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/development/src/MasterContainer.cjs +14 -3
- package/dist/development/src/MasterContainer.cjs.map +1 -1
- package/dist/development/src/MasterContainer.js +14 -3
- package/dist/development/src/MasterContainer.js.map +1 -1
- package/dist/development/src/content/ContentApiControllerFactory.cjs +4 -3
- package/dist/development/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/development/src/content/ContentApiControllerFactory.js +4 -3
- package/dist/development/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/development/src/content/ContentGraphQLContextFactory.cjs +2 -1
- package/dist/development/src/content/ContentGraphQLContextFactory.cjs.map +1 -1
- package/dist/development/src/content/ContentGraphQLContextFactory.js +2 -1
- package/dist/development/src/content/ContentGraphQLContextFactory.js.map +1 -1
- package/dist/development/src/content/ContentSchemaResolver.cjs +10 -4
- package/dist/development/src/content/ContentSchemaResolver.cjs.map +1 -1
- package/dist/development/src/content/ContentSchemaResolver.js +11 -5
- package/dist/development/src/content/ContentSchemaResolver.js.map +1 -1
- package/dist/development/src/content/GraphQlSchemaFactory.cjs +5 -3
- package/dist/development/src/content/GraphQlSchemaFactory.cjs.map +1 -1
- package/dist/development/src/content/GraphQlSchemaFactory.js +5 -3
- package/dist/development/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/development/src/project/ProjectContainer.cjs +2 -24
- package/dist/development/src/project/ProjectContainer.cjs.map +1 -1
- package/dist/development/src/project/ProjectContainer.js +2 -24
- package/dist/development/src/project/ProjectContainer.js.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs +0 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.js +0 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/development/src/system/ContentQueryExecutor.cjs +1 -0
- package/dist/development/src/system/ContentQueryExecutor.cjs.map +1 -1
- package/dist/development/src/system/ContentQueryExecutor.js +1 -0
- package/dist/development/src/system/ContentQueryExecutor.js.map +1 -1
- package/dist/development/src/utils/memoizeObject.cjs +33 -0
- package/dist/development/src/utils/memoizeObject.cjs.map +1 -0
- package/dist/development/src/utils/memoizeObject.js +33 -0
- package/dist/development/src/utils/memoizeObject.js.map +1 -0
- package/dist/production/src/MasterContainer.cjs +14 -3
- package/dist/production/src/MasterContainer.cjs.map +1 -1
- package/dist/production/src/MasterContainer.js +14 -3
- package/dist/production/src/MasterContainer.js.map +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.cjs +4 -3
- package/dist/production/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.js +4 -3
- package/dist/production/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/production/src/content/ContentGraphQLContextFactory.cjs +2 -1
- package/dist/production/src/content/ContentGraphQLContextFactory.cjs.map +1 -1
- package/dist/production/src/content/ContentGraphQLContextFactory.js +2 -1
- package/dist/production/src/content/ContentGraphQLContextFactory.js.map +1 -1
- package/dist/production/src/content/ContentSchemaResolver.cjs +10 -4
- package/dist/production/src/content/ContentSchemaResolver.cjs.map +1 -1
- package/dist/production/src/content/ContentSchemaResolver.js +11 -5
- package/dist/production/src/content/ContentSchemaResolver.js.map +1 -1
- package/dist/production/src/content/GraphQlSchemaFactory.cjs +5 -3
- package/dist/production/src/content/GraphQlSchemaFactory.cjs.map +1 -1
- package/dist/production/src/content/GraphQlSchemaFactory.js +5 -3
- package/dist/production/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/production/src/project/ProjectContainer.cjs +2 -24
- package/dist/production/src/project/ProjectContainer.cjs.map +1 -1
- package/dist/production/src/project/ProjectContainer.js +2 -24
- package/dist/production/src/project/ProjectContainer.js.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs +0 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.js +0 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/production/src/system/ContentQueryExecutor.cjs +1 -0
- package/dist/production/src/system/ContentQueryExecutor.cjs.map +1 -1
- package/dist/production/src/system/ContentQueryExecutor.js +1 -0
- package/dist/production/src/system/ContentQueryExecutor.js.map +1 -1
- package/dist/production/src/utils/memoizeObject.cjs +33 -0
- package/dist/production/src/utils/memoizeObject.cjs.map +1 -0
- package/dist/production/src/utils/memoizeObject.js +33 -0
- package/dist/production/src/utils/memoizeObject.js.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/MasterContainer.d.ts +7 -1
- package/dist/types/MasterContainer.d.ts.map +1 -1
- package/dist/types/content/ContentApiControllerFactory.d.ts +3 -1
- package/dist/types/content/ContentApiControllerFactory.d.ts.map +1 -1
- package/dist/types/content/ContentGraphQLContextFactory.d.ts +3 -0
- package/dist/types/content/ContentGraphQLContextFactory.d.ts.map +1 -1
- package/dist/types/content/ContentSchemaResolver.d.ts.map +1 -1
- package/dist/types/content/GraphQLSchemaContributor.d.ts +3 -0
- package/dist/types/content/GraphQLSchemaContributor.d.ts.map +1 -1
- package/dist/types/content/GraphQlSchemaFactory.d.ts +2 -1
- package/dist/types/content/GraphQlSchemaFactory.d.ts.map +1 -1
- package/dist/types/plugin/Plugin.d.ts +2 -4
- package/dist/types/plugin/Plugin.d.ts.map +1 -1
- package/dist/types/project/ProjectContainer.d.ts +4 -19
- package/dist/types/project/ProjectContainer.d.ts.map +1 -1
- package/dist/types/system/ContentQueryExecutor.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/memoizeObject.d.ts +2 -0
- package/dist/types/utils/memoizeObject.d.ts.map +1 -0
- package/package.json +15 -15
- package/src/MasterContainer.ts +26 -5
- package/src/content/ContentApiControllerFactory.ts +4 -2
- package/src/content/ContentGraphQLContextFactory.ts +2 -0
- package/src/content/ContentSchemaResolver.ts +13 -5
- package/src/content/GraphQLSchemaContributor.ts +7 -1
- package/src/content/GraphQlSchemaFactory.ts +6 -3
- package/src/plugin/Plugin.ts +2 -4
- package/src/project/ProjectContainer.ts +3 -30
- package/src/system/ContentQueryExecutor.ts +1 -0
- package/src/utils/memoizeObject.ts +38 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoizeObject.d.ts","sourceRoot":"","sources":["../../../src/utils/memoizeObject.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,qBAAqB,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,aAQxE,CAAC,KAAG,CA4BnB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-http",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.37",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/production/index.js",
|
|
6
6
|
"typings": "./dist/types/index.d.ts",
|
|
@@ -26,20 +26,20 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@contember/config-loader": "2.0.0-alpha.
|
|
30
|
-
"@contember/database": "2.0.0-alpha.
|
|
31
|
-
"@contember/database-migrations": "2.0.0-alpha.
|
|
32
|
-
"@contember/dic": "2.0.0-alpha.
|
|
33
|
-
"@contember/engine-common": "2.0.0-alpha.
|
|
34
|
-
"@contember/engine-content-api": "2.0.0-alpha.
|
|
35
|
-
"@contember/engine-system-api": "2.0.0-alpha.
|
|
36
|
-
"@contember/engine-tenant-api": "2.0.0-alpha.
|
|
37
|
-
"@contember/graphql-utils": "2.0.0-alpha.
|
|
38
|
-
"@contember/logger": "2.0.0-alpha.
|
|
39
|
-
"@contember/schema": "2.0.0-alpha.
|
|
40
|
-
"@contember/schema-migrations": "2.0.0-alpha.
|
|
41
|
-
"@contember/schema-utils": "2.0.0-alpha.
|
|
42
|
-
"@contember/typesafe": "2.0.0-alpha.
|
|
29
|
+
"@contember/config-loader": "2.0.0-alpha.37",
|
|
30
|
+
"@contember/database": "2.0.0-alpha.37",
|
|
31
|
+
"@contember/database-migrations": "2.0.0-alpha.37",
|
|
32
|
+
"@contember/dic": "2.0.0-alpha.37",
|
|
33
|
+
"@contember/engine-common": "2.0.0-alpha.37",
|
|
34
|
+
"@contember/engine-content-api": "2.0.0-alpha.37",
|
|
35
|
+
"@contember/engine-system-api": "2.0.0-alpha.37",
|
|
36
|
+
"@contember/engine-tenant-api": "2.0.0-alpha.37",
|
|
37
|
+
"@contember/graphql-utils": "2.0.0-alpha.37",
|
|
38
|
+
"@contember/logger": "2.0.0-alpha.37",
|
|
39
|
+
"@contember/schema": "2.0.0-alpha.37",
|
|
40
|
+
"@contember/schema-migrations": "2.0.0-alpha.37",
|
|
41
|
+
"@contember/schema-utils": "2.0.0-alpha.37",
|
|
42
|
+
"@contember/typesafe": "2.0.0-alpha.37",
|
|
43
43
|
"@graphql-tools/merge": "^9.0.8",
|
|
44
44
|
"@graphql-tools/schema": "^10.0.7",
|
|
45
45
|
"@koa/cors": "^5.0.0",
|
package/src/MasterContainer.ts
CHANGED
|
@@ -15,7 +15,10 @@ import { ExecutionContainerFactory, GraphQlSchemaBuilderFactory, PermissionFacto
|
|
|
15
15
|
import { createProviders, Providers } from './providers'
|
|
16
16
|
import { TenantApiMiddlewareFactory, TenantGraphQLContextFactory, TenantGraphQLHandlerFactory } from './tenant'
|
|
17
17
|
import { SystemApiMiddlewareFactory, SystemGraphQLContextFactory, SystemGraphQLHandlerFactory } from './system'
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
ContentApiControllerFactory, ContentGraphQLContextFactory, ContentQueryHandlerFactory, GraphQLSchemaContributor, GraphQlSchemaFactory,
|
|
20
|
+
GraphQLSchemaFactoryResult, NotModifiedChecker,
|
|
21
|
+
} from './content'
|
|
19
22
|
import { ProjectContextResolver } from './project-common'
|
|
20
23
|
import {
|
|
21
24
|
ContentSchemaTransferMappingFactory,
|
|
@@ -39,6 +42,8 @@ import { ProjectGroupContainerMetricsHook } from './prometheus/ProjectGroupConta
|
|
|
39
42
|
import { createColllectHttpMetricsMiddleware, createShowMetricsMiddleware } from './prometheus'
|
|
40
43
|
import { createSecretKey } from 'node:crypto'
|
|
41
44
|
import { CryptoWrapper } from './utils/CryptoWrapper'
|
|
45
|
+
import { ContentApiSpecificCache } from './content/ContentApiSpecificCache'
|
|
46
|
+
import { Schema } from '@contember/schema'
|
|
42
47
|
|
|
43
48
|
export type ProcessType =
|
|
44
49
|
| 'singleNode'
|
|
@@ -120,8 +125,24 @@ export class MasterContainerFactory {
|
|
|
120
125
|
new PermissionFactory())
|
|
121
126
|
.addService('databaseMetadataResolver', () =>
|
|
122
127
|
new DatabaseMetadataResolver())
|
|
123
|
-
.addService('
|
|
124
|
-
new
|
|
128
|
+
.addService('graphqlSchemaCache', ({ serverConfig }) =>
|
|
129
|
+
new ContentApiSpecificCache<Schema, GraphQLSchemaFactoryResult>({
|
|
130
|
+
ttlSeconds: serverConfig.contentApi?.schemaCacheTtlSeconds,
|
|
131
|
+
}))
|
|
132
|
+
.addService('graphQlSchemaFactory', ({ plugins, providers, graphqlSchemaCache, contentPermissionFactory, graphQlSchemaBuilderFactory }) => {
|
|
133
|
+
const contributors = plugins
|
|
134
|
+
.map(it => (it.getSchemaContributor ? it.getSchemaContributor({ providers }) : null))
|
|
135
|
+
.filter((it): it is GraphQLSchemaContributor => !!it)
|
|
136
|
+
|
|
137
|
+
return new GraphQlSchemaFactory(
|
|
138
|
+
graphqlSchemaCache,
|
|
139
|
+
graphQlSchemaBuilderFactory,
|
|
140
|
+
contentPermissionFactory,
|
|
141
|
+
contributors,
|
|
142
|
+
)
|
|
143
|
+
})
|
|
144
|
+
.addService('projectContainerFactoryFactory', ({ plugins, providers, databaseMetadataResolver }) =>
|
|
145
|
+
new ProjectContainerFactoryFactory(plugins, providers, databaseMetadataResolver))
|
|
125
146
|
.addService('tenantGraphQLHandlerFactory', () =>
|
|
126
147
|
new TenantGraphQLHandlerFactory())
|
|
127
148
|
.addService('systemGraphQLHandlerFactory', ({ debugMode }) =>
|
|
@@ -163,8 +184,8 @@ export class MasterContainerFactory {
|
|
|
163
184
|
new ContentQueryHandlerFactory(debugMode))
|
|
164
185
|
.addService('projectContextResolver', () =>
|
|
165
186
|
new ProjectContextResolver())
|
|
166
|
-
.addService('contentApiMiddlewareFactory', ({ projectContextResolver, notModifiedChecker, contentGraphqlContextFactory, contentQueryHandlerFactory }) =>
|
|
167
|
-
new ContentApiControllerFactory(notModifiedChecker, contentGraphqlContextFactory, contentQueryHandlerFactory, projectContextResolver))
|
|
187
|
+
.addService('contentApiMiddlewareFactory', ({ projectContextResolver, notModifiedChecker, contentGraphqlContextFactory, contentQueryHandlerFactory, graphQlSchemaFactory }) =>
|
|
188
|
+
new ContentApiControllerFactory(notModifiedChecker, contentGraphqlContextFactory, contentQueryHandlerFactory, projectContextResolver, graphQlSchemaFactory))
|
|
168
189
|
.addService('tenantGraphQLContextFactory', () =>
|
|
169
190
|
new TenantGraphQLContextFactory())
|
|
170
191
|
.addService('tenantApiMiddlewareFactory', ({ debugMode, projectGroupResolver, tenantGraphQLContextFactory }) =>
|
|
@@ -7,6 +7,7 @@ import { ContentGraphQLContextFactory } from './ContentGraphQLContextFactory'
|
|
|
7
7
|
import { ContentQueryHandler, ContentQueryHandlerFactory } from './ContentQueryHandlerFactory'
|
|
8
8
|
import { GraphQLSchema } from 'graphql'
|
|
9
9
|
import { GraphQLKoaState } from '../graphql'
|
|
10
|
+
import { GraphQlSchemaFactory } from './GraphQlSchemaFactory'
|
|
10
11
|
|
|
11
12
|
const debugHeader = 'x-contember-debug'
|
|
12
13
|
|
|
@@ -16,6 +17,7 @@ export class ContentApiControllerFactory {
|
|
|
16
17
|
private readonly contentGraphqlContextFactory: ContentGraphQLContextFactory,
|
|
17
18
|
private readonly handlerFactory: ContentQueryHandlerFactory,
|
|
18
19
|
private readonly projectContextResolver: ProjectContextResolver,
|
|
20
|
+
private readonly graphQlSchemaFactory: GraphQlSchemaFactory,
|
|
19
21
|
) {
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -79,9 +81,9 @@ export class ContentApiControllerFactory {
|
|
|
79
81
|
|
|
80
82
|
const { schema: graphQlSchema, permissions } = await timer(
|
|
81
83
|
'GraphQLSchemaCreate',
|
|
82
|
-
() =>
|
|
84
|
+
() => this.graphQlSchemaFactory.create(schema, {
|
|
83
85
|
projectRoles: projectRoles,
|
|
84
|
-
}),
|
|
86
|
+
}, project),
|
|
85
87
|
)
|
|
86
88
|
|
|
87
89
|
|
|
@@ -11,6 +11,7 @@ import { ProjectConfig } from '../project/config'
|
|
|
11
11
|
export type ExtendedGraphqlContext = Context & {
|
|
12
12
|
identityId: string
|
|
13
13
|
requestDebug: boolean
|
|
14
|
+
project: { slug: string }
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export class ContentGraphQLContextFactory {
|
|
@@ -63,6 +64,7 @@ export class ContentGraphQLContextFactory {
|
|
|
63
64
|
executionContainer,
|
|
64
65
|
timer,
|
|
65
66
|
requestDebug,
|
|
67
|
+
project,
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { DatabaseContext, SchemaProvider, SchemaWithMeta } from '@contember/engine-system-api'
|
|
2
|
-
import { filterSchemaByStage, normalizeSchema } from '@contember/schema-utils'
|
|
2
|
+
import { calculateSchemaChecksum, filterSchemaByStage, normalizeSchema } from '@contember/schema-utils'
|
|
3
3
|
import { Schema } from '@contember/schema'
|
|
4
4
|
import { ContentApiSpecificCache } from './ContentApiSpecificCache'
|
|
5
|
+
import { createMemoizer } from '../utils/memoizeObject'
|
|
6
|
+
|
|
7
|
+
const memoizedSchema = createMemoizer(calculateSchemaChecksum)
|
|
5
8
|
|
|
6
9
|
export class ContentSchemaResolver {
|
|
7
10
|
private baseSchemaCache: SchemaWithMeta | null = null
|
|
@@ -19,7 +22,11 @@ export class ContentSchemaResolver {
|
|
|
19
22
|
stage?: string
|
|
20
23
|
}): Promise<SchemaWithMeta> {
|
|
21
24
|
const prevBaseSchema = this.baseSchemaCache
|
|
22
|
-
|
|
25
|
+
const { schema, meta } = await this.schemaProvider.fetch({ db, currentSchema: prevBaseSchema })
|
|
26
|
+
this.baseSchemaCache = {
|
|
27
|
+
schema: memoizedSchema(schema),
|
|
28
|
+
meta: meta,
|
|
29
|
+
}
|
|
23
30
|
const finalSchema = getSchema(this.baseSchemaCache.schema, { stage, normalize })
|
|
24
31
|
return {
|
|
25
32
|
schema: finalSchema,
|
|
@@ -32,13 +39,14 @@ const cache = new ContentApiSpecificCache<Schema, Schema>({})
|
|
|
32
39
|
const getSchema = (schema: Schema, options: { stage?: string; normalize?: boolean }) => {
|
|
33
40
|
const cacheKey = [options.stage, options.normalize].join('\xff')
|
|
34
41
|
return cache.fetch(schema, cacheKey, () => {
|
|
35
|
-
|
|
42
|
+
let result = schema
|
|
36
43
|
if (options.normalize) {
|
|
37
|
-
|
|
44
|
+
result = normalizeSchema(result)
|
|
38
45
|
}
|
|
39
46
|
if (options.stage) {
|
|
40
|
-
|
|
47
|
+
result = filterSchemaByStage(result, options.stage)
|
|
41
48
|
}
|
|
42
49
|
return result
|
|
43
50
|
})
|
|
44
51
|
}
|
|
52
|
+
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { Schema } from '@contember/schema'
|
|
2
2
|
import { GraphQLSchema, GraphQLSchemaConfig } from 'graphql'
|
|
3
3
|
import { Identity } from './Identity'
|
|
4
|
+
import { ProjectConfig } from '../project/config'
|
|
4
5
|
|
|
5
|
-
export type GraphQLSchemaContributorContext = {
|
|
6
|
+
export type GraphQLSchemaContributorContext = {
|
|
7
|
+
schema: Schema
|
|
8
|
+
identity: Identity
|
|
9
|
+
project: ProjectConfig
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
export interface GraphQLSchemaContributor {
|
|
13
|
+
getCacheKey?: (context: GraphQLSchemaContributorContext) => string
|
|
8
14
|
createSchema(context: GraphQLSchemaContributorContext): undefined | GraphQLSchema | GraphQLSchemaConfig
|
|
9
15
|
}
|
|
@@ -12,6 +12,7 @@ import { GraphQLFieldConfig, GraphQLNamedType, GraphQLSchema } from 'graphql'
|
|
|
12
12
|
import { GraphQLSchemaContributor } from './GraphQLSchemaContributor'
|
|
13
13
|
import { Identity } from './Identity'
|
|
14
14
|
import { ContentApiSpecificCache } from './ContentApiSpecificCache'
|
|
15
|
+
import { ProjectConfig } from '../project/config'
|
|
15
16
|
|
|
16
17
|
export interface GraphQLSchemaFactoryResult {
|
|
17
18
|
permissions: Acl.Permissions
|
|
@@ -27,10 +28,12 @@ export class GraphQlSchemaFactory {
|
|
|
27
28
|
private readonly schemaContributors: GraphQLSchemaContributor[],
|
|
28
29
|
) {}
|
|
29
30
|
|
|
30
|
-
public create(schema: Schema, identity: Identity): GraphQLSchemaFactoryResult {
|
|
31
|
+
public create(schema: Schema, identity: Identity, project: ProjectConfig): GraphQLSchemaFactoryResult {
|
|
31
32
|
const rolesKey = [...identity.projectRoles].sort().join('\xff')
|
|
33
|
+
const contributorsKey = this.schemaContributors.map(it => it.getCacheKey?.({ schema, identity, project }) ?? '').join('\xff')
|
|
34
|
+
const cacheKey = `${rolesKey}\xff\xff${contributorsKey}`
|
|
32
35
|
|
|
33
|
-
return this.cache.fetch(schema,
|
|
36
|
+
return this.cache.fetch(schema, cacheKey, () => {
|
|
34
37
|
const permissions = this.permissionFactory.create(schema, identity.projectRoles)
|
|
35
38
|
|
|
36
39
|
const authorizator = new Authorizator(permissions, schema.acl.customPrimary ?? false)
|
|
@@ -45,7 +48,7 @@ export class GraphQlSchemaFactory {
|
|
|
45
48
|
const introspectionSchema = introspectionSchemaFactory.createConfig()
|
|
46
49
|
|
|
47
50
|
const otherSchemas = this.schemaContributors
|
|
48
|
-
.map(it => it.createSchema({ schema, identity }))
|
|
51
|
+
.map(it => it.createSchema({ schema, identity, project }))
|
|
49
52
|
.filter(<T>(it: T | undefined): it is T => it !== undefined)
|
|
50
53
|
|
|
51
54
|
const queries = new Map<string, GraphQLFieldConfig<any, Context, any>>()
|
package/src/plugin/Plugin.ts
CHANGED
|
@@ -4,11 +4,9 @@ import { ConfigProcessor } from '../config/ConfigProcessor'
|
|
|
4
4
|
import * as Typesafe from '@contember/typesafe'
|
|
5
5
|
import { GraphQLSchemaContributor } from '../content'
|
|
6
6
|
import { Providers } from '../providers'
|
|
7
|
-
import { ProjectConfig } from '../project/config'
|
|
8
7
|
import { MasterContainerHook } from '../MasterContainer'
|
|
9
8
|
|
|
10
|
-
export interface SchemaContributorArgs
|
|
11
|
-
project: ProjectConfig & CustomConfig
|
|
9
|
+
export interface SchemaContributorArgs {
|
|
12
10
|
providers: Providers
|
|
13
11
|
}
|
|
14
12
|
|
|
@@ -17,7 +15,7 @@ export interface Plugin<CustomConfig extends Typesafe.JsonObject = Typesafe.Json
|
|
|
17
15
|
|
|
18
16
|
getConfigProcessor?(): ConfigProcessor<CustomConfig>
|
|
19
17
|
|
|
20
|
-
getSchemaContributor?(args: SchemaContributorArgs
|
|
18
|
+
getSchemaContributor?(args: SchemaContributorArgs): GraphQLSchemaContributor | undefined
|
|
21
19
|
|
|
22
20
|
getSystemMigrations?(): MigrationGroup<unknown>
|
|
23
21
|
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { Builder } from '@contember/dic'
|
|
2
2
|
import { Connection, DatabaseMetadataResolver } from '@contember/database'
|
|
3
3
|
import {
|
|
4
|
+
DatabaseContext,
|
|
4
5
|
DatabaseContextFactory,
|
|
5
6
|
ProjectInitializer,
|
|
6
7
|
SchemaProvider,
|
|
7
8
|
StageCreator,
|
|
8
9
|
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'
|
|
13
13
|
import { ProjectConfig } from './config'
|
|
14
|
-
import { ContentSchemaResolver
|
|
14
|
+
import { ContentSchemaResolver } from '../content'
|
|
15
15
|
import { Providers } from '../providers'
|
|
16
16
|
import { Plugin } from '../plugin/Plugin'
|
|
17
17
|
import { ServerConfig } from '../config/config'
|
|
18
|
-
import { ContentApiSpecificCache } from '../content/ContentApiSpecificCache'
|
|
19
|
-
import { Schema } from '@contember/schema'
|
|
20
18
|
import { ProjectDatabaseMetadataResolver } from './ProjectDatabaseMetadataResolver'
|
|
21
19
|
|
|
22
20
|
export interface ProjectContainer {
|
|
@@ -27,7 +25,6 @@ export interface ProjectContainer {
|
|
|
27
25
|
logger: Logger
|
|
28
26
|
connection: Connection
|
|
29
27
|
readConnection: Connection
|
|
30
|
-
graphQlSchemaFactory: GraphQlSchemaFactory
|
|
31
28
|
contentSchemaResolver: ContentSchemaResolver
|
|
32
29
|
projectInitializer: ProjectInitializer
|
|
33
30
|
projectDatabaseMetadataResolver: ProjectDatabaseMetadataResolver
|
|
@@ -37,9 +34,6 @@ export class ProjectContainerFactoryFactory {
|
|
|
37
34
|
constructor(
|
|
38
35
|
private readonly plugins: Plugin[],
|
|
39
36
|
private readonly providers: Providers,
|
|
40
|
-
private readonly serverConfig: ServerConfig,
|
|
41
|
-
private readonly graphQlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,
|
|
42
|
-
private readonly permissionFactory: PermissionFactory,
|
|
43
37
|
private readonly databaseMetadataResolver: DatabaseMetadataResolver,
|
|
44
38
|
) {
|
|
45
39
|
}
|
|
@@ -50,9 +44,6 @@ export class ProjectContainerFactoryFactory {
|
|
|
50
44
|
schemaProvider,
|
|
51
45
|
this.providers,
|
|
52
46
|
logger,
|
|
53
|
-
this.serverConfig,
|
|
54
|
-
this.graphQlSchemaBuilderFactory,
|
|
55
|
-
this.permissionFactory,
|
|
56
47
|
this.databaseMetadataResolver,
|
|
57
48
|
)
|
|
58
49
|
}
|
|
@@ -68,9 +59,6 @@ export class ProjectContainerFactory {
|
|
|
68
59
|
private readonly schemaProvider: SchemaProvider,
|
|
69
60
|
private readonly providers: Providers,
|
|
70
61
|
private readonly logger: Logger,
|
|
71
|
-
private readonly serverConfig: ServerConfig,
|
|
72
|
-
private readonly graphQlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,
|
|
73
|
-
private readonly permissionFactory: PermissionFactory,
|
|
74
62
|
private readonly databaseMetadataResolver: DatabaseMetadataResolver,
|
|
75
63
|
) {}
|
|
76
64
|
|
|
@@ -85,7 +73,6 @@ export class ProjectContainerFactory {
|
|
|
85
73
|
'systemDatabaseContext',
|
|
86
74
|
'systemReadDatabaseContext',
|
|
87
75
|
'contentSchemaResolver',
|
|
88
|
-
'graphQlSchemaFactory',
|
|
89
76
|
'projectInitializer',
|
|
90
77
|
'logger',
|
|
91
78
|
'projectDatabaseMetadataResolver',
|
|
@@ -114,21 +101,7 @@ export class ProjectContainerFactory {
|
|
|
114
101
|
}, err => logger.error(err))
|
|
115
102
|
})
|
|
116
103
|
|
|
117
|
-
|
|
118
|
-
new ContentApiSpecificCache<Schema, GraphQLSchemaFactoryResult>({
|
|
119
|
-
ttlSeconds: this.serverConfig.contentApi?.schemaCacheTtlSeconds,
|
|
120
|
-
}))
|
|
121
|
-
.addService('graphQlSchemaFactory', ({ project, graphqlSchemaCache }) => {
|
|
122
|
-
const contributors = this.plugins
|
|
123
|
-
.map(it => (it.getSchemaContributor ? it.getSchemaContributor({ project, providers: this.providers }) : null))
|
|
124
|
-
.filter((it): it is GraphQLSchemaContributor => !!it)
|
|
125
|
-
return new GraphQlSchemaFactory(
|
|
126
|
-
graphqlSchemaCache,
|
|
127
|
-
this.graphQlSchemaBuilderFactory,
|
|
128
|
-
this.permissionFactory,
|
|
129
|
-
contributors,
|
|
130
|
-
)
|
|
131
|
-
})
|
|
104
|
+
|
|
132
105
|
.addService('contentSchemaResolver', () =>
|
|
133
106
|
new ContentSchemaResolver(this.schemaProvider))
|
|
134
107
|
.addService('systemSchemaName', ({ project }) =>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
export const createMemoizer = <T extends object>(canonicalizeValue: (value: T) => string) => {
|
|
3
|
+
const cache = new Map<string, WeakRef<T>>()
|
|
4
|
+
const canonicalValueCache = new WeakMap<T, string>()
|
|
5
|
+
|
|
6
|
+
const finalizer = new FinalizationRegistry<string>(key => {
|
|
7
|
+
cache.delete(key)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
return (value: T): T => {
|
|
11
|
+
if (typeof value !== 'object' || value === null) {
|
|
12
|
+
throw new TypeError('Value must be a non-null object')
|
|
13
|
+
}
|
|
14
|
+
let key = canonicalValueCache.get(value)
|
|
15
|
+
if (!key) {
|
|
16
|
+
key = canonicalizeValue(value)
|
|
17
|
+
canonicalValueCache.set(value, key)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const entry = cache.get(key)
|
|
21
|
+
if (entry) {
|
|
22
|
+
const obj = entry.deref()
|
|
23
|
+
if (obj !== undefined) {
|
|
24
|
+
return obj as T
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const stableObj = value
|
|
29
|
+
const weakRef = new WeakRef(stableObj)
|
|
30
|
+
|
|
31
|
+
finalizer.register(stableObj, key)
|
|
32
|
+
|
|
33
|
+
cache.set(key, weakRef)
|
|
34
|
+
|
|
35
|
+
return stableObj
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|