@contember/engine-http 2.0.0-alpha.36 → 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.
Files changed (103) hide show
  1. package/dist/development/src/MasterContainer.cjs +14 -3
  2. package/dist/development/src/MasterContainer.cjs.map +1 -1
  3. package/dist/development/src/MasterContainer.js +14 -3
  4. package/dist/development/src/MasterContainer.js.map +1 -1
  5. package/dist/development/src/content/ContentApiControllerFactory.cjs +4 -3
  6. package/dist/development/src/content/ContentApiControllerFactory.cjs.map +1 -1
  7. package/dist/development/src/content/ContentApiControllerFactory.js +4 -3
  8. package/dist/development/src/content/ContentApiControllerFactory.js.map +1 -1
  9. package/dist/development/src/content/ContentGraphQLContextFactory.cjs +2 -1
  10. package/dist/development/src/content/ContentGraphQLContextFactory.cjs.map +1 -1
  11. package/dist/development/src/content/ContentGraphQLContextFactory.js +2 -1
  12. package/dist/development/src/content/ContentGraphQLContextFactory.js.map +1 -1
  13. package/dist/development/src/content/ContentSchemaResolver.cjs +7 -1
  14. package/dist/development/src/content/ContentSchemaResolver.cjs.map +1 -1
  15. package/dist/development/src/content/ContentSchemaResolver.js +8 -2
  16. package/dist/development/src/content/ContentSchemaResolver.js.map +1 -1
  17. package/dist/development/src/content/GraphQlSchemaFactory.cjs +5 -3
  18. package/dist/development/src/content/GraphQlSchemaFactory.cjs.map +1 -1
  19. package/dist/development/src/content/GraphQlSchemaFactory.js +5 -3
  20. package/dist/development/src/content/GraphQlSchemaFactory.js.map +1 -1
  21. package/dist/development/src/project/ProjectContainer.cjs +2 -24
  22. package/dist/development/src/project/ProjectContainer.cjs.map +1 -1
  23. package/dist/development/src/project/ProjectContainer.js +2 -24
  24. package/dist/development/src/project/ProjectContainer.js.map +1 -1
  25. package/dist/development/src/projectGroup/ProjectGroupContainer.cjs +0 -1
  26. package/dist/development/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
  27. package/dist/development/src/projectGroup/ProjectGroupContainer.js +0 -1
  28. package/dist/development/src/projectGroup/ProjectGroupContainer.js.map +1 -1
  29. package/dist/development/src/system/ContentQueryExecutor.cjs +1 -0
  30. package/dist/development/src/system/ContentQueryExecutor.cjs.map +1 -1
  31. package/dist/development/src/system/ContentQueryExecutor.js +1 -0
  32. package/dist/development/src/system/ContentQueryExecutor.js.map +1 -1
  33. package/dist/development/src/utils/memoizeObject.cjs +33 -0
  34. package/dist/development/src/utils/memoizeObject.cjs.map +1 -0
  35. package/dist/development/src/utils/memoizeObject.js +33 -0
  36. package/dist/development/src/utils/memoizeObject.js.map +1 -0
  37. package/dist/production/src/MasterContainer.cjs +14 -3
  38. package/dist/production/src/MasterContainer.cjs.map +1 -1
  39. package/dist/production/src/MasterContainer.js +14 -3
  40. package/dist/production/src/MasterContainer.js.map +1 -1
  41. package/dist/production/src/content/ContentApiControllerFactory.cjs +4 -3
  42. package/dist/production/src/content/ContentApiControllerFactory.cjs.map +1 -1
  43. package/dist/production/src/content/ContentApiControllerFactory.js +4 -3
  44. package/dist/production/src/content/ContentApiControllerFactory.js.map +1 -1
  45. package/dist/production/src/content/ContentGraphQLContextFactory.cjs +2 -1
  46. package/dist/production/src/content/ContentGraphQLContextFactory.cjs.map +1 -1
  47. package/dist/production/src/content/ContentGraphQLContextFactory.js +2 -1
  48. package/dist/production/src/content/ContentGraphQLContextFactory.js.map +1 -1
  49. package/dist/production/src/content/ContentSchemaResolver.cjs +7 -1
  50. package/dist/production/src/content/ContentSchemaResolver.cjs.map +1 -1
  51. package/dist/production/src/content/ContentSchemaResolver.js +8 -2
  52. package/dist/production/src/content/ContentSchemaResolver.js.map +1 -1
  53. package/dist/production/src/content/GraphQlSchemaFactory.cjs +5 -3
  54. package/dist/production/src/content/GraphQlSchemaFactory.cjs.map +1 -1
  55. package/dist/production/src/content/GraphQlSchemaFactory.js +5 -3
  56. package/dist/production/src/content/GraphQlSchemaFactory.js.map +1 -1
  57. package/dist/production/src/project/ProjectContainer.cjs +2 -24
  58. package/dist/production/src/project/ProjectContainer.cjs.map +1 -1
  59. package/dist/production/src/project/ProjectContainer.js +2 -24
  60. package/dist/production/src/project/ProjectContainer.js.map +1 -1
  61. package/dist/production/src/projectGroup/ProjectGroupContainer.cjs +0 -1
  62. package/dist/production/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
  63. package/dist/production/src/projectGroup/ProjectGroupContainer.js +0 -1
  64. package/dist/production/src/projectGroup/ProjectGroupContainer.js.map +1 -1
  65. package/dist/production/src/system/ContentQueryExecutor.cjs +1 -0
  66. package/dist/production/src/system/ContentQueryExecutor.cjs.map +1 -1
  67. package/dist/production/src/system/ContentQueryExecutor.js +1 -0
  68. package/dist/production/src/system/ContentQueryExecutor.js.map +1 -1
  69. package/dist/production/src/utils/memoizeObject.cjs +33 -0
  70. package/dist/production/src/utils/memoizeObject.cjs.map +1 -0
  71. package/dist/production/src/utils/memoizeObject.js +33 -0
  72. package/dist/production/src/utils/memoizeObject.js.map +1 -0
  73. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  74. package/dist/types/MasterContainer.d.ts +7 -1
  75. package/dist/types/MasterContainer.d.ts.map +1 -1
  76. package/dist/types/content/ContentApiControllerFactory.d.ts +3 -1
  77. package/dist/types/content/ContentApiControllerFactory.d.ts.map +1 -1
  78. package/dist/types/content/ContentGraphQLContextFactory.d.ts +3 -0
  79. package/dist/types/content/ContentGraphQLContextFactory.d.ts.map +1 -1
  80. package/dist/types/content/ContentSchemaResolver.d.ts.map +1 -1
  81. package/dist/types/content/GraphQLSchemaContributor.d.ts +3 -0
  82. package/dist/types/content/GraphQLSchemaContributor.d.ts.map +1 -1
  83. package/dist/types/content/GraphQlSchemaFactory.d.ts +2 -1
  84. package/dist/types/content/GraphQlSchemaFactory.d.ts.map +1 -1
  85. package/dist/types/plugin/Plugin.d.ts +2 -4
  86. package/dist/types/plugin/Plugin.d.ts.map +1 -1
  87. package/dist/types/project/ProjectContainer.d.ts +4 -19
  88. package/dist/types/project/ProjectContainer.d.ts.map +1 -1
  89. package/dist/types/system/ContentQueryExecutor.d.ts.map +1 -1
  90. package/dist/types/tsconfig.tsbuildinfo +1 -1
  91. package/dist/types/utils/memoizeObject.d.ts +2 -0
  92. package/dist/types/utils/memoizeObject.d.ts.map +1 -0
  93. package/package.json +15 -15
  94. package/src/MasterContainer.ts +26 -5
  95. package/src/content/ContentApiControllerFactory.ts +4 -2
  96. package/src/content/ContentGraphQLContextFactory.ts +2 -0
  97. package/src/content/ContentSchemaResolver.ts +10 -2
  98. package/src/content/GraphQLSchemaContributor.ts +7 -1
  99. package/src/content/GraphQlSchemaFactory.ts +6 -3
  100. package/src/plugin/Plugin.ts +2 -4
  101. package/src/project/ProjectContainer.ts +3 -30
  102. package/src/system/ContentQueryExecutor.ts +1 -0
  103. package/src/utils/memoizeObject.ts +38 -0
@@ -0,0 +1,2 @@
1
+ export declare const createMemoizer: <T extends object>(canonicalizeValue: (value: T) => string) => (value: T) => T;
2
+ //# sourceMappingURL=memoizeObject.d.ts.map
@@ -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.36",
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.36",
30
- "@contember/database": "2.0.0-alpha.36",
31
- "@contember/database-migrations": "2.0.0-alpha.36",
32
- "@contember/dic": "2.0.0-alpha.36",
33
- "@contember/engine-common": "2.0.0-alpha.36",
34
- "@contember/engine-content-api": "2.0.0-alpha.36",
35
- "@contember/engine-system-api": "2.0.0-alpha.36",
36
- "@contember/engine-tenant-api": "2.0.0-alpha.36",
37
- "@contember/graphql-utils": "2.0.0-alpha.36",
38
- "@contember/logger": "2.0.0-alpha.36",
39
- "@contember/schema": "2.0.0-alpha.36",
40
- "@contember/schema-migrations": "2.0.0-alpha.36",
41
- "@contember/schema-utils": "2.0.0-alpha.36",
42
- "@contember/typesafe": "2.0.0-alpha.36",
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",
@@ -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 { ContentApiControllerFactory, ContentGraphQLContextFactory, ContentQueryHandlerFactory, NotModifiedChecker } from './content'
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('projectContainerFactoryFactory', ({ plugins, providers, serverConfig, graphQlSchemaBuilderFactory, contentPermissionFactory, databaseMetadataResolver }) =>
124
- new ProjectContainerFactoryFactory(plugins, providers, serverConfig, graphQlSchemaBuilderFactory, contentPermissionFactory, databaseMetadataResolver))
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
- () => projectContainer.graphQlSchemaFactory.create(schema, {
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
- this.baseSchemaCache = await this.schemaProvider.fetch({ db, currentSchema: prevBaseSchema })
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,
@@ -42,3 +49,4 @@ const getSchema = (schema: Schema, options: { stage?: string; normalize?: boolea
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 = { schema: Schema; identity: Identity }
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, rolesKey, () => {
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>>()
@@ -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<CustomConfig extends Typesafe.JsonObject = Typesafe.JsonObject> {
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<CustomConfig>): GraphQLSchemaContributor | undefined
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, GraphQLSchemaContributor, GraphQlSchemaFactory, GraphQLSchemaFactoryResult } from '../content'
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
- .addService('graphqlSchemaCache', () =>
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 }) =>
@@ -40,6 +40,7 @@ export class ContentQueryExecutorImpl implements ContentQueryExecutor {
40
40
  })
41
41
 
42
42
  const ctx: ExtendedGraphqlContext = {
43
+ project,
43
44
  db: db.client.forSchema(stage.schema),
44
45
  identityVariables: {},
45
46
  identityId,
@@ -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
+ }