@webiny/api-graphql 0.0.0-unstable.0d717d18dd
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/LICENSE +21 -0
- package/README.md +11 -0
- package/ResolverDecoration.d.ts +6 -0
- package/ResolverDecoration.js +23 -0
- package/ResolverDecoration.js.map +1 -0
- package/builtInTypes/AnyScalar.d.ts +2 -0
- package/builtInTypes/AnyScalar.js +11 -0
- package/builtInTypes/AnyScalar.js.map +1 -0
- package/builtInTypes/DateScalar.d.ts +2 -0
- package/builtInTypes/DateScalar.js +23 -0
- package/builtInTypes/DateScalar.js.map +1 -0
- package/builtInTypes/DateTimeScalar.d.ts +2 -0
- package/builtInTypes/DateTimeScalar.js +18 -0
- package/builtInTypes/DateTimeScalar.js.map +1 -0
- package/builtInTypes/DateTimeZScalar.d.ts +6 -0
- package/builtInTypes/DateTimeZScalar.js +32 -0
- package/builtInTypes/DateTimeZScalar.js.map +1 -0
- package/builtInTypes/IconScalar.d.ts +10 -0
- package/builtInTypes/IconScalar.js +65 -0
- package/builtInTypes/IconScalar.js.map +1 -0
- package/builtInTypes/JsonScalar.d.ts +1 -0
- package/builtInTypes/JsonScalar.js +5 -0
- package/builtInTypes/JsonScalar.js.map +1 -0
- package/builtInTypes/LongScalar.d.ts +2 -0
- package/builtInTypes/LongScalar.js +40 -0
- package/builtInTypes/LongScalar.js.map +1 -0
- package/builtInTypes/NumberScalar.d.ts +2 -0
- package/builtInTypes/NumberScalar.js +41 -0
- package/builtInTypes/NumberScalar.js.map +1 -0
- package/builtInTypes/RefInputScalar.d.ts +2 -0
- package/builtInTypes/RefInputScalar.js +53 -0
- package/builtInTypes/RefInputScalar.js.map +1 -0
- package/builtInTypes/TimeScalar.d.ts +2 -0
- package/builtInTypes/TimeScalar.js +40 -0
- package/builtInTypes/TimeScalar.js.map +1 -0
- package/builtInTypes/index.d.ts +10 -0
- package/builtInTypes/index.js +10 -0
- package/createRequestBody.d.ts +2 -0
- package/createRequestBody.js +28 -0
- package/createRequestBody.js.map +1 -0
- package/createResolverDecorator.d.ts +2 -0
- package/createResolverDecorator.js +4 -0
- package/createResolverDecorator.js.map +1 -0
- package/engine/GraphQLContextEnhancer.d.ts +12 -0
- package/engine/GraphQLContextEnhancer.js +5 -0
- package/engine/GraphQLContextEnhancer.js.map +1 -0
- package/engine/GraphQLContextualSchema.d.ts +14 -0
- package/engine/GraphQLContextualSchema.js +5 -0
- package/engine/GraphQLContextualSchema.js.map +1 -0
- package/engine/GraphQLEngine.d.ts +21 -0
- package/engine/GraphQLEngine.js +95 -0
- package/engine/GraphQLEngine.js.map +1 -0
- package/engine/GraphQLEngineFeature.d.ts +4 -0
- package/engine/GraphQLEngineFeature.js +15 -0
- package/engine/GraphQLEngineFeature.js.map +1 -0
- package/engine/GraphQLRoute.d.ts +14 -0
- package/engine/GraphQLRoute.js +28 -0
- package/engine/GraphQLRoute.js.map +1 -0
- package/engine/abstractions.d.ts +7 -0
- package/engine/abstractions.js +5 -0
- package/engine/abstractions.js.map +1 -0
- package/engine/index.d.ts +5 -0
- package/engine/index.js +5 -0
- package/errors.d.ts +4 -0
- package/errors.js +9 -0
- package/errors.js.map +1 -0
- package/exports/api/graphql.d.ts +2 -0
- package/exports/api/graphql.js +2 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.d.ts +17 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js +71 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js.map +1 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.d.ts +12 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js +26 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js.map +1 -0
- package/features/GraphQLSchemaBuilder/abstractions.d.ts +39 -0
- package/features/GraphQLSchemaBuilder/abstractions.js +6 -0
- package/features/GraphQLSchemaBuilder/abstractions.js.map +1 -0
- package/features/GraphQLSchemaBuilder/feature.d.ts +4 -0
- package/features/GraphQLSchemaBuilder/feature.js +11 -0
- package/features/GraphQLSchemaBuilder/feature.js.map +1 -0
- package/graphql/abstractions.core.d.ts +15 -0
- package/graphql/abstractions.core.js +5 -0
- package/graphql/abstractions.core.js.map +1 -0
- package/graphql/abstractions.d.ts +2 -0
- package/graphql/abstractions.js +2 -0
- package/graphql/abstractions.public.d.ts +18 -0
- package/graphql/abstractions.public.js +5 -0
- package/graphql/abstractions.public.js.map +1 -0
- package/index.d.ts +12 -0
- package/index.js +14 -0
- package/index.js.map +1 -0
- package/package.json +50 -0
- package/plugins/GraphQLSchemaPlugin.d.ts +21 -0
- package/plugins/GraphQLSchemaPlugin.js +25 -0
- package/plugins/GraphQLSchemaPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +1 -0
- package/processRequestBody.d.ts +4 -0
- package/processRequestBody.js +26 -0
- package/processRequestBody.js.map +1 -0
- package/registerLegacyPluginsViaGqlContextEnhancer.d.ts +12 -0
- package/registerLegacyPluginsViaGqlContextEnhancer.js +21 -0
- package/registerLegacyPluginsViaGqlContextEnhancer.js.map +1 -0
- package/responses.d.ts +51 -0
- package/responses.js +59 -0
- package/responses.js.map +1 -0
- package/types.d.ts +50 -0
- package/types.js +0 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/resolve.d.ts +21 -0
- package/utils/resolve.js +20 -0
- package/utils/resolve.js.map +1 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allows packages to add properties to the GraphQL resolver contextValue.
|
|
3
|
+
* Register implementations to make things like `context.security`, `context.tenancy`
|
|
4
|
+
* available to resolvers alongside the base `context.container`.
|
|
5
|
+
*/
|
|
6
|
+
export interface IGraphQLContextEnhancer {
|
|
7
|
+
enhance(ctx: Record<string, any>): void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare const GraphQLContextEnhancer: import("@webiny/di").Abstraction<IGraphQLContextEnhancer>;
|
|
10
|
+
export declare namespace GraphQLContextEnhancer {
|
|
11
|
+
type Interface = IGraphQLContextEnhancer;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine/GraphQLContextEnhancer.js","sources":["../../src/engine/GraphQLContextEnhancer.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\n/**\n * Allows packages to add properties to the GraphQL resolver contextValue.\n * Register implementations to make things like `context.security`, `context.tenancy`\n * available to resolvers alongside the base `context.container`.\n */\nexport interface IGraphQLContextEnhancer {\n enhance(ctx: Record<string, any>): void | Promise<void>;\n}\n\nexport const GraphQLContextEnhancer =\n createAbstraction<IGraphQLContextEnhancer>(\"GraphQLContextEnhancer\");\n\nexport namespace GraphQLContextEnhancer {\n export type Interface = IGraphQLContextEnhancer;\n}\n"],"names":["GraphQLContextEnhancer","createAbstraction"],"mappings":";AAWO,MAAMA,yBACTC,kBAA2C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GraphQLSchema } from "graphql";
|
|
2
|
+
/**
|
|
3
|
+
* A schema that is built after context enhancement — use when schema content depends on
|
|
4
|
+
* runtime data (e.g. CMS content models fetched from the database).
|
|
5
|
+
*
|
|
6
|
+
* Registered schemas are merged with the static schema from GraphQLSchemaComposer.
|
|
7
|
+
*/
|
|
8
|
+
export interface IGraphQLContextualSchema {
|
|
9
|
+
build(ctx: Record<string, any>): Promise<GraphQLSchema>;
|
|
10
|
+
}
|
|
11
|
+
export declare const GraphQLContextualSchema: import("@webiny/di").Abstraction<IGraphQLContextualSchema>;
|
|
12
|
+
export declare namespace GraphQLContextualSchema {
|
|
13
|
+
type Interface = IGraphQLContextualSchema;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine/GraphQLContextualSchema.js","sources":["../../src/engine/GraphQLContextualSchema.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { GraphQLSchema } from \"graphql\";\n\n/**\n * A schema that is built after context enhancement — use when schema content depends on\n * runtime data (e.g. CMS content models fetched from the database).\n *\n * Registered schemas are merged with the static schema from GraphQLSchemaComposer.\n */\nexport interface IGraphQLContextualSchema {\n build(ctx: Record<string, any>): Promise<GraphQLSchema>;\n}\n\nexport const GraphQLContextualSchema =\n createAbstraction<IGraphQLContextualSchema>(\"GraphQLContextualSchema\");\n\nexport namespace GraphQLContextualSchema {\n export type Interface = IGraphQLContextualSchema;\n}\n"],"names":["GraphQLContextualSchema","createAbstraction"],"mappings":";AAaO,MAAMA,0BACTC,kBAA4C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Container } from "@webiny/di";
|
|
2
|
+
import { GraphQLEngine as GraphQLEngineAbstraction } from "./abstractions.js";
|
|
3
|
+
import type { IGraphQLSchemaComposer } from "../features/GraphQLSchemaBuilder/abstractions.js";
|
|
4
|
+
import type { IGraphQLContextEnhancer } from "./GraphQLContextEnhancer.js";
|
|
5
|
+
import type { IGraphQLContextualSchema } from "./GraphQLContextualSchema.js";
|
|
6
|
+
declare class GraphQLEngineImpl implements GraphQLEngineAbstraction.Interface {
|
|
7
|
+
private composer;
|
|
8
|
+
private container;
|
|
9
|
+
private enhancers;
|
|
10
|
+
private contextualSchemas;
|
|
11
|
+
constructor(composer: IGraphQLSchemaComposer, container: Container, enhancers: IGraphQLContextEnhancer[], contextualSchemas: IGraphQLContextualSchema[]);
|
|
12
|
+
execute(body: any): Promise<any>;
|
|
13
|
+
private buildContext;
|
|
14
|
+
private buildContextualSchemas;
|
|
15
|
+
private buildSchema;
|
|
16
|
+
private executeOne;
|
|
17
|
+
}
|
|
18
|
+
export declare const GraphQLEngine: typeof GraphQLEngineImpl & {
|
|
19
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGraphQLEngine>;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { graphql } from "graphql";
|
|
2
|
+
import { makeExecutableSchema, mergeSchemas } from "@graphql-tools/schema";
|
|
3
|
+
import { mergeResolvers } from "@graphql-tools/merge";
|
|
4
|
+
import { RequestContainer } from "@webiny/event-handler-core";
|
|
5
|
+
import { GraphQLEngine } from "./abstractions.js";
|
|
6
|
+
import { GraphQLContextEnhancer } from "./GraphQLContextEnhancer.js";
|
|
7
|
+
import { GraphQLContextualSchema } from "./GraphQLContextualSchema.js";
|
|
8
|
+
import { GraphQLSchemaComposer } from "../features/GraphQLSchemaBuilder/abstractions.js";
|
|
9
|
+
import { ResolverDecoration } from "../ResolverDecoration.js";
|
|
10
|
+
import { createRequestBody } from "../createRequestBody.js";
|
|
11
|
+
class GraphQLEngineImpl {
|
|
12
|
+
constructor(composer, container, enhancers, contextualSchemas){
|
|
13
|
+
this.composer = composer;
|
|
14
|
+
this.container = container;
|
|
15
|
+
this.enhancers = enhancers;
|
|
16
|
+
this.contextualSchemas = contextualSchemas;
|
|
17
|
+
}
|
|
18
|
+
async execute(body) {
|
|
19
|
+
const ctx = await this.buildContext();
|
|
20
|
+
const extraSchemas = await this.buildContextualSchemas(ctx);
|
|
21
|
+
const schemaConfig = await this.composer.build(ctx);
|
|
22
|
+
const resolverDecoration = new ResolverDecoration();
|
|
23
|
+
if (schemaConfig.resolverDecorators) resolverDecoration.addDecorators(schemaConfig.resolverDecorators);
|
|
24
|
+
const typeDefs = `type Query\ntype Mutation\n${schemaConfig.typeDefs ?? ""}`;
|
|
25
|
+
const staticSchema = makeExecutableSchema({
|
|
26
|
+
typeDefs,
|
|
27
|
+
resolvers: resolverDecoration.decorateResolvers(mergeResolvers([
|
|
28
|
+
schemaConfig.resolvers ?? {}
|
|
29
|
+
])),
|
|
30
|
+
assumeValidSDL: true,
|
|
31
|
+
inheritResolversFromInterfaces: true
|
|
32
|
+
});
|
|
33
|
+
const schema = await this.buildSchema(staticSchema, extraSchemas);
|
|
34
|
+
const parsed = createRequestBody(body);
|
|
35
|
+
if (!Array.isArray(parsed)) return this.executeOne(parsed, schema, ctx);
|
|
36
|
+
const results = [];
|
|
37
|
+
for (const b of parsed)results.push(await this.executeOne(b, schema, ctx));
|
|
38
|
+
return results;
|
|
39
|
+
}
|
|
40
|
+
async buildContext() {
|
|
41
|
+
const ctx = {
|
|
42
|
+
container: this.container
|
|
43
|
+
};
|
|
44
|
+
for (const enhancer of this.enhancers)await enhancer.enhance(ctx);
|
|
45
|
+
return ctx;
|
|
46
|
+
}
|
|
47
|
+
async buildContextualSchemas(ctx) {
|
|
48
|
+
if (0 === this.contextualSchemas.length) return [];
|
|
49
|
+
const schemas = [];
|
|
50
|
+
for (const s of this.contextualSchemas)schemas.push(await s.build(ctx));
|
|
51
|
+
return schemas;
|
|
52
|
+
}
|
|
53
|
+
async buildSchema(staticSchema, extraSchemas) {
|
|
54
|
+
if (0 === extraSchemas.length) return staticSchema;
|
|
55
|
+
return mergeSchemas({
|
|
56
|
+
schemas: [
|
|
57
|
+
staticSchema,
|
|
58
|
+
...extraSchemas
|
|
59
|
+
]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async executeOne(body, schema, ctx) {
|
|
63
|
+
const { query, variables, operationName } = body;
|
|
64
|
+
return graphql({
|
|
65
|
+
schema,
|
|
66
|
+
source: query,
|
|
67
|
+
rootValue: {},
|
|
68
|
+
contextValue: ctx,
|
|
69
|
+
variableValues: variables ?? void 0,
|
|
70
|
+
operationName: operationName ?? void 0
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const GraphQLEngine_GraphQLEngine = GraphQLEngine.createImplementation({
|
|
75
|
+
implementation: GraphQLEngineImpl,
|
|
76
|
+
dependencies: [
|
|
77
|
+
GraphQLSchemaComposer,
|
|
78
|
+
RequestContainer,
|
|
79
|
+
[
|
|
80
|
+
GraphQLContextEnhancer,
|
|
81
|
+
{
|
|
82
|
+
multiple: true
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
GraphQLContextualSchema,
|
|
87
|
+
{
|
|
88
|
+
multiple: true
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
]
|
|
92
|
+
});
|
|
93
|
+
export { GraphQLEngine_GraphQLEngine as GraphQLEngine };
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=GraphQLEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine/GraphQLEngine.js","sources":["../../src/engine/GraphQLEngine.ts"],"sourcesContent":["import { graphql } from \"graphql\";\nimport { makeExecutableSchema, mergeSchemas } from \"@graphql-tools/schema\";\nimport { mergeResolvers } from \"@graphql-tools/merge\";\nimport { Container } from \"@webiny/di\";\nimport { RequestContainer } from \"@webiny/event-handler-core\";\nimport { GraphQLEngine as GraphQLEngineAbstraction } from \"./abstractions.js\";\nimport { GraphQLContextEnhancer } from \"./GraphQLContextEnhancer.js\";\nimport { GraphQLContextualSchema } from \"./GraphQLContextualSchema.js\";\nimport { GraphQLSchemaComposer } from \"~/features/GraphQLSchemaBuilder/abstractions.js\";\nimport { ResolverDecoration } from \"~/ResolverDecoration.js\";\nimport { createRequestBody } from \"~/createRequestBody.js\";\nimport type { IGraphQLSchemaComposer } from \"~/features/GraphQLSchemaBuilder/abstractions.js\";\nimport type { IGraphQLContextEnhancer } from \"./GraphQLContextEnhancer.js\";\nimport type { IGraphQLContextualSchema } from \"./GraphQLContextualSchema.js\";\nimport type { GraphQLRequestBody } from \"~/types.js\";\nimport type { GraphQLSchema } from \"graphql\";\n\nclass GraphQLEngineImpl implements GraphQLEngineAbstraction.Interface {\n constructor(\n private composer: IGraphQLSchemaComposer,\n private container: Container,\n private enhancers: IGraphQLContextEnhancer[],\n private contextualSchemas: IGraphQLContextualSchema[]\n ) {}\n\n async execute(body: any): Promise<any> {\n // Build context first — enhancers may be async (e.g. CMS storage init)\n const ctx = await this.buildContext();\n\n // NOTE: the post-auth RequestContextInitializers (CMS facade, FileModel, ...) are run once\n // per request by the HTTP layer (RequestContextInitializerDecorator in event-handler-core),\n // before the router dispatches — so they cover every route, not just GraphQL. Their side-\n // effects are container registrations, which persist and are resolvable here.\n\n // Run contextual schemas BEFORE composer.build() so that any CoreGraphQLSchemaFactory\n // registrations they make (e.g. ACO folder schema plugins) are picked up by GraphQLSchemaComposer.\n const extraSchemas = await this.buildContextualSchemas(ctx);\n\n const schemaConfig = await this.composer.build(ctx);\n\n const resolverDecoration = new ResolverDecoration();\n if (schemaConfig.resolverDecorators) {\n resolverDecoration.addDecorators(schemaConfig.resolverDecorators);\n }\n\n // Always provide base root types so that `extend type Query/Mutation` works without\n // requiring callers to define them. With assumeValidSDL:true, empty base types are\n // allowed at build time; graphql() then returns schema-validation errors at execution\n // time (e.g. \"Type Query must define one or more fields.\") when no fields are registered.\n const typeDefs = `type Query\\ntype Mutation\\n${schemaConfig.typeDefs ?? \"\"}`;\n const staticSchema = makeExecutableSchema({\n typeDefs,\n resolvers: resolverDecoration.decorateResolvers(\n mergeResolvers([schemaConfig.resolvers ?? {}])\n ),\n assumeValidSDL: true,\n inheritResolversFromInterfaces: true\n });\n\n const schema = await this.buildSchema(staticSchema, extraSchemas);\n const parsed = createRequestBody(body);\n\n if (!Array.isArray(parsed)) {\n return this.executeOne(parsed, schema, ctx);\n }\n // Run sequentially so per-request state (e.g. ctx.debug.logs) is scoped per query.\n const results = [];\n for (const b of parsed) {\n results.push(await this.executeOne(b, schema, ctx));\n }\n return results;\n }\n\n private async buildContext(): Promise<Record<string, any>> {\n const ctx: Record<string, any> = { container: this.container };\n for (const enhancer of this.enhancers) {\n await enhancer.enhance(ctx);\n }\n return ctx;\n }\n\n private async buildContextualSchemas(ctx: Record<string, any>): Promise<GraphQLSchema[]> {\n if (this.contextualSchemas.length === 0) {\n return [];\n }\n // Sequential — schemas may have ordering dependencies (e.g. Aco needs ctx.cms from HeadlessCms).\n const schemas: GraphQLSchema[] = [];\n for (const s of this.contextualSchemas) {\n schemas.push(await s.build(ctx));\n }\n return schemas;\n }\n\n private async buildSchema(\n staticSchema: GraphQLSchema,\n extraSchemas: GraphQLSchema[]\n ): Promise<GraphQLSchema> {\n if (extraSchemas.length === 0) {\n return staticSchema;\n }\n return mergeSchemas({ schemas: [staticSchema, ...extraSchemas] });\n }\n\n private async executeOne(\n body: GraphQLRequestBody,\n schema: GraphQLSchema,\n ctx: Record<string, any>\n ): Promise<any> {\n const { query, variables, operationName } = body;\n\n return graphql({\n schema,\n source: query,\n rootValue: {},\n contextValue: ctx,\n variableValues: variables ?? undefined,\n operationName: operationName ?? undefined\n });\n }\n}\n\nexport const GraphQLEngine = GraphQLEngineAbstraction.createImplementation({\n implementation: GraphQLEngineImpl,\n dependencies: [\n GraphQLSchemaComposer,\n RequestContainer,\n [GraphQLContextEnhancer, { multiple: true }],\n [GraphQLContextualSchema, { multiple: true }]\n ]\n});\n"],"names":["GraphQLEngineImpl","composer","container","enhancers","contextualSchemas","body","ctx","extraSchemas","schemaConfig","resolverDecoration","ResolverDecoration","typeDefs","staticSchema","makeExecutableSchema","mergeResolvers","schema","parsed","createRequestBody","Array","results","b","enhancer","schemas","s","mergeSchemas","query","variables","operationName","graphql","undefined","GraphQLEngine","GraphQLEngineAbstraction","GraphQLSchemaComposer","RequestContainer","GraphQLContextEnhancer","GraphQLContextualSchema"],"mappings":";;;;;;;;;;AAiBA,MAAMA;IACF,YACYC,QAAgC,EAChCC,SAAoB,EACpBC,SAAoC,EACpCC,iBAA6C,CACvD;aAJUH,QAAQ,GAARA;aACAC,SAAS,GAATA;aACAC,SAAS,GAATA;aACAC,iBAAiB,GAAjBA;IACT;IAEH,MAAM,QAAQC,IAAS,EAAgB;QAEnC,MAAMC,MAAM,MAAM,IAAI,CAAC,YAAY;QASnC,MAAMC,eAAe,MAAM,IAAI,CAAC,sBAAsB,CAACD;QAEvD,MAAME,eAAe,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAACF;QAE/C,MAAMG,qBAAqB,IAAIC;QAC/B,IAAIF,aAAa,kBAAkB,EAC/BC,mBAAmB,aAAa,CAACD,aAAa,kBAAkB;QAOpE,MAAMG,WAAW,CAAC,2BAA2B,EAAEH,aAAa,QAAQ,IAAI,IAAI;QAC5E,MAAMI,eAAeC,qBAAqB;YACtCF;YACA,WAAWF,mBAAmB,iBAAiB,CAC3CK,eAAe;gBAACN,aAAa,SAAS,IAAI,CAAC;aAAE;YAEjD,gBAAgB;YAChB,gCAAgC;QACpC;QAEA,MAAMO,SAAS,MAAM,IAAI,CAAC,WAAW,CAACH,cAAcL;QACpD,MAAMS,SAASC,kBAAkBZ;QAEjC,IAAI,CAACa,MAAM,OAAO,CAACF,SACf,OAAO,IAAI,CAAC,UAAU,CAACA,QAAQD,QAAQT;QAG3C,MAAMa,UAAU,EAAE;QAClB,KAAK,MAAMC,KAAKJ,OACZG,QAAQ,IAAI,CAAC,MAAM,IAAI,CAAC,UAAU,CAACC,GAAGL,QAAQT;QAElD,OAAOa;IACX;IAEA,MAAc,eAA6C;QACvD,MAAMb,MAA2B;YAAE,WAAW,IAAI,CAAC,SAAS;QAAC;QAC7D,KAAK,MAAMe,YAAY,IAAI,CAAC,SAAS,CACjC,MAAMA,SAAS,OAAO,CAACf;QAE3B,OAAOA;IACX;IAEA,MAAc,uBAAuBA,GAAwB,EAA4B;QACrF,IAAI,AAAkC,MAAlC,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAC7B,OAAO,EAAE;QAGb,MAAMgB,UAA2B,EAAE;QACnC,KAAK,MAAMC,KAAK,IAAI,CAAC,iBAAiB,CAClCD,QAAQ,IAAI,CAAC,MAAMC,EAAE,KAAK,CAACjB;QAE/B,OAAOgB;IACX;IAEA,MAAc,YACVV,YAA2B,EAC3BL,YAA6B,EACP;QACtB,IAAIA,AAAwB,MAAxBA,aAAa,MAAM,EACnB,OAAOK;QAEX,OAAOY,aAAa;YAAE,SAAS;gBAACZ;mBAAiBL;aAAa;QAAC;IACnE;IAEA,MAAc,WACVF,IAAwB,EACxBU,MAAqB,EACrBT,GAAwB,EACZ;QACZ,MAAM,EAAEmB,KAAK,EAAEC,SAAS,EAAEC,aAAa,EAAE,GAAGtB;QAE5C,OAAOuB,QAAQ;YACXb;YACA,QAAQU;YACR,WAAW,CAAC;YACZ,cAAcnB;YACd,gBAAgBoB,aAAaG;YAC7B,eAAeF,iBAAiBE;QACpC;IACJ;AACJ;AAEO,MAAMC,8BAAgBC,cAAAA,oBAA6C,CAAC;IACvE,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACA;YAACC;YAAwB;gBAAE,UAAU;YAAK;SAAE;QAC5C;YAACC;YAAyB;gBAAE,UAAU;YAAK;SAAE;KAChD;AACL"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { GraphQLSchemaComposerFeature } from "../features/GraphQLSchemaBuilder/feature.js";
|
|
3
|
+
import { GraphQLEngine } from "./GraphQLEngine.js";
|
|
4
|
+
import { GraphQLRoute } from "./GraphQLRoute.js";
|
|
5
|
+
const GraphQLEngineFeature = createFeature({
|
|
6
|
+
name: "GraphQLEngine",
|
|
7
|
+
register (container) {
|
|
8
|
+
GraphQLSchemaComposerFeature.register(container);
|
|
9
|
+
container.register(GraphQLEngine);
|
|
10
|
+
container.register(GraphQLRoute);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
export { GraphQLEngineFeature };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=GraphQLEngineFeature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine/GraphQLEngineFeature.js","sources":["../../src/engine/GraphQLEngineFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GraphQLSchemaComposerFeature } from \"~/features/GraphQLSchemaBuilder/feature.js\";\nimport { GraphQLEngine } from \"./GraphQLEngine.js\";\nimport { GraphQLRoute } from \"./GraphQLRoute.js\";\n\nexport const GraphQLEngineFeature = createFeature({\n name: \"GraphQLEngine\",\n register(container) {\n GraphQLSchemaComposerFeature.register(container);\n container.register(GraphQLEngine);\n container.register(GraphQLRoute);\n }\n});\n"],"names":["GraphQLEngineFeature","createFeature","container","GraphQLSchemaComposerFeature","GraphQLEngine","GraphQLRoute"],"mappings":";;;;AAKO,MAAMA,uBAAuBC,cAAc;IAC9C,MAAM;IACN,UAASC,SAAS;QACdC,6BAA6B,QAAQ,CAACD;QACtCA,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;IACvB;AACJ"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HttpRoute } from "@webiny/event-handler-core";
|
|
2
|
+
import type { IHttpRequest, IHttpResponse } from "@webiny/event-handler-core";
|
|
3
|
+
import type { IGraphQLEngine } from "./abstractions.js";
|
|
4
|
+
declare class GraphQLRouteImpl implements HttpRoute.Interface {
|
|
5
|
+
private engine;
|
|
6
|
+
readonly method = "POST";
|
|
7
|
+
readonly path = "/graphql";
|
|
8
|
+
constructor(engine: IGraphQLEngine);
|
|
9
|
+
handle(request: IHttpRequest): Promise<IHttpResponse>;
|
|
10
|
+
}
|
|
11
|
+
export declare const GraphQLRoute: typeof GraphQLRouteImpl & {
|
|
12
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/event-handler-core").IHttpRoute>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { HttpRoute } from "@webiny/event-handler-core";
|
|
2
|
+
import { GraphQLEngine } from "./abstractions.js";
|
|
3
|
+
class GraphQLRouteImpl {
|
|
4
|
+
constructor(engine){
|
|
5
|
+
this.engine = engine;
|
|
6
|
+
this.method = "POST";
|
|
7
|
+
this.path = "/graphql";
|
|
8
|
+
}
|
|
9
|
+
async handle(request) {
|
|
10
|
+
const result = await this.engine.execute(request.body);
|
|
11
|
+
return {
|
|
12
|
+
statusCode: 200,
|
|
13
|
+
headers: {
|
|
14
|
+
"Content-Type": "application/json"
|
|
15
|
+
},
|
|
16
|
+
body: result
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const GraphQLRoute = HttpRoute.createImplementation({
|
|
21
|
+
implementation: GraphQLRouteImpl,
|
|
22
|
+
dependencies: [
|
|
23
|
+
GraphQLEngine
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
export { GraphQLRoute };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=GraphQLRoute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine/GraphQLRoute.js","sources":["../../src/engine/GraphQLRoute.ts"],"sourcesContent":["import { HttpRoute } from \"@webiny/event-handler-core\";\nimport { GraphQLEngine } from \"./abstractions.js\";\nimport type { IHttpRequest, IHttpResponse } from \"@webiny/event-handler-core\";\nimport type { IGraphQLEngine } from \"./abstractions.js\";\n\nclass GraphQLRouteImpl implements HttpRoute.Interface {\n readonly method = \"POST\";\n readonly path = \"/graphql\";\n\n constructor(private engine: IGraphQLEngine) {}\n\n async handle(request: IHttpRequest): Promise<IHttpResponse> {\n const result = await this.engine.execute(request.body);\n return {\n statusCode: 200,\n headers: { \"Content-Type\": \"application/json\" },\n body: result\n };\n }\n}\n\nexport const GraphQLRoute = HttpRoute.createImplementation({\n implementation: GraphQLRouteImpl,\n dependencies: [GraphQLEngine]\n});\n"],"names":["GraphQLRouteImpl","engine","request","result","GraphQLRoute","HttpRoute","GraphQLEngine"],"mappings":";;AAKA,MAAMA;IAIF,YAAoBC,MAAsB,CAAE;aAAxBA,MAAM,GAANA;aAHX,MAAM,GAAG;aACT,IAAI,GAAG;IAE6B;IAE7C,MAAM,OAAOC,OAAqB,EAA0B;QACxD,MAAMC,SAAS,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAACD,QAAQ,IAAI;QACrD,OAAO;YACH,YAAY;YACZ,SAAS;gBAAE,gBAAgB;YAAmB;YAC9C,MAAMC;QACV;IACJ;AACJ;AAEO,MAAMC,eAAeC,UAAU,oBAAoB,CAAC;IACvD,gBAAgBL;IAChB,cAAc;QAACM;KAAc;AACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine/abstractions.js","sources":["../../src/engine/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IGraphQLEngine {\n execute(body: any): Promise<any>;\n}\n\nexport const GraphQLEngine = createAbstraction<IGraphQLEngine>(\"GraphQLEngine\");\n\nexport namespace GraphQLEngine {\n export type Interface = IGraphQLEngine;\n}\n"],"names":["GraphQLEngine","createAbstraction"],"mappings":";AAMO,MAAMA,gBAAgBC,kBAAkC"}
|
package/engine/index.js
ADDED
package/errors.d.ts
ADDED
package/errors.js
ADDED
package/errors.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sources":["../src/errors.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport class NotFoundError extends WebinyError {\n constructor(message = \"Not found.\") {\n super(message, \"NOT_FOUND\");\n }\n}\n"],"names":["NotFoundError","WebinyError","message"],"mappings":";AAEO,MAAMA,sBAAsBC;IAC/B,YAAYC,UAAU,YAAY,CAAE;QAChC,KAAK,CAACA,SAAS;IACnB;AACJ"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { GraphQLSchemaBuilder as Abstraction } from "./abstractions.js";
|
|
2
|
+
import type { IGraphQLSchema } from "../../graphql/abstractions.public.js";
|
|
3
|
+
import type { ResolverDecorator } from "../../types.js";
|
|
4
|
+
export declare class GraphQLSchemaBuilder implements Abstraction.Interface {
|
|
5
|
+
private readonly typeDefsArray;
|
|
6
|
+
private readonly resolvers;
|
|
7
|
+
private readonly resolverDecorators;
|
|
8
|
+
addTypeDefs(typeDefs: string): this;
|
|
9
|
+
addResolver<TArgs = any>(config: Abstraction.Config<TArgs>): this;
|
|
10
|
+
addLegacyResolvers(resolvers: Record<string, any>, prefix?: string): this;
|
|
11
|
+
/**
|
|
12
|
+
* @internal This method needs revisiting, to align with DI concepts.
|
|
13
|
+
*/
|
|
14
|
+
addResolverDecorator(path: string, decorator: ResolverDecorator): this;
|
|
15
|
+
build(): IGraphQLSchema;
|
|
16
|
+
private setResolverAtPath;
|
|
17
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
class GraphQLSchemaBuilder {
|
|
2
|
+
addTypeDefs(typeDefs) {
|
|
3
|
+
this.typeDefsArray.push(typeDefs);
|
|
4
|
+
return this;
|
|
5
|
+
}
|
|
6
|
+
addResolver(config) {
|
|
7
|
+
const { path, dependencies = [], resolver } = config;
|
|
8
|
+
const pathParts = path.split(".");
|
|
9
|
+
const graphqlResolver = (parent, args, context, info)=>{
|
|
10
|
+
const resolvedDeps = dependencies.map((dep)=>{
|
|
11
|
+
const [abstraction] = Array.isArray(dep) ? dep : [
|
|
12
|
+
dep
|
|
13
|
+
];
|
|
14
|
+
return context.container.resolve(abstraction);
|
|
15
|
+
});
|
|
16
|
+
const actualResolver = resolver(...resolvedDeps);
|
|
17
|
+
return actualResolver({
|
|
18
|
+
parent,
|
|
19
|
+
args,
|
|
20
|
+
context,
|
|
21
|
+
info
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
this.setResolverAtPath(pathParts, graphqlResolver);
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
addLegacyResolvers(resolvers, prefix = "") {
|
|
28
|
+
for (const [key, value] of Object.entries(resolvers)){
|
|
29
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
30
|
+
if ("function" == typeof value) {
|
|
31
|
+
const fn = value;
|
|
32
|
+
this.addResolver({
|
|
33
|
+
path,
|
|
34
|
+
dependencies: [],
|
|
35
|
+
resolver: ()=>({ parent, args, context, info })=>fn(parent, args, context, info)
|
|
36
|
+
});
|
|
37
|
+
} else if ("object" == typeof value && null !== value) this.addLegacyResolvers(value, path);
|
|
38
|
+
}
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
addResolverDecorator(path, decorator) {
|
|
42
|
+
if (!this.resolverDecorators[path]) this.resolverDecorators[path] = [];
|
|
43
|
+
this.resolverDecorators[path].push(decorator);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
build() {
|
|
47
|
+
return {
|
|
48
|
+
typeDefs: this.typeDefsArray.join("\n"),
|
|
49
|
+
resolvers: this.resolvers,
|
|
50
|
+
resolverDecorators: this.resolverDecorators
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
setResolverAtPath(pathParts, resolver) {
|
|
54
|
+
let current = this.resolvers;
|
|
55
|
+
for(let i = 0; i < pathParts.length - 1; i++){
|
|
56
|
+
const part = pathParts[i];
|
|
57
|
+
if (!current[part]) current[part] = {};
|
|
58
|
+
current = current[part];
|
|
59
|
+
}
|
|
60
|
+
const finalKey = pathParts[pathParts.length - 1];
|
|
61
|
+
current[finalKey] = resolver;
|
|
62
|
+
}
|
|
63
|
+
constructor(){
|
|
64
|
+
this.typeDefsArray = [];
|
|
65
|
+
this.resolvers = {};
|
|
66
|
+
this.resolverDecorators = {};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export { GraphQLSchemaBuilder };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=GraphQLSchemaBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js","sources":["../../../src/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.ts"],"sourcesContent":["import type { GraphQLSchemaBuilder as Abstraction } from \"./abstractions.js\";\nimport type { IGraphQLSchema } from \"~/graphql/abstractions.public.js\";\nimport type { ResolverDecorator, ResolverDecorators, Resolvers } from \"~/types.js\";\nimport type { Dependency } from \"@webiny/di\";\n\nexport class GraphQLSchemaBuilder implements Abstraction.Interface {\n private readonly typeDefsArray: string[] = [];\n private readonly resolvers: Resolvers<any> = {};\n private readonly resolverDecorators: ResolverDecorators = {};\n\n addTypeDefs(typeDefs: string): this {\n this.typeDefsArray.push(typeDefs);\n return this;\n }\n\n addResolver<TArgs = any>(config: Abstraction.Config<TArgs>): this {\n const { path, dependencies = [], resolver } = config;\n\n const pathParts = path.split(\".\");\n\n const graphqlResolver = (parent: any, args: TArgs, context: any, info: any) => {\n const resolvedDeps = dependencies.map((dep: Dependency) => {\n const [abstraction] = Array.isArray(dep) ? dep : [dep];\n return context.container.resolve(abstraction);\n });\n\n const actualResolver = resolver(...resolvedDeps);\n\n return actualResolver({ parent, args, context, info });\n };\n\n this.setResolverAtPath(pathParts, graphqlResolver);\n\n return this;\n }\n\n addLegacyResolvers(resolvers: Record<string, any>, prefix = \"\"): this {\n for (const [key, value] of Object.entries(resolvers)) {\n const path = prefix ? `${prefix}.${key}` : key;\n if (typeof value === \"function\") {\n const fn = value;\n this.addResolver({\n path,\n dependencies: [],\n resolver:\n () =>\n ({ parent, args, context, info }: any) =>\n fn(parent, args, context, info)\n });\n } else if (typeof value === \"object\" && value !== null) {\n this.addLegacyResolvers(value, path);\n }\n }\n return this;\n }\n\n /**\n * @internal This method needs revisiting, to align with DI concepts.\n */\n addResolverDecorator(path: string, decorator: ResolverDecorator): this {\n if (!this.resolverDecorators[path]) {\n this.resolverDecorators[path] = [];\n }\n this.resolverDecorators[path].push(decorator);\n return this;\n }\n\n build(): IGraphQLSchema {\n return {\n typeDefs: this.typeDefsArray.join(\"\\n\"),\n resolvers: this.resolvers,\n resolverDecorators: this.resolverDecorators\n };\n }\n\n private setResolverAtPath(pathParts: string[], resolver: any): void {\n let current: any = this.resolvers;\n\n for (let i = 0; i < pathParts.length - 1; i++) {\n const part = pathParts[i];\n if (!current[part]) {\n current[part] = {};\n }\n current = current[part];\n }\n\n const finalKey = pathParts[pathParts.length - 1];\n current[finalKey] = resolver;\n }\n}\n"],"names":["GraphQLSchemaBuilder","typeDefs","config","path","dependencies","resolver","pathParts","graphqlResolver","parent","args","context","info","resolvedDeps","dep","abstraction","Array","actualResolver","resolvers","prefix","key","value","Object","fn","decorator","current","i","part","finalKey"],"mappings":"AAKO,MAAMA;IAKT,YAAYC,QAAgB,EAAQ;QAChC,IAAI,CAAC,aAAa,CAAC,IAAI,CAACA;QACxB,OAAO,IAAI;IACf;IAEA,YAAyBC,MAAiC,EAAQ;QAC9D,MAAM,EAAEC,IAAI,EAAEC,eAAe,EAAE,EAAEC,QAAQ,EAAE,GAAGH;QAE9C,MAAMI,YAAYH,KAAK,KAAK,CAAC;QAE7B,MAAMI,kBAAkB,CAACC,QAAaC,MAAaC,SAAcC;YAC7D,MAAMC,eAAeR,aAAa,GAAG,CAAC,CAACS;gBACnC,MAAM,CAACC,YAAY,GAAGC,MAAM,OAAO,CAACF,OAAOA,MAAM;oBAACA;iBAAI;gBACtD,OAAOH,QAAQ,SAAS,CAAC,OAAO,CAACI;YACrC;YAEA,MAAME,iBAAiBX,YAAYO;YAEnC,OAAOI,eAAe;gBAAER;gBAAQC;gBAAMC;gBAASC;YAAK;QACxD;QAEA,IAAI,CAAC,iBAAiB,CAACL,WAAWC;QAElC,OAAO,IAAI;IACf;IAEA,mBAAmBU,SAA8B,EAAEC,SAAS,EAAE,EAAQ;QAClE,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAO,OAAO,CAACJ,WAAY;YAClD,MAAMd,OAAOe,SAAS,GAAGA,OAAO,CAAC,EAAEC,KAAK,GAAGA;YAC3C,IAAI,AAAiB,cAAjB,OAAOC,OAAsB;gBAC7B,MAAME,KAAKF;gBACX,IAAI,CAAC,WAAW,CAAC;oBACbjB;oBACA,cAAc,EAAE;oBAChB,UACI,IACA,CAAC,EAAEK,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,IAAI,EAAO,GACjCW,GAAGd,QAAQC,MAAMC,SAASC;gBACtC;YACJ,OAAO,IAAI,AAAiB,YAAjB,OAAOS,SAAsBA,AAAU,SAAVA,OACpC,IAAI,CAAC,kBAAkB,CAACA,OAAOjB;QAEvC;QACA,OAAO,IAAI;IACf;IAKA,qBAAqBA,IAAY,EAAEoB,SAA4B,EAAQ;QACnE,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAACpB,KAAK,EAC9B,IAAI,CAAC,kBAAkB,CAACA,KAAK,GAAG,EAAE;QAEtC,IAAI,CAAC,kBAAkB,CAACA,KAAK,CAAC,IAAI,CAACoB;QACnC,OAAO,IAAI;IACf;IAEA,QAAwB;QACpB,OAAO;YACH,UAAU,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YAClC,WAAW,IAAI,CAAC,SAAS;YACzB,oBAAoB,IAAI,CAAC,kBAAkB;QAC/C;IACJ;IAEQ,kBAAkBjB,SAAmB,EAAED,QAAa,EAAQ;QAChE,IAAImB,UAAe,IAAI,CAAC,SAAS;QAEjC,IAAK,IAAIC,IAAI,GAAGA,IAAInB,UAAU,MAAM,GAAG,GAAGmB,IAAK;YAC3C,MAAMC,OAAOpB,SAAS,CAACmB,EAAE;YACzB,IAAI,CAACD,OAAO,CAACE,KAAK,EACdF,OAAO,CAACE,KAAK,GAAG,CAAC;YAErBF,UAAUA,OAAO,CAACE,KAAK;QAC3B;QAEA,MAAMC,WAAWrB,SAAS,CAACA,UAAU,MAAM,GAAG,EAAE;QAChDkB,OAAO,CAACG,SAAS,GAAGtB;IACxB;;aAlFiB,aAAa,GAAa,EAAE;aAC5B,SAAS,GAAmB,CAAC;aAC7B,kBAAkB,GAAuB,CAAC;;AAiF/D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Container } from "@webiny/di";
|
|
2
|
+
import { GraphQLSchemaComposer as Abstraction } from "./abstractions.js";
|
|
3
|
+
import type { IGraphQLSchema } from "../../graphql/abstractions.public.js";
|
|
4
|
+
declare class GraphQLSchemaComposerImpl implements Abstraction.Interface {
|
|
5
|
+
private container;
|
|
6
|
+
constructor(container: Container);
|
|
7
|
+
build(ctx?: Record<string, any>): Promise<IGraphQLSchema>;
|
|
8
|
+
}
|
|
9
|
+
export declare const GraphQLSchemaComposer: typeof GraphQLSchemaComposerImpl & {
|
|
10
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGraphQLSchemaComposer>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { RequestContainer } from "@webiny/event-handler-core";
|
|
2
|
+
import { GraphQLSchemaComposer } from "./abstractions.js";
|
|
3
|
+
import { CoreGraphQLSchemaFactory, GraphQLSchemaFactory } from "../../graphql/abstractions.js";
|
|
4
|
+
import { GraphQLSchemaBuilder } from "./GraphQLSchemaBuilder.js";
|
|
5
|
+
class GraphQLSchemaComposerImpl {
|
|
6
|
+
constructor(container){
|
|
7
|
+
this.container = container;
|
|
8
|
+
}
|
|
9
|
+
async build(ctx) {
|
|
10
|
+
const builder = new GraphQLSchemaBuilder();
|
|
11
|
+
const coreSchemas = this.container.resolveAll(CoreGraphQLSchemaFactory);
|
|
12
|
+
const userSchemas = this.container.resolveAll(GraphQLSchemaFactory);
|
|
13
|
+
for (const factory of coreSchemas)await factory.execute(builder, ctx);
|
|
14
|
+
for (const factory of userSchemas)await factory.execute(builder);
|
|
15
|
+
return builder.build();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const GraphQLSchemaComposer_GraphQLSchemaComposer = GraphQLSchemaComposer.createImplementation({
|
|
19
|
+
implementation: GraphQLSchemaComposerImpl,
|
|
20
|
+
dependencies: [
|
|
21
|
+
RequestContainer
|
|
22
|
+
]
|
|
23
|
+
});
|
|
24
|
+
export { GraphQLSchemaComposer_GraphQLSchemaComposer as GraphQLSchemaComposer };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=GraphQLSchemaComposer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js","sources":["../../../src/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.ts"],"sourcesContent":["import { Container } from \"@webiny/di\";\nimport { RequestContainer } from \"@webiny/event-handler-core\";\nimport { GraphQLSchemaComposer as Abstraction } from \"./abstractions.js\";\nimport { GraphQLSchemaFactory, CoreGraphQLSchemaFactory } from \"~/graphql/abstractions.js\";\nimport { GraphQLSchemaBuilder } from \"./GraphQLSchemaBuilder.js\";\nimport type { IGraphQLSchema } from \"~/graphql/abstractions.public.js\";\n\nclass GraphQLSchemaComposerImpl implements Abstraction.Interface {\n constructor(private container: Container) {}\n\n async build(ctx?: Record<string, any>): Promise<IGraphQLSchema> {\n const builder = new GraphQLSchemaBuilder();\n\n // Resolve lazily so factories registered during enhance() (e.g. by extensions) are included.\n const coreSchemas = this.container.resolveAll(CoreGraphQLSchemaFactory);\n const userSchemas = this.container.resolveAll(GraphQLSchemaFactory);\n\n for (const factory of coreSchemas) {\n await factory.execute(builder, ctx);\n }\n\n for (const factory of userSchemas) {\n await factory.execute(builder);\n }\n\n return builder.build();\n }\n}\n\nexport const GraphQLSchemaComposer = Abstraction.createImplementation({\n implementation: GraphQLSchemaComposerImpl,\n dependencies: [RequestContainer]\n});\n"],"names":["GraphQLSchemaComposerImpl","container","ctx","builder","GraphQLSchemaBuilder","coreSchemas","CoreGraphQLSchemaFactory","userSchemas","GraphQLSchemaFactory","factory","GraphQLSchemaComposer","Abstraction","RequestContainer"],"mappings":";;;;AAOA,MAAMA;IACF,YAAoBC,SAAoB,CAAE;aAAtBA,SAAS,GAATA;IAAuB;IAE3C,MAAM,MAAMC,GAAyB,EAA2B;QAC5D,MAAMC,UAAU,IAAIC;QAGpB,MAAMC,cAAc,IAAI,CAAC,SAAS,CAAC,UAAU,CAACC;QAC9C,MAAMC,cAAc,IAAI,CAAC,SAAS,CAAC,UAAU,CAACC;QAE9C,KAAK,MAAMC,WAAWJ,YAClB,MAAMI,QAAQ,OAAO,CAACN,SAASD;QAGnC,KAAK,MAAMO,WAAWF,YAClB,MAAME,QAAQ,OAAO,CAACN;QAG1B,OAAOA,QAAQ,KAAK;IACxB;AACJ;AAEO,MAAMO,8CAAwBC,sBAAAA,oBAAgC,CAAC;IAClE,gBAAgBX;IAChB,cAAc;QAACY;KAAiB;AACpC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ResolverDecorator, TypeDefs } from "../../types.js";
|
|
2
|
+
import type { Dependency } from "@webiny/di";
|
|
3
|
+
import type { IGraphQLSchema } from "../../graphql/abstractions.public.js";
|
|
4
|
+
export interface ResolverConfig<TArgs = any, TParent = any> {
|
|
5
|
+
path: string;
|
|
6
|
+
dependencies?: Dependency[];
|
|
7
|
+
resolver: (...resolvedDeps: any[]) => (params: {
|
|
8
|
+
parent: TParent;
|
|
9
|
+
args: TArgs;
|
|
10
|
+
context: any;
|
|
11
|
+
info: any;
|
|
12
|
+
}) => any;
|
|
13
|
+
}
|
|
14
|
+
export interface IGraphQLSchemaBuilder {
|
|
15
|
+
addTypeDefs(typeDefs: TypeDefs): this;
|
|
16
|
+
addResolver<TArgs = any, TParent = any>(config: ResolverConfig<TArgs, TParent>): this;
|
|
17
|
+
/**
|
|
18
|
+
* Bridge for legacy (parent, args, ctx, info) resolver objects.
|
|
19
|
+
* Walks a nested resolvers map and registers each leaf as an addResolver() call.
|
|
20
|
+
*/
|
|
21
|
+
addLegacyResolvers(resolvers: Record<string, any>, prefix?: string): this;
|
|
22
|
+
/**
|
|
23
|
+
* @internal This method needs revisiting, to align with DI concepts.
|
|
24
|
+
*/
|
|
25
|
+
addResolverDecorator(path: string, decorator: ResolverDecorator): this;
|
|
26
|
+
build(): IGraphQLSchema;
|
|
27
|
+
}
|
|
28
|
+
export declare const GraphQLSchemaBuilder: import("@webiny/di").Abstraction<IGraphQLSchemaBuilder>;
|
|
29
|
+
export declare namespace GraphQLSchemaBuilder {
|
|
30
|
+
type Interface = IGraphQLSchemaBuilder;
|
|
31
|
+
type Config<TArgs = any> = ResolverConfig<TArgs>;
|
|
32
|
+
}
|
|
33
|
+
export interface IGraphQLSchemaComposer {
|
|
34
|
+
build(ctx?: Record<string, any>): Promise<IGraphQLSchema>;
|
|
35
|
+
}
|
|
36
|
+
export declare const GraphQLSchemaComposer: import("@webiny/di").Abstraction<IGraphQLSchemaComposer>;
|
|
37
|
+
export declare namespace GraphQLSchemaComposer {
|
|
38
|
+
type Interface = IGraphQLSchemaComposer;
|
|
39
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
const GraphQLSchemaBuilder = createAbstraction("GraphQLSchemaBuilder");
|
|
3
|
+
const GraphQLSchemaComposer = createAbstraction("GraphQLSchemaComposer");
|
|
4
|
+
export { GraphQLSchemaBuilder, GraphQLSchemaComposer };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GraphQLSchemaBuilder/abstractions.js","sources":["../../../src/features/GraphQLSchemaBuilder/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { ResolverDecorator, TypeDefs } from \"~/types.js\";\nimport type { Dependency } from \"@webiny/di\";\nimport type { IGraphQLSchema } from \"~/graphql/abstractions.public.js\";\n\nexport interface ResolverConfig<TArgs = any, TParent = any> {\n path: string;\n dependencies?: Dependency[];\n resolver: (\n ...resolvedDeps: any[]\n ) => (params: { parent: TParent; args: TArgs; context: any; info: any }) => any;\n}\n\nexport interface IGraphQLSchemaBuilder {\n addTypeDefs(typeDefs: TypeDefs): this;\n addResolver<TArgs = any, TParent = any>(config: ResolverConfig<TArgs, TParent>): this;\n /**\n * Bridge for legacy (parent, args, ctx, info) resolver objects.\n * Walks a nested resolvers map and registers each leaf as an addResolver() call.\n */\n addLegacyResolvers(resolvers: Record<string, any>, prefix?: string): this;\n /**\n * @internal This method needs revisiting, to align with DI concepts.\n */\n addResolverDecorator(path: string, decorator: ResolverDecorator): this;\n build(): IGraphQLSchema;\n}\n\nexport const GraphQLSchemaBuilder =\n createAbstraction<IGraphQLSchemaBuilder>(\"GraphQLSchemaBuilder\");\n\nexport namespace GraphQLSchemaBuilder {\n export type Interface = IGraphQLSchemaBuilder;\n export type Config<TArgs = any> = ResolverConfig<TArgs>;\n}\n\nexport interface IGraphQLSchemaComposer {\n build(ctx?: Record<string, any>): Promise<IGraphQLSchema>;\n}\n\nexport const GraphQLSchemaComposer =\n createAbstraction<IGraphQLSchemaComposer>(\"GraphQLSchemaComposer\");\n\nexport namespace GraphQLSchemaComposer {\n export type Interface = IGraphQLSchemaComposer;\n}\n"],"names":["GraphQLSchemaBuilder","createAbstraction","GraphQLSchemaComposer"],"mappings":";AA4BO,MAAMA,uBACTC,kBAAyC;AAWtC,MAAMC,wBACTD,kBAA0C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { GraphQLSchemaComposer } from "./GraphQLSchemaComposer.js";
|
|
3
|
+
const GraphQLSchemaComposerFeature = createFeature({
|
|
4
|
+
name: "GraphQLSchemaComposer",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(GraphQLSchemaComposer);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { GraphQLSchemaComposerFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GraphQLSchemaBuilder/feature.js","sources":["../../../src/features/GraphQLSchemaBuilder/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GraphQLSchemaComposer } from \"./GraphQLSchemaComposer.js\";\n\nexport const GraphQLSchemaComposerFeature = createFeature({\n name: \"GraphQLSchemaComposer\",\n register(container) {\n container.register(GraphQLSchemaComposer);\n }\n});\n"],"names":["GraphQLSchemaComposerFeature","createFeature","container","GraphQLSchemaComposer"],"mappings":";;AAGO,MAAMA,+BAA+BC,cAAc;IACtD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GraphQLSchemaBuilder } from "../features/GraphQLSchemaBuilder/abstractions.js";
|
|
2
|
+
/**
|
|
3
|
+
* Internal — ctx is a legacy bridge, not exposed to public implementors.
|
|
4
|
+
* TODO: remove ctx? once all registerLegacyPluginsViaGqlContextEnhancer callers are migrated —
|
|
5
|
+
* at that point GraphQLSchemaComposer no longer needs to thread ctx through to schema factories.
|
|
6
|
+
*/
|
|
7
|
+
export interface ICoreGraphQLSchemaFactory {
|
|
8
|
+
execute(builder: GraphQLSchemaBuilder.Interface, ctx?: Record<string, any>): Promise<GraphQLSchemaBuilder.Interface>;
|
|
9
|
+
}
|
|
10
|
+
export declare const CoreGraphQLSchemaFactory: import("@webiny/di").Abstraction<ICoreGraphQLSchemaFactory>;
|
|
11
|
+
export declare namespace CoreGraphQLSchemaFactory {
|
|
12
|
+
type Interface = ICoreGraphQLSchemaFactory;
|
|
13
|
+
type SchemaBuilder = GraphQLSchemaBuilder.Interface;
|
|
14
|
+
type Return = Promise<GraphQLSchemaBuilder.Interface>;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql/abstractions.core.js","sources":["../../src/graphql/abstractions.core.ts"],"sourcesContent":["/**\n * This file contains abstraction for use by the core Webiny team, or anyone contributing to the webiny-js repository.\n */\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { GraphQLSchemaBuilder } from \"~/features/GraphQLSchemaBuilder/abstractions.js\";\n\n/**\n * Internal — ctx is a legacy bridge, not exposed to public implementors.\n * TODO: remove ctx? once all registerLegacyPluginsViaGqlContextEnhancer callers are migrated —\n * at that point GraphQLSchemaComposer no longer needs to thread ctx through to schema factories.\n */\nexport interface ICoreGraphQLSchemaFactory {\n execute(\n builder: GraphQLSchemaBuilder.Interface,\n ctx?: Record<string, any>\n ): Promise<GraphQLSchemaBuilder.Interface>;\n}\n\nexport const CoreGraphQLSchemaFactory = createAbstraction<ICoreGraphQLSchemaFactory>(\n \"CoreGraphQLSchemaFactory\"\n);\nexport namespace CoreGraphQLSchemaFactory {\n export type Interface = ICoreGraphQLSchemaFactory;\n export type SchemaBuilder = GraphQLSchemaBuilder.Interface;\n export type Return = Promise<GraphQLSchemaBuilder.Interface>;\n}\n"],"names":["CoreGraphQLSchemaFactory","createAbstraction"],"mappings":";AAkBO,MAAMA,2BAA2BC,kBACpC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Resolvers as IResolvers, TypeDefs as ITypeDefs, ResolverDecorators as IResolverDecorators } from "../types.js";
|
|
2
|
+
import type { GraphQLSchemaBuilder } from "../features/GraphQLSchemaBuilder/abstractions.js";
|
|
3
|
+
export interface IGraphQLSchema {
|
|
4
|
+
typeDefs?: ITypeDefs;
|
|
5
|
+
resolvers?: IResolvers<any>;
|
|
6
|
+
resolverDecorators?: IResolverDecorators;
|
|
7
|
+
}
|
|
8
|
+
/** Define custom GraphQL schema extensions. */
|
|
9
|
+
export interface IGraphQLSchemaFactory {
|
|
10
|
+
execute(builder: GraphQLSchemaBuilder.Interface): Promise<GraphQLSchemaBuilder.Interface>;
|
|
11
|
+
}
|
|
12
|
+
/** Define custom GraphQL schema extensions. */
|
|
13
|
+
export declare const GraphQLSchemaFactory: import("@webiny/di").Abstraction<IGraphQLSchemaFactory>;
|
|
14
|
+
export declare namespace GraphQLSchemaFactory {
|
|
15
|
+
type Interface = IGraphQLSchemaFactory;
|
|
16
|
+
type SchemaBuilder = GraphQLSchemaBuilder.Interface;
|
|
17
|
+
type Return = Promise<GraphQLSchemaBuilder.Interface>;
|
|
18
|
+
}
|