@contember/engine-http 0.12.0-alpha.0 → 0.12.0-alpha.12
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/ProjectConfig.d.ts +15 -0
- package/dist/src/ProjectConfig.d.ts.map +1 -0
- package/dist/src/{Project.js → ProjectConfig.js} +1 -1
- package/dist/src/ProjectConfig.js.map +1 -0
- package/dist/src/ProjectContainer.d.ts +5 -5
- package/dist/src/ProjectContainer.d.ts.map +1 -1
- package/dist/src/common/PoweredByHeaderMiddleware.d.ts +3 -0
- package/dist/src/common/PoweredByHeaderMiddleware.d.ts.map +1 -0
- package/dist/src/common/PoweredByHeaderMiddleware.js +15 -0
- package/dist/src/common/PoweredByHeaderMiddleware.js.map +1 -0
- package/dist/src/common/index.d.ts +1 -1
- package/dist/src/common/index.js +1 -1
- package/dist/src/content/ContentMiddleware.d.ts.map +1 -1
- package/dist/src/content/ContentMiddleware.js +0 -2
- package/dist/src/content/ContentMiddleware.js.map +1 -1
- package/dist/src/content/ContentQueryHandlerFactory.d.ts +18 -0
- package/dist/src/content/ContentQueryHandlerFactory.d.ts.map +1 -0
- package/dist/src/content/{ContentApolloServerFactory.js → ContentQueryHandlerFactory.js} +20 -26
- package/dist/src/content/ContentQueryHandlerFactory.js.map +1 -0
- package/dist/src/content/ContentQueryHandlerProvider.d.ts +15 -0
- package/dist/src/content/ContentQueryHandlerProvider.d.ts.map +1 -0
- package/dist/src/content/{ContentServerProvider.js → ContentQueryHandlerProvider.js} +12 -12
- package/dist/src/content/ContentQueryHandlerProvider.js.map +1 -0
- package/dist/src/content/ContentServerMiddleware.d.ts +2 -2
- package/dist/src/content/ContentServerMiddleware.d.ts.map +1 -1
- package/dist/src/content/ContentServerMiddleware.js +2 -3
- package/dist/src/content/ContentServerMiddleware.js.map +1 -1
- package/dist/src/content/GraphQlSchemaFactory.d.ts.map +1 -1
- package/dist/src/content/GraphQlSchemaFactory.js +4 -3
- package/dist/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/src/content/StageResolveMiddlewareFactory.d.ts +2 -2
- package/dist/src/content/StageResolveMiddlewareFactory.d.ts.map +1 -1
- package/dist/src/content/index.d.ts +2 -2
- package/dist/src/content/index.d.ts.map +1 -1
- package/dist/src/content/index.js +2 -2
- package/dist/src/content/index.js.map +1 -1
- package/dist/src/graphql/dbQueriesListener.d.ts +4 -0
- package/dist/src/graphql/dbQueriesListener.d.ts.map +1 -0
- package/dist/src/graphql/{DbQueriesPlugin.js → dbQueriesListener.js} +9 -15
- package/dist/src/graphql/dbQueriesListener.js.map +1 -0
- package/dist/src/graphql/errors.d.ts +13 -0
- package/dist/src/graphql/errors.d.ts.map +1 -0
- package/dist/src/graphql/errors.js +38 -0
- package/dist/src/graphql/errors.js.map +1 -0
- package/dist/src/graphql/execution.d.ts +25 -0
- package/dist/src/graphql/execution.d.ts.map +1 -0
- package/dist/src/graphql/execution.js +83 -0
- package/dist/src/graphql/execution.js.map +1 -0
- package/dist/src/graphql/index.d.ts +5 -0
- package/dist/src/graphql/index.d.ts.map +1 -0
- package/dist/src/graphql/index.js +17 -0
- package/dist/src/graphql/index.js.map +1 -0
- package/dist/src/graphql/state.d.ts +11 -0
- package/dist/src/graphql/state.d.ts.map +1 -0
- package/dist/src/graphql/state.js +20 -0
- package/dist/src/graphql/state.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/koa/compose.d.ts +1 -1
- package/dist/src/koa/compose.d.ts.map +1 -1
- package/dist/src/koa/compose.js +3 -0
- package/dist/src/koa/compose.js.map +1 -1
- package/dist/src/misc/PlaygroundMiddlewareFactory.d.ts.map +1 -1
- package/dist/src/misc/PlaygroundMiddlewareFactory.js +2 -6
- package/dist/src/misc/PlaygroundMiddlewareFactory.js.map +1 -1
- package/dist/src/project-common/ProjectMemberMiddlewareFactory.d.ts.map +1 -1
- package/dist/src/project-common/ProjectMemberMiddlewareFactory.js.map +1 -1
- package/dist/src/project-common/ProjectResolveMiddlewareFactory.d.ts +3 -4
- package/dist/src/project-common/ProjectResolveMiddlewareFactory.d.ts.map +1 -1
- package/dist/src/providers.d.ts +10 -1
- package/dist/src/providers.d.ts.map +1 -1
- package/dist/src/providers.js +20 -3
- package/dist/src/providers.js.map +1 -1
- package/dist/src/services/ProjectContainerResolverState.d.ts +2 -2
- package/dist/src/services/ProjectContainerResolverState.d.ts.map +1 -1
- package/dist/src/services/ProvidersState.d.ts +2 -2
- package/dist/src/services/ProvidersState.d.ts.map +1 -1
- package/dist/src/services/ServicesProviderMiddleware.d.ts +1 -3
- package/dist/src/services/ServicesProviderMiddleware.d.ts.map +1 -1
- package/dist/src/services/ServicesProviderMiddleware.js +0 -2
- package/dist/src/services/ServicesProviderMiddleware.js.map +1 -1
- package/dist/src/services/index.d.ts +0 -3
- package/dist/src/services/index.d.ts.map +1 -1
- package/dist/src/services/index.js +0 -3
- package/dist/src/services/index.js.map +1 -1
- package/dist/src/system/SystemGraphQLMiddlewareFactory.d.ts +21 -0
- package/dist/src/system/SystemGraphQLMiddlewareFactory.d.ts.map +1 -0
- package/dist/src/system/SystemGraphQLMiddlewareFactory.js +68 -0
- package/dist/src/system/SystemGraphQLMiddlewareFactory.js.map +1 -0
- package/dist/src/system/SystemMiddleware.d.ts +2 -1
- package/dist/src/system/SystemMiddleware.d.ts.map +1 -1
- package/dist/src/system/SystemMiddleware.js +2 -5
- package/dist/src/system/SystemMiddleware.js.map +1 -1
- package/dist/src/system/index.d.ts +1 -2
- package/dist/src/system/index.d.ts.map +1 -1
- package/dist/src/system/index.js +1 -2
- package/dist/src/system/index.js.map +1 -1
- package/dist/src/tenant/TenantGraphQLMiddlewareFactory.d.ts +19 -0
- package/dist/src/tenant/TenantGraphQLMiddlewareFactory.d.ts.map +1 -0
- package/dist/src/tenant/TenantGraphQLMiddlewareFactory.js +46 -0
- package/dist/src/tenant/TenantGraphQLMiddlewareFactory.js.map +1 -0
- package/dist/src/tenant/TenantMiddleware.d.ts +2 -2
- package/dist/src/tenant/TenantMiddleware.d.ts.map +1 -1
- package/dist/src/tenant/TenantMiddleware.js +2 -9
- package/dist/src/tenant/TenantMiddleware.js.map +1 -1
- package/dist/src/tenant/index.d.ts +1 -1
- package/dist/src/tenant/index.d.ts.map +1 -1
- package/dist/src/tenant/index.js +1 -1
- package/dist/src/tenant/index.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -18834
- package/package.json +15 -20
- package/src/ProjectConfig.ts +21 -0
- package/src/ProjectContainer.ts +8 -5
- package/src/common/PoweredByHeaderMiddleware.ts +12 -0
- package/src/common/index.ts +1 -1
- package/src/content/ContentMiddleware.ts +0 -2
- package/src/content/{ContentApolloServerFactory.ts → ContentQueryHandlerFactory.ts} +39 -32
- package/src/content/ContentQueryHandlerProvider.ts +36 -0
- package/src/content/ContentServerMiddleware.ts +12 -11
- package/src/content/GraphQlSchemaFactory.ts +2 -1
- package/src/content/StageResolveMiddlewareFactory.ts +2 -2
- package/src/content/index.ts +2 -2
- package/src/graphql/{DbQueriesPlugin.ts → dbQueriesListener.ts} +8 -14
- package/src/graphql/errors.ts +49 -0
- package/src/graphql/execution.ts +106 -0
- package/src/graphql/index.ts +4 -0
- package/src/graphql/state.ts +28 -0
- package/src/index.ts +2 -0
- package/src/koa/compose.ts +4 -1
- package/src/misc/PlaygroundMiddlewareFactory.ts +1 -6
- package/src/project-common/ProjectMemberMiddlewareFactory.ts +7 -6
- package/src/project-common/ProjectResolveMiddlewareFactory.ts +9 -9
- package/src/providers.ts +22 -4
- package/src/services/ProjectContainerResolverState.ts +2 -2
- package/src/services/ProvidersState.ts +2 -2
- package/src/services/ServicesProviderMiddleware.ts +5 -10
- package/src/services/index.ts +0 -3
- package/src/system/SystemGraphQLMiddlewareFactory.ts +92 -0
- package/src/system/SystemMiddleware.ts +4 -5
- package/src/system/index.ts +1 -2
- package/src/tenant/TenantGraphQLMiddlewareFactory.ts +53 -0
- package/src/tenant/TenantMiddleware.ts +4 -13
- package/src/tenant/index.ts +1 -1
- package/dist/src/Project.d.ts +0 -18
- package/dist/src/Project.d.ts.map +0 -1
- package/dist/src/Project.js.map +0 -1
- package/dist/src/common/GraphqlInfoProviderPlugin.d.ts +0 -16
- package/dist/src/common/GraphqlInfoProviderPlugin.d.ts.map +0 -1
- package/dist/src/common/GraphqlInfoProviderPlugin.js +0 -18
- package/dist/src/common/GraphqlInfoProviderPlugin.js.map +0 -1
- package/dist/src/content/ContentApolloServerFactory.d.ts +0 -14
- package/dist/src/content/ContentApolloServerFactory.d.ts.map +0 -1
- package/dist/src/content/ContentApolloServerFactory.js.map +0 -1
- package/dist/src/content/ContentServerProvider.d.ts +0 -15
- package/dist/src/content/ContentServerProvider.d.ts.map +0 -1
- package/dist/src/content/ContentServerProvider.js.map +0 -1
- package/dist/src/graphql/DbQueriesPlugin.d.ts +0 -9
- package/dist/src/graphql/DbQueriesPlugin.d.ts.map +0 -1
- package/dist/src/graphql/DbQueriesPlugin.js.map +0 -1
- package/dist/src/graphql/ErrorHandlerPlugin.d.ts +0 -24
- package/dist/src/graphql/ErrorHandlerPlugin.d.ts.map +0 -1
- package/dist/src/graphql/ErrorHandlerPlugin.js +0 -53
- package/dist/src/graphql/ErrorHandlerPlugin.js.map +0 -1
- package/dist/src/graphql/errorExtract.d.ts +0 -2
- package/dist/src/graphql/errorExtract.d.ts.map +0 -1
- package/dist/src/graphql/errorExtract.js +0 -15
- package/dist/src/graphql/errorExtract.js.map +0 -1
- package/dist/src/services/SystemServerState.d.ts +0 -5
- package/dist/src/services/SystemServerState.d.ts.map +0 -1
- package/dist/src/services/SystemServerState.js +0 -3
- package/dist/src/services/SystemServerState.js.map +0 -1
- package/dist/src/services/TenantApolloServerState.d.ts +0 -5
- package/dist/src/services/TenantApolloServerState.d.ts.map +0 -1
- package/dist/src/services/TenantApolloServerState.js +0 -3
- package/dist/src/services/TenantApolloServerState.js.map +0 -1
- package/dist/src/system/SchemaCacheCleanerPlugin.d.ts +0 -6
- package/dist/src/system/SchemaCacheCleanerPlugin.d.ts.map +0 -1
- package/dist/src/system/SchemaCacheCleanerPlugin.js +0 -14
- package/dist/src/system/SchemaCacheCleanerPlugin.js.map +0 -1
- package/dist/src/system/SystemServerMiddleware.d.ts +0 -6
- package/dist/src/system/SystemServerMiddleware.d.ts.map +0 -1
- package/dist/src/system/SystemServerMiddleware.js +0 -13
- package/dist/src/system/SystemServerMiddleware.js.map +0 -1
- package/dist/src/system/SystemServerProvider.d.ts +0 -23
- package/dist/src/system/SystemServerProvider.d.ts.map +0 -1
- package/dist/src/system/SystemServerProvider.js +0 -67
- package/dist/src/system/SystemServerProvider.js.map +0 -1
- package/dist/src/tenant/TenantApolloServerFactory.d.ts +0 -12
- package/dist/src/tenant/TenantApolloServerFactory.d.ts.map +0 -1
- package/dist/src/tenant/TenantApolloServerFactory.js +0 -41
- package/dist/src/tenant/TenantApolloServerFactory.js.map +0 -1
- package/src/Project.ts +0 -20
- package/src/common/GraphqlInfoProviderPlugin.ts +0 -25
- package/src/content/ContentServerProvider.ts +0 -36
- package/src/graphql/ErrorHandlerPlugin.ts +0 -69
- package/src/graphql/errorExtract.ts +0 -11
- package/src/services/SystemServerState.ts +0 -3
- package/src/services/TenantApolloServerState.ts +0 -5
- package/src/system/SchemaCacheCleanerPlugin.ts +0 -12
- package/src/system/SystemServerMiddleware.ts +0 -13
- package/src/system/SystemServerProvider.ts +0 -93
- package/src/tenant/TenantApolloServerFactory.ts +0 -49
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SystemServerMiddleware.js","sourceRoot":"","sources":["../../../src/system/SystemServerMiddleware.ts"],"names":[],"mappings":";;;AACA,gEAA6D;AAKtD,MAAM,4BAA4B,GAAG,GAA8B,EAAE;IAC3E,MAAM,sBAAsB,GAA8B,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC7E,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,oBAAoB,CAAC,GAAG,EAAE,CAAA;QACnD,MAAM,sBAAU,CAAC,MAAM,CAAC,0BAA0B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC5E,CAAC,CAAA;IACD,OAAO,sBAAsB,CAAA;AAC9B,CAAC,CAAA;AANY,QAAA,4BAA4B,gCAMxC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ApolloServer } from 'apollo-server-koa';
|
|
2
|
-
import { ResolverContext, ResolverContextFactory, ResolverFactory } from '@contember/engine-system-api';
|
|
3
|
-
import { KoaContext } from '../koa';
|
|
4
|
-
import { ErrorContextProvider, ErrorLogger } from '../graphql/ErrorHandlerPlugin';
|
|
5
|
-
import { ProjectMemberMiddlewareState, ProjectResolveMiddlewareState } from '../project-common';
|
|
6
|
-
import { AuthMiddlewareState, GraphQLInfoState } from '../common';
|
|
7
|
-
declare type InputKoaContext = KoaContext<AuthMiddlewareState & ProjectMemberMiddlewareState & ProjectResolveMiddlewareState & GraphQLInfoState>;
|
|
8
|
-
export declare type ExtendedGraphqlContext = ResolverContext & {
|
|
9
|
-
errorContextProvider: ErrorContextProvider;
|
|
10
|
-
koaContext: InputKoaContext;
|
|
11
|
-
};
|
|
12
|
-
declare class SystemServerProvider {
|
|
13
|
-
private readonly resolversFactory;
|
|
14
|
-
private readonly resolverContextFactory;
|
|
15
|
-
private readonly errorLogger;
|
|
16
|
-
private readonly debugMode;
|
|
17
|
-
private server;
|
|
18
|
-
constructor(resolversFactory: ResolverFactory, resolverContextFactory: ResolverContextFactory, errorLogger: ErrorLogger, debugMode: boolean);
|
|
19
|
-
get(): ApolloServer;
|
|
20
|
-
private createContext;
|
|
21
|
-
}
|
|
22
|
-
export { SystemServerProvider };
|
|
23
|
-
//# sourceMappingURL=SystemServerProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SystemServerProvider.d.ts","sourceRoot":"","sources":["../../../src/system/SystemServerProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAgB,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAGN,eAAe,EACf,sBAAsB,EACtB,eAAe,EAEf,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAEnC,OAAO,EAAE,oBAAoB,EAAsB,WAAW,EAAE,MAAM,+BAA+B,CAAA;AACrG,OAAO,EAAE,4BAA4B,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AAC/F,OAAO,EAAE,mBAAmB,EAA6B,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAK5F,aAAK,eAAe,GAAG,UAAU,CAChC,mBAAmB,GAAG,4BAA4B,GAAG,6BAA6B,GAAG,gBAAgB,CACrG,CAAA;AAED,oBAAY,sBAAsB,GAAG,eAAe,GAAG;IACtD,oBAAoB,EAAE,oBAAoB,CAAA;IAC1C,UAAU,EAAE,eAAe,CAAA;CAC3B,CAAA;AAED,cAAM,oBAAoB;IAIxB,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAN3B,OAAO,CAAC,MAAM,CAA4B;gBAGxB,gBAAgB,EAAE,eAAe,EACjC,sBAAsB,EAAE,sBAAsB,EAC9C,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,OAAO;IAGpC,GAAG,IAAI,YAAY;YA4BL,aAAa;CAwB3B;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAA"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SystemServerProvider = void 0;
|
|
7
|
-
const apollo_server_koa_1 = require("apollo-server-koa");
|
|
8
|
-
const engine_system_api_1 = require("@contember/engine-system-api");
|
|
9
|
-
const engine_content_api_1 = require("@contember/engine-content-api");
|
|
10
|
-
const ErrorHandlerPlugin_1 = require("../graphql/ErrorHandlerPlugin");
|
|
11
|
-
const common_1 = require("../common");
|
|
12
|
-
const DbQueriesPlugin_1 = __importDefault(require("../graphql/DbQueriesPlugin"));
|
|
13
|
-
const SchemaCacheCleanerPlugin_1 = require("./SchemaCacheCleanerPlugin");
|
|
14
|
-
class SystemServerProvider {
|
|
15
|
-
constructor(resolversFactory, resolverContextFactory, errorLogger, debugMode) {
|
|
16
|
-
this.resolversFactory = resolversFactory;
|
|
17
|
-
this.resolverContextFactory = resolverContextFactory;
|
|
18
|
-
this.errorLogger = errorLogger;
|
|
19
|
-
this.debugMode = debugMode;
|
|
20
|
-
this.server = null;
|
|
21
|
-
}
|
|
22
|
-
get() {
|
|
23
|
-
if (this.server) {
|
|
24
|
-
return this.server;
|
|
25
|
-
}
|
|
26
|
-
const schemas = [engine_system_api_1.typeDefs];
|
|
27
|
-
if (this.debugMode) {
|
|
28
|
-
schemas.push(engine_system_api_1.devTypeDefs);
|
|
29
|
-
}
|
|
30
|
-
const plugins = [
|
|
31
|
-
new common_1.GraphqlInfoProviderPlugin(),
|
|
32
|
-
new ErrorHandlerPlugin_1.ErrorHandlerPlugin(undefined, 'system', this.errorLogger),
|
|
33
|
-
];
|
|
34
|
-
if (this.debugMode) {
|
|
35
|
-
plugins.push(new DbQueriesPlugin_1.default(context => context.db.client));
|
|
36
|
-
plugins.push(new SchemaCacheCleanerPlugin_1.SchemaCacheCleanerPlugin());
|
|
37
|
-
}
|
|
38
|
-
const resolvers = this.resolversFactory.create(this.debugMode);
|
|
39
|
-
const mergedSchema = apollo_server_koa_1.mergeSchemas({ schemas, resolvers: resolvers });
|
|
40
|
-
return (this.server = new apollo_server_koa_1.ApolloServer({
|
|
41
|
-
uploads: false,
|
|
42
|
-
playground: false,
|
|
43
|
-
introspection: true,
|
|
44
|
-
schema: mergedSchema,
|
|
45
|
-
plugins: plugins,
|
|
46
|
-
context: ({ ctx }) => this.createContext(ctx),
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
async createContext(ctx) {
|
|
50
|
-
const identity = new engine_system_api_1.Identity(ctx.state.authResult.identityId, ctx.state.projectMemberships.map(it => it.role));
|
|
51
|
-
const dbContextFactory = ctx.state.projectContainer.systemDatabaseContextFactory;
|
|
52
|
-
const variables = engine_content_api_1.flattenVariables(ctx.state.projectMemberships);
|
|
53
|
-
const systemContext = await this.resolverContextFactory.create(dbContextFactory.create(identity.id), ctx.state.project, identity, variables);
|
|
54
|
-
return {
|
|
55
|
-
...systemContext,
|
|
56
|
-
errorContextProvider: () => ({
|
|
57
|
-
body: ctx.request.body,
|
|
58
|
-
project: ctx.state.project.slug,
|
|
59
|
-
url: ctx.request.originalUrl,
|
|
60
|
-
user: ctx.state.authResult.identityId,
|
|
61
|
-
}),
|
|
62
|
-
koaContext: ctx,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.SystemServerProvider = SystemServerProvider;
|
|
67
|
-
//# sourceMappingURL=SystemServerProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SystemServerProvider.js","sourceRoot":"","sources":["../../../src/system/SystemServerProvider.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ApolloServer } from 'apollo-server-koa';
|
|
2
|
-
import { ResolverContextFactory, Schema } from '@contember/engine-tenant-api';
|
|
3
|
-
import { ErrorLogger } from '../graphql/ErrorHandlerPlugin';
|
|
4
|
-
declare class TenantApolloServerFactory {
|
|
5
|
-
private readonly resolvers;
|
|
6
|
-
private readonly resolverContextFactory;
|
|
7
|
-
private readonly errorLogger;
|
|
8
|
-
constructor(resolvers: Schema.Resolvers, resolverContextFactory: ResolverContextFactory, errorLogger: ErrorLogger);
|
|
9
|
-
create(): ApolloServer;
|
|
10
|
-
}
|
|
11
|
-
export { TenantApolloServerFactory };
|
|
12
|
-
//# sourceMappingURL=TenantApolloServerFactory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TenantApolloServerFactory.d.ts","sourceRoot":"","sources":["../../../src/tenant/TenantApolloServerFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAwB,MAAM,mBAAmB,CAAA;AACtE,OAAO,EAAmB,sBAAsB,EAAE,MAAM,EAAY,MAAM,8BAA8B,CAAA;AAExG,OAAO,EAA4C,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAUrG,cAAM,yBAAyB;IAE7B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAFX,SAAS,EAAE,MAAM,CAAC,SAAS,EAC3B,sBAAsB,EAAE,sBAAsB,EAC9C,WAAW,EAAE,WAAW;IAG1C,MAAM,IAAI,YAAY;CAyBtB;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAA"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TenantApolloServerFactory = void 0;
|
|
4
|
-
const apollo_server_koa_1 = require("apollo-server-koa");
|
|
5
|
-
const engine_tenant_api_1 = require("@contember/engine-tenant-api");
|
|
6
|
-
const common_1 = require("../common");
|
|
7
|
-
const ErrorHandlerPlugin_1 = require("../graphql/ErrorHandlerPlugin");
|
|
8
|
-
class TenantApolloServerFactory {
|
|
9
|
-
constructor(resolvers, resolverContextFactory, errorLogger) {
|
|
10
|
-
this.resolvers = resolvers;
|
|
11
|
-
this.resolverContextFactory = resolverContextFactory;
|
|
12
|
-
this.errorLogger = errorLogger;
|
|
13
|
-
}
|
|
14
|
-
create() {
|
|
15
|
-
const schema = apollo_server_koa_1.makeExecutableSchema({
|
|
16
|
-
typeDefs: engine_tenant_api_1.typeDefs,
|
|
17
|
-
resolvers: this.resolvers,
|
|
18
|
-
resolverValidationOptions: { requireResolversForResolveType: false },
|
|
19
|
-
});
|
|
20
|
-
return new apollo_server_koa_1.ApolloServer({
|
|
21
|
-
schema,
|
|
22
|
-
uploads: false,
|
|
23
|
-
playground: false,
|
|
24
|
-
introspection: true,
|
|
25
|
-
plugins: [new common_1.GraphqlInfoProviderPlugin(), new ErrorHandlerPlugin_1.ErrorHandlerPlugin(undefined, 'tenant', this.errorLogger)],
|
|
26
|
-
context: ({ ctx }) => {
|
|
27
|
-
return {
|
|
28
|
-
...this.resolverContextFactory.create(ctx.state.authResult),
|
|
29
|
-
errorContextProvider: () => ({
|
|
30
|
-
body: ctx.request.body,
|
|
31
|
-
url: ctx.request.originalUrl,
|
|
32
|
-
user: ctx.state.authResult.identityId,
|
|
33
|
-
}),
|
|
34
|
-
koaContext: ctx,
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.TenantApolloServerFactory = TenantApolloServerFactory;
|
|
41
|
-
//# sourceMappingURL=TenantApolloServerFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TenantApolloServerFactory.js","sourceRoot":"","sources":["../../../src/tenant/TenantApolloServerFactory.ts"],"names":[],"mappings":";;;AACA,yDAAsE;AACtE,oEAAwG;AACxG,sCAA4F;AAC5F,sEAAqG;AAUrG,MAAM,yBAAyB;IAC9B,YACkB,SAA2B,EAC3B,sBAA8C,EAC9C,WAAwB;QAFxB,cAAS,GAAT,SAAS,CAAkB;QAC3B,2BAAsB,GAAtB,sBAAsB,CAAwB;QAC9C,gBAAW,GAAX,WAAW,CAAa;IACvC,CAAC;IAEJ,MAAM;QACL,MAAM,MAAM,GAAG,wCAAoB,CAAC;YACnC,QAAQ,EAAR,4BAAQ;YACR,SAAS,EAAE,IAAI,CAAC,SAAgC;YAChD,yBAAyB,EAAE,EAAE,8BAA8B,EAAE,KAAK,EAAE;SACpE,CAAC,CAAA;QACF,OAAO,IAAI,gCAAY,CAAC;YACvB,MAAM;YACN,OAAO,EAAE,KAAK;YACd,UAAU,EAAE,KAAK;YACjB,aAAa,EAAE,IAAI;YACnB,OAAO,EAAE,CAAC,IAAI,kCAAyB,EAAE,EAAE,IAAI,uCAAkB,CAAC,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;YACzG,OAAO,EAAE,CAAC,EAAE,GAAG,EAA4B,EAA0B,EAAE;gBACtE,OAAO;oBACN,GAAG,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC;oBAC3D,oBAAoB,EAAE,GAAG,EAAE,CAAC,CAAC;wBAC5B,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI;wBACtB,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,WAAW;wBAC5B,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU;qBACrC,CAAC;oBACF,UAAU,EAAE,GAAG;iBACf,CAAA;YACF,CAAC;SACD,CAAC,CAAA;IACH,CAAC;CACD;AAEQ,8DAAyB"}
|
package/src/Project.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { DatabaseCredentials } from '@contember/database'
|
|
2
|
-
|
|
3
|
-
type Project = {
|
|
4
|
-
readonly slug: string
|
|
5
|
-
readonly alias?: string[]
|
|
6
|
-
readonly directory?: string
|
|
7
|
-
readonly name: string
|
|
8
|
-
readonly stages: Array<Project.Stage>
|
|
9
|
-
readonly db: DatabaseCredentials
|
|
10
|
-
} & Record<string, unknown>
|
|
11
|
-
|
|
12
|
-
namespace Project {
|
|
13
|
-
export interface Stage {
|
|
14
|
-
readonly slug: string
|
|
15
|
-
readonly name: string
|
|
16
|
-
readonly base?: string
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default Project
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ApolloServerPlugin, GraphQLRequestListener } from 'apollo-server-plugin-base'
|
|
2
|
-
import { GraphQLRequestContext } from 'apollo-server-core'
|
|
3
|
-
import { KoaContext } from '../koa'
|
|
4
|
-
|
|
5
|
-
export type GraphQLInfoState = {
|
|
6
|
-
graphql?: {
|
|
7
|
-
operationName: string
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type Context = { koaContext?: KoaContext<GraphQLInfoState> }
|
|
12
|
-
|
|
13
|
-
export class GraphqlInfoProviderPlugin implements ApolloServerPlugin<Context> {
|
|
14
|
-
requestDidStart(requestContext: GraphQLRequestContext<Context>): GraphQLRequestListener<Context> {
|
|
15
|
-
return {
|
|
16
|
-
didResolveOperation: requestContext => {
|
|
17
|
-
if (requestContext.context.koaContext) {
|
|
18
|
-
requestContext.context.koaContext.state.graphql = {
|
|
19
|
-
operationName: requestContext.operation.operation,
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ContentSchemaResolver } from './ContentSchemaResolver'
|
|
2
|
-
import { GraphQlSchemaFactory } from './GraphQlSchemaFactory'
|
|
3
|
-
import { ContentApolloServerFactory } from './ContentApolloServerFactory'
|
|
4
|
-
import Project from '../Project'
|
|
5
|
-
import { ApolloServer } from 'apollo-server-koa'
|
|
6
|
-
import LRUCache from 'lru-cache'
|
|
7
|
-
import { GraphQLSchema } from 'graphql'
|
|
8
|
-
import { DatabaseContext } from '@contember/engine-system-api'
|
|
9
|
-
|
|
10
|
-
export class ContentServerProvider {
|
|
11
|
-
private cache = new LRUCache<GraphQLSchema, ApolloServer>({
|
|
12
|
-
max: 100,
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
constructor(
|
|
16
|
-
private readonly contentSchemaFactory: ContentSchemaResolver,
|
|
17
|
-
private readonly graphqlSchemaFactory: GraphQlSchemaFactory,
|
|
18
|
-
private readonly apolloServerFactory: ContentApolloServerFactory,
|
|
19
|
-
) {}
|
|
20
|
-
|
|
21
|
-
async get(db: DatabaseContext, stage: Project.Stage, projectRoles: string[]): Promise<ApolloServer> {
|
|
22
|
-
const schema = await this.contentSchemaFactory.getSchema(db, stage.slug)
|
|
23
|
-
|
|
24
|
-
const [dataSchema, permissions] = await this.graphqlSchemaFactory.create(schema, {
|
|
25
|
-
projectRoles: projectRoles,
|
|
26
|
-
})
|
|
27
|
-
const server = this.cache.get(dataSchema)
|
|
28
|
-
if (server) {
|
|
29
|
-
return server
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const newServer = this.apolloServerFactory.create(permissions, schema, dataSchema)
|
|
33
|
-
this.cache.set(dataSchema, newServer)
|
|
34
|
-
return newServer
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { AuthenticationError } from 'apollo-server-koa'
|
|
2
|
-
import { ApolloError } from 'apollo-server-errors'
|
|
3
|
-
import { ApolloError as ApolloCoreError, GraphQLRequestContext } from 'apollo-server-core'
|
|
4
|
-
import { UserError } from '@contember/engine-content-api'
|
|
5
|
-
import { GraphQLError } from 'graphql'
|
|
6
|
-
import { extractOriginalError } from './errorExtract'
|
|
7
|
-
import { ApolloServerPlugin, GraphQLRequestListener } from 'apollo-server-plugin-base'
|
|
8
|
-
|
|
9
|
-
interface ErrorContext {
|
|
10
|
-
user: string
|
|
11
|
-
body: string
|
|
12
|
-
project?: string
|
|
13
|
-
url: string
|
|
14
|
-
module: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type ErrorLogger = (error: any, context: ErrorContext) => void
|
|
18
|
-
|
|
19
|
-
export type ErrorContextProvider = () => Pick<ErrorContext, 'url' | 'body' | 'user'>
|
|
20
|
-
|
|
21
|
-
type Context = { errorContextProvider?: ErrorContextProvider }
|
|
22
|
-
|
|
23
|
-
export class ErrorHandlerPlugin implements ApolloServerPlugin {
|
|
24
|
-
constructor(
|
|
25
|
-
private readonly projectSlug: string | undefined,
|
|
26
|
-
private readonly module: string,
|
|
27
|
-
private readonly errorLogger: ErrorLogger,
|
|
28
|
-
) {}
|
|
29
|
-
|
|
30
|
-
requestDidStart(requestContext: GraphQLRequestContext<Context>): GraphQLRequestListener<Context> {
|
|
31
|
-
return {
|
|
32
|
-
willSendResponse: ({ response, context }) => {
|
|
33
|
-
const errorContextProvider = context.errorContextProvider
|
|
34
|
-
if (response.errors && errorContextProvider) {
|
|
35
|
-
response.errors = response.errors.map((it: any) => this.processError(it, errorContextProvider))
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
processError(error: any, errorContextProvider: ErrorContextProvider): any {
|
|
42
|
-
if (error instanceof AuthenticationError) {
|
|
43
|
-
return { message: error.message, locations: undefined, path: undefined }
|
|
44
|
-
}
|
|
45
|
-
if (error instanceof ApolloError) {
|
|
46
|
-
return error
|
|
47
|
-
}
|
|
48
|
-
const originalError = extractOriginalError(error)
|
|
49
|
-
if (
|
|
50
|
-
originalError instanceof GraphQLError ||
|
|
51
|
-
originalError instanceof ApolloError ||
|
|
52
|
-
originalError instanceof ApolloCoreError
|
|
53
|
-
) {
|
|
54
|
-
return error
|
|
55
|
-
}
|
|
56
|
-
if (originalError instanceof UserError) {
|
|
57
|
-
return { message: error.message, locations: error.locations, path: error.path }
|
|
58
|
-
}
|
|
59
|
-
// eslint-disable-next-line no-console
|
|
60
|
-
console.error(originalError || error)
|
|
61
|
-
this.errorLogger(originalError || error, {
|
|
62
|
-
project: this.projectSlug,
|
|
63
|
-
module: this.module,
|
|
64
|
-
...errorContextProvider(),
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
return { message: 'Internal server error', locations: undefined, path: undefined }
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { GraphQLError } from 'graphql'
|
|
2
|
-
|
|
3
|
-
export const extractOriginalError = (e: Error): Error => {
|
|
4
|
-
if (e instanceof GraphQLError && e.originalError) {
|
|
5
|
-
return extractOriginalError(e.originalError)
|
|
6
|
-
}
|
|
7
|
-
if ('errors' in e && Array.isArray((e as any).errors) && (e as any).errors.length === 1) {
|
|
8
|
-
return extractOriginalError((e as any).errors[0])
|
|
9
|
-
}
|
|
10
|
-
return e
|
|
11
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ApolloServerPlugin, GraphQLRequestListener } from 'apollo-server-plugin-base'
|
|
2
|
-
import { ExtendedGraphqlContext } from './SystemServerProvider'
|
|
3
|
-
|
|
4
|
-
export class SchemaCacheCleanerPlugin implements ApolloServerPlugin<ExtendedGraphqlContext> {
|
|
5
|
-
requestDidStart({}): GraphQLRequestListener<ExtendedGraphqlContext> {
|
|
6
|
-
return {
|
|
7
|
-
willSendResponse({ context }) {
|
|
8
|
-
context.koaContext.state.projectContainer.contentSchemaResolver.clearCache()
|
|
9
|
-
},
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { KoaMiddleware } from '../koa'
|
|
2
|
-
import { graphqlKoa } from 'apollo-server-koa/dist/koaApollo'
|
|
3
|
-
import { SystemServerState } from '../services/SystemServerState'
|
|
4
|
-
|
|
5
|
-
type InputState = SystemServerState
|
|
6
|
-
|
|
7
|
-
export const createSystemServerMiddleware = (): KoaMiddleware<InputState> => {
|
|
8
|
-
const systemServerMiddleware: KoaMiddleware<InputState> = async (ctx, next) => {
|
|
9
|
-
const server = ctx.state.systemServerProvider.get()
|
|
10
|
-
await graphqlKoa(server.createGraphQLServerOptions.bind(server))(ctx, next)
|
|
11
|
-
}
|
|
12
|
-
return systemServerMiddleware
|
|
13
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { Config } from 'apollo-server-core'
|
|
2
|
-
import { ApolloServer, mergeSchemas } from 'apollo-server-koa'
|
|
3
|
-
import {
|
|
4
|
-
devTypeDefs,
|
|
5
|
-
Identity,
|
|
6
|
-
ResolverContext,
|
|
7
|
-
ResolverContextFactory,
|
|
8
|
-
ResolverFactory,
|
|
9
|
-
typeDefs,
|
|
10
|
-
} from '@contember/engine-system-api'
|
|
11
|
-
import { KoaContext } from '../koa'
|
|
12
|
-
import { flattenVariables } from '@contember/engine-content-api'
|
|
13
|
-
import { ErrorContextProvider, ErrorHandlerPlugin, ErrorLogger } from '../graphql/ErrorHandlerPlugin'
|
|
14
|
-
import { ProjectMemberMiddlewareState, ProjectResolveMiddlewareState } from '../project-common'
|
|
15
|
-
import { AuthMiddlewareState, GraphqlInfoProviderPlugin, GraphQLInfoState } from '../common'
|
|
16
|
-
import DbQueriesPlugin from '../graphql/DbQueriesPlugin'
|
|
17
|
-
import { ApolloServerPlugin } from 'apollo-server-plugin-base'
|
|
18
|
-
import { SchemaCacheCleanerPlugin } from './SchemaCacheCleanerPlugin'
|
|
19
|
-
|
|
20
|
-
type InputKoaContext = KoaContext<
|
|
21
|
-
AuthMiddlewareState & ProjectMemberMiddlewareState & ProjectResolveMiddlewareState & GraphQLInfoState
|
|
22
|
-
>
|
|
23
|
-
|
|
24
|
-
export type ExtendedGraphqlContext = ResolverContext & {
|
|
25
|
-
errorContextProvider: ErrorContextProvider
|
|
26
|
-
koaContext: InputKoaContext
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
class SystemServerProvider {
|
|
30
|
-
private server: ApolloServer | null = null
|
|
31
|
-
|
|
32
|
-
constructor(
|
|
33
|
-
private readonly resolversFactory: ResolverFactory,
|
|
34
|
-
private readonly resolverContextFactory: ResolverContextFactory,
|
|
35
|
-
private readonly errorLogger: ErrorLogger,
|
|
36
|
-
private readonly debugMode: boolean,
|
|
37
|
-
) {}
|
|
38
|
-
|
|
39
|
-
get(): ApolloServer {
|
|
40
|
-
if (this.server) {
|
|
41
|
-
return this.server
|
|
42
|
-
}
|
|
43
|
-
const schemas: Parameters<typeof mergeSchemas>[0]['schemas'] = [typeDefs]
|
|
44
|
-
if (this.debugMode) {
|
|
45
|
-
schemas.push(devTypeDefs)
|
|
46
|
-
}
|
|
47
|
-
const plugins: ApolloServerPlugin[] = [
|
|
48
|
-
new GraphqlInfoProviderPlugin(),
|
|
49
|
-
new ErrorHandlerPlugin(undefined, 'system', this.errorLogger),
|
|
50
|
-
]
|
|
51
|
-
if (this.debugMode) {
|
|
52
|
-
plugins.push(new DbQueriesPlugin<ExtendedGraphqlContext>(context => context.db.client))
|
|
53
|
-
plugins.push(new SchemaCacheCleanerPlugin())
|
|
54
|
-
}
|
|
55
|
-
const resolvers = this.resolversFactory.create(this.debugMode)
|
|
56
|
-
const mergedSchema = mergeSchemas({ schemas, resolvers: resolvers as Config['resolvers'] })
|
|
57
|
-
return (this.server = new ApolloServer({
|
|
58
|
-
uploads: false,
|
|
59
|
-
playground: false,
|
|
60
|
-
introspection: true,
|
|
61
|
-
schema: mergedSchema,
|
|
62
|
-
plugins: plugins,
|
|
63
|
-
context: ({ ctx }: { ctx: InputKoaContext }) => this.createContext(ctx),
|
|
64
|
-
}))
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private async createContext(ctx: InputKoaContext): Promise<ExtendedGraphqlContext> {
|
|
68
|
-
const identity = new Identity(
|
|
69
|
-
ctx.state.authResult.identityId,
|
|
70
|
-
ctx.state.projectMemberships.map(it => it.role),
|
|
71
|
-
)
|
|
72
|
-
const dbContextFactory = ctx.state.projectContainer.systemDatabaseContextFactory
|
|
73
|
-
const variables = flattenVariables(ctx.state.projectMemberships)
|
|
74
|
-
const systemContext = await this.resolverContextFactory.create(
|
|
75
|
-
dbContextFactory.create(identity.id),
|
|
76
|
-
ctx.state.project,
|
|
77
|
-
identity,
|
|
78
|
-
variables,
|
|
79
|
-
)
|
|
80
|
-
return {
|
|
81
|
-
...systemContext,
|
|
82
|
-
errorContextProvider: () => ({
|
|
83
|
-
body: ctx.request.body,
|
|
84
|
-
project: ctx.state.project.slug,
|
|
85
|
-
url: ctx.request.originalUrl,
|
|
86
|
-
user: ctx.state.authResult.identityId,
|
|
87
|
-
}),
|
|
88
|
-
koaContext: ctx,
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export { SystemServerProvider }
|