@webiny/api-graphql 0.0.0-unstable.0156a4c312
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/GraphQLEngine.d.ts +23 -0
- package/engine/GraphQLEngine.js +81 -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 +24 -0
- package/engine/GraphQLRoute.js +38 -0
- package/engine/GraphQLRoute.js.map +1 -0
- package/engine/GraphQLSchemaCacheFeature.d.ts +8 -0
- package/engine/GraphQLSchemaCacheFeature.js +11 -0
- package/engine/GraphQLSchemaCacheFeature.js.map +1 -0
- package/engine/GraphQLSchemaKeyVerificationFeature.d.ts +9 -0
- package/engine/GraphQLSchemaKeyVerificationFeature.js +11 -0
- package/engine/GraphQLSchemaKeyVerificationFeature.js.map +1 -0
- package/engine/MemoryGraphQLSchemaCache.d.ts +15 -0
- package/engine/MemoryGraphQLSchemaCache.js +32 -0
- package/engine/MemoryGraphQLSchemaCache.js.map +1 -0
- package/engine/MemoryGraphQLSchemaKeyVerification.d.ts +13 -0
- package/engine/MemoryGraphQLSchemaKeyVerification.js +23 -0
- package/engine/MemoryGraphQLSchemaKeyVerification.js.map +1 -0
- package/engine/abstractions.d.ts +36 -0
- package/engine/abstractions.js +7 -0
- package/engine/abstractions.js.map +1 -0
- package/engine/createSchemaCacheKey.d.ts +8 -0
- package/engine/createSchemaCacheKey.js +23 -0
- package/engine/createSchemaCacheKey.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 +3 -0
- package/exports/api/graphql.js +3 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.d.ts +17 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js +72 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js.map +1 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.d.ts +16 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js +70 -0
- package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js.map +1 -0
- package/features/GraphQLSchemaBuilder/abstractions.d.ts +44 -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 +17 -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 +39 -0
- package/graphql/abstractions.public.js +5 -0
- package/graphql/abstractions.public.js.map +1 -0
- package/graphql/staticSchemaKey.d.ts +5 -0
- package/graphql/staticSchemaKey.js +4 -0
- package/graphql/staticSchemaKey.js.map +1 -0
- package/index.d.ts +12 -0
- package/index.js +14 -0
- package/index.js.map +1 -0
- package/package.json +49 -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/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 @@
|
|
|
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 /*\n * `Dependency` allows `[abstraction, { multiple: true }]`, same as anywhere else in\n * the container. This used to destructure the tuple, throw the options away and\n * always single-resolve, so a resolver asking for every implementation of an\n * abstraction received one object and failed on `.map`.\n */\n const [abstraction, options] = Array.isArray(dep) ? dep : [dep, undefined];\n\n return options?.multiple\n ? context.container.resolveAll(abstraction)\n : 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","options","Array","undefined","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;gBAOnC,MAAM,CAACC,aAAaC,QAAQ,GAAGC,MAAM,OAAO,CAACH,OAAOA,MAAM;oBAACA;oBAAKI;iBAAU;gBAE1E,OAAOF,SAAS,WACVL,QAAQ,SAAS,CAAC,UAAU,CAACI,eAC7BJ,QAAQ,SAAS,CAAC,OAAO,CAACI;YACpC;YAEA,MAAMI,iBAAiBb,YAAYO;YAEnC,OAAOM,eAAe;gBAAEV;gBAAQC;gBAAMC;gBAASC;YAAK;QACxD;QAEA,IAAI,CAAC,iBAAiB,CAACL,WAAWC;QAElC,OAAO,IAAI;IACf;IAEA,mBAAmBY,SAA8B,EAAEC,SAAS,EAAE,EAAQ;QAClE,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAO,OAAO,CAACJ,WAAY;YAClD,MAAMhB,OAAOiB,SAAS,GAAGA,OAAO,CAAC,EAAEC,KAAK,GAAGA;YAC3C,IAAI,AAAiB,cAAjB,OAAOC,OAAsB;gBAC7B,MAAME,KAAKF;gBACX,IAAI,CAAC,WAAW,CAAC;oBACbnB;oBACA,cAAc,EAAE;oBAChB,UACI,IACA,CAAC,EAAEK,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,IAAI,EAAO,GACjCa,GAAGhB,QAAQC,MAAMC,SAASC;gBACtC;YACJ,OAAO,IAAI,AAAiB,YAAjB,OAAOW,SAAsBA,AAAU,SAAVA,OACpC,IAAI,CAAC,kBAAkB,CAACA,OAAOnB;QAEvC;QACA,OAAO,IAAI;IACf;IAKA,qBAAqBA,IAAY,EAAEsB,SAA4B,EAAQ;QACnE,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAACtB,KAAK,EAC9B,IAAI,CAAC,kBAAkB,CAACA,KAAK,GAAG,EAAE;QAEtC,IAAI,CAAC,kBAAkB,CAACA,KAAK,CAAC,IAAI,CAACsB;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,kBAAkBnB,SAAmB,EAAED,QAAa,EAAQ;QAChE,IAAIqB,UAAe,IAAI,CAAC,SAAS;QAEjC,IAAK,IAAIC,IAAI,GAAGA,IAAIrB,UAAU,MAAM,GAAG,GAAGqB,IAAK;YAC3C,MAAMC,OAAOtB,SAAS,CAACqB,EAAE;YACzB,IAAI,CAACD,OAAO,CAACE,KAAK,EACdF,OAAO,CAACE,KAAK,GAAG,CAAC;YAErBF,UAAUA,OAAO,CAACE,KAAK;QAC3B;QAEA,MAAMC,WAAWvB,SAAS,CAACA,UAAU,MAAM,GAAG,EAAE;QAChDoB,OAAO,CAACG,SAAS,GAAGxB;IACxB;;aA3FiB,aAAa,GAAa,EAAE;aAC5B,SAAS,GAAmB,CAAC;aAC7B,kBAAkB,GAAuB,CAAC;;AA0F/D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Container } from "@webiny/di";
|
|
2
|
+
import { GraphQLSchemaComposer as Abstraction } from "./abstractions.js";
|
|
3
|
+
import { GraphQLSchemaKeyVerification } from "../../engine/abstractions.js";
|
|
4
|
+
import type { IGraphQLSchema } from "../../graphql/abstractions.public.js";
|
|
5
|
+
declare class GraphQLSchemaComposerImpl implements Abstraction.Interface {
|
|
6
|
+
private container;
|
|
7
|
+
private verification;
|
|
8
|
+
constructor(container: Container, verification: GraphQLSchemaKeyVerification.Interface | undefined);
|
|
9
|
+
build(): Promise<IGraphQLSchema>;
|
|
10
|
+
getSchemaKey(): Promise<string | null>;
|
|
11
|
+
private getFactories;
|
|
12
|
+
}
|
|
13
|
+
export declare const GraphQLSchemaComposer: typeof GraphQLSchemaComposerImpl & {
|
|
14
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGraphQLSchemaComposer>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { RequestContainer } from "@webiny/event-handler-core";
|
|
3
|
+
import { GraphQLSchemaComposer } from "./abstractions.js";
|
|
4
|
+
import { CoreGraphQLSchemaFactory, GraphQLSchemaFactory } from "../../graphql/abstractions.js";
|
|
5
|
+
import { GraphQLSchemaKeyVerification } from "../../engine/abstractions.js";
|
|
6
|
+
import { createSchemaCacheKey } from "../../engine/createSchemaCacheKey.js";
|
|
7
|
+
import { GraphQLSchemaBuilder } from "./GraphQLSchemaBuilder.js";
|
|
8
|
+
function isKeyed(factory) {
|
|
9
|
+
return "function" == typeof factory.getSchemaKey;
|
|
10
|
+
}
|
|
11
|
+
async function getFactoryOutput(factory) {
|
|
12
|
+
const builder = new GraphQLSchemaBuilder();
|
|
13
|
+
await factory.execute(builder);
|
|
14
|
+
const schema = builder.build();
|
|
15
|
+
return createSchemaCacheKey(schema);
|
|
16
|
+
}
|
|
17
|
+
async function verifyKeys(verification, factories, keys) {
|
|
18
|
+
for(let i = 0; i < factories.length; i++){
|
|
19
|
+
const output = await getFactoryOutput(factories[i]);
|
|
20
|
+
verification.check({
|
|
21
|
+
factory: factories[i].constructor.name,
|
|
22
|
+
key: keys[i],
|
|
23
|
+
output
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
class GraphQLSchemaComposerImpl {
|
|
28
|
+
constructor(container, verification){
|
|
29
|
+
this.container = container;
|
|
30
|
+
this.verification = verification;
|
|
31
|
+
}
|
|
32
|
+
async build() {
|
|
33
|
+
const builder = new GraphQLSchemaBuilder();
|
|
34
|
+
for (const factory of this.getFactories())await factory.execute(builder);
|
|
35
|
+
return builder.build();
|
|
36
|
+
}
|
|
37
|
+
async getSchemaKey() {
|
|
38
|
+
const factories = this.getFactories();
|
|
39
|
+
if (!factories.every(isKeyed)) return null;
|
|
40
|
+
const pendingKeys = factories.map((factory)=>factory.getSchemaKey());
|
|
41
|
+
const keys = await Promise.all(pendingKeys);
|
|
42
|
+
if (this.verification) await verifyKeys(this.verification, factories, keys);
|
|
43
|
+
const hash = createHash("sha1");
|
|
44
|
+
hash.update(keys.join("\n"));
|
|
45
|
+
return hash.digest("hex");
|
|
46
|
+
}
|
|
47
|
+
getFactories() {
|
|
48
|
+
const coreSchemas = this.container.resolveAll(CoreGraphQLSchemaFactory);
|
|
49
|
+
const userSchemas = this.container.resolveAll(GraphQLSchemaFactory);
|
|
50
|
+
return [
|
|
51
|
+
...coreSchemas,
|
|
52
|
+
...userSchemas
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const GraphQLSchemaComposer_GraphQLSchemaComposer = GraphQLSchemaComposer.createImplementation({
|
|
57
|
+
implementation: GraphQLSchemaComposerImpl,
|
|
58
|
+
dependencies: [
|
|
59
|
+
RequestContainer,
|
|
60
|
+
[
|
|
61
|
+
GraphQLSchemaKeyVerification,
|
|
62
|
+
{
|
|
63
|
+
optional: true
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
]
|
|
67
|
+
});
|
|
68
|
+
export { GraphQLSchemaComposer_GraphQLSchemaComposer as GraphQLSchemaComposer };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=GraphQLSchemaComposer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js","sources":["../../../src/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { 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 { GraphQLSchemaKeyVerification } from \"~/engine/abstractions.js\";\nimport { createSchemaCacheKey } from \"~/engine/createSchemaCacheKey.js\";\nimport { GraphQLSchemaBuilder } from \"./GraphQLSchemaBuilder.js\";\nimport type { IGraphQLSchema } from \"~/graphql/abstractions.public.js\";\n\ntype SchemaFactory = CoreGraphQLSchemaFactory.Interface | GraphQLSchemaFactory.Interface;\n\ntype KeyedSchemaFactory = SchemaFactory & {\n getSchemaKey(): string | Promise<string>;\n};\n\nfunction isKeyed(factory: SchemaFactory): factory is KeyedSchemaFactory {\n return typeof factory.getSchemaKey === \"function\";\n}\n\n// The output of one factory on its own, reduced to the same key the engine uses for a full schema.\nasync function getFactoryOutput(factory: SchemaFactory): Promise<string> {\n const builder = new GraphQLSchemaBuilder();\n await factory.execute(builder);\n const schema = builder.build();\n return createSchemaCacheKey(schema);\n}\n\n// Runs each factory on its own and checks its output against its schema key.\nasync function verifyKeys(\n verification: GraphQLSchemaKeyVerification.Interface,\n factories: SchemaFactory[],\n keys: string[]\n): Promise<void> {\n for (let i = 0; i < factories.length; i++) {\n const output = await getFactoryOutput(factories[i]);\n verification.check({\n factory: factories[i].constructor.name,\n key: keys[i],\n output\n });\n }\n}\n\nclass GraphQLSchemaComposerImpl implements Abstraction.Interface {\n constructor(\n private container: Container,\n private verification: GraphQLSchemaKeyVerification.Interface | undefined\n ) {}\n\n async build(): Promise<IGraphQLSchema> {\n const builder = new GraphQLSchemaBuilder();\n\n for (const factory of this.getFactories()) {\n await factory.execute(builder);\n }\n\n return builder.build();\n }\n\n async getSchemaKey(): Promise<string | null> {\n const factories = this.getFactories();\n if (!factories.every(isKeyed)) {\n return null;\n }\n\n const pendingKeys = factories.map(factory => factory.getSchemaKey());\n const keys = await Promise.all(pendingKeys);\n\n if (this.verification) {\n await verifyKeys(this.verification, factories, keys);\n }\n\n const hash = createHash(\"sha1\");\n hash.update(keys.join(\"\\n\"));\n return hash.digest(\"hex\");\n }\n\n private getFactories(): SchemaFactory[] {\n const coreSchemas = this.container.resolveAll(CoreGraphQLSchemaFactory);\n const userSchemas = this.container.resolveAll(GraphQLSchemaFactory);\n return [...coreSchemas, ...userSchemas];\n }\n}\n\nexport const GraphQLSchemaComposer = Abstraction.createImplementation({\n implementation: GraphQLSchemaComposerImpl,\n dependencies: [RequestContainer, [GraphQLSchemaKeyVerification, { optional: true }]]\n});\n"],"names":["isKeyed","factory","getFactoryOutput","builder","GraphQLSchemaBuilder","schema","createSchemaCacheKey","verifyKeys","verification","factories","keys","i","output","GraphQLSchemaComposerImpl","container","pendingKeys","Promise","hash","createHash","coreSchemas","CoreGraphQLSchemaFactory","userSchemas","GraphQLSchemaFactory","GraphQLSchemaComposer","Abstraction","RequestContainer","GraphQLSchemaKeyVerification"],"mappings":";;;;;;;AAgBA,SAASA,QAAQC,OAAsB;IACnC,OAAO,AAAgC,cAAhC,OAAOA,QAAQ,YAAY;AACtC;AAGA,eAAeC,iBAAiBD,OAAsB;IAClD,MAAME,UAAU,IAAIC;IACpB,MAAMH,QAAQ,OAAO,CAACE;IACtB,MAAME,SAASF,QAAQ,KAAK;IAC5B,OAAOG,qBAAqBD;AAChC;AAGA,eAAeE,WACXC,YAAoD,EACpDC,SAA0B,EAC1BC,IAAc;IAEd,IAAK,IAAIC,IAAI,GAAGA,IAAIF,UAAU,MAAM,EAAEE,IAAK;QACvC,MAAMC,SAAS,MAAMV,iBAAiBO,SAAS,CAACE,EAAE;QAClDH,aAAa,KAAK,CAAC;YACf,SAASC,SAAS,CAACE,EAAE,CAAC,WAAW,CAAC,IAAI;YACtC,KAAKD,IAAI,CAACC,EAAE;YACZC;QACJ;IACJ;AACJ;AAEA,MAAMC;IACF,YACYC,SAAoB,EACpBN,YAAgE,CAC1E;aAFUM,SAAS,GAATA;aACAN,YAAY,GAAZA;IACT;IAEH,MAAM,QAAiC;QACnC,MAAML,UAAU,IAAIC;QAEpB,KAAK,MAAMH,WAAW,IAAI,CAAC,YAAY,GACnC,MAAMA,QAAQ,OAAO,CAACE;QAG1B,OAAOA,QAAQ,KAAK;IACxB;IAEA,MAAM,eAAuC;QACzC,MAAMM,YAAY,IAAI,CAAC,YAAY;QACnC,IAAI,CAACA,UAAU,KAAK,CAACT,UACjB,OAAO;QAGX,MAAMe,cAAcN,UAAU,GAAG,CAACR,CAAAA,UAAWA,QAAQ,YAAY;QACjE,MAAMS,OAAO,MAAMM,QAAQ,GAAG,CAACD;QAE/B,IAAI,IAAI,CAAC,YAAY,EACjB,MAAMR,WAAW,IAAI,CAAC,YAAY,EAAEE,WAAWC;QAGnD,MAAMO,OAAOC,WAAW;QACxBD,KAAK,MAAM,CAACP,KAAK,IAAI,CAAC;QACtB,OAAOO,KAAK,MAAM,CAAC;IACvB;IAEQ,eAAgC;QACpC,MAAME,cAAc,IAAI,CAAC,SAAS,CAAC,UAAU,CAACC;QAC9C,MAAMC,cAAc,IAAI,CAAC,SAAS,CAAC,UAAU,CAACC;QAC9C,OAAO;eAAIH;eAAgBE;SAAY;IAC3C;AACJ;AAEO,MAAME,8CAAwBC,sBAAAA,oBAAgC,CAAC;IAClE,gBAAgBX;IAChB,cAAc;QAACY;QAAkB;YAACC;YAA8B;gBAAE,UAAU;YAAK;SAAE;KAAC;AACxF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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(): Promise<IGraphQLSchema>;
|
|
35
|
+
/**
|
|
36
|
+
* Combines every factory's schema key. Returns null when any factory has no key, because its
|
|
37
|
+
* output can then only be known by running it.
|
|
38
|
+
*/
|
|
39
|
+
getSchemaKey(): Promise<string | null>;
|
|
40
|
+
}
|
|
41
|
+
export declare const GraphQLSchemaComposer: import("@webiny/di").Abstraction<IGraphQLSchemaComposer>;
|
|
42
|
+
export declare namespace GraphQLSchemaComposer {
|
|
43
|
+
type Interface = IGraphQLSchemaComposer;
|
|
44
|
+
}
|
|
@@ -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(): Promise<IGraphQLSchema>;\n /**\n * Combines every factory's schema key. Returns null when any factory has no key, because its\n * output can then only be known by running it.\n */\n getSchemaKey(): Promise<string | null>;\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;AAgBtC,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,17 @@
|
|
|
1
|
+
import type { GraphQLSchemaBuilder } from "../features/GraphQLSchemaBuilder/abstractions.js";
|
|
2
|
+
export interface ICoreGraphQLSchemaFactory {
|
|
3
|
+
execute(builder: GraphQLSchemaBuilder.Interface): Promise<GraphQLSchemaBuilder.Interface>;
|
|
4
|
+
/**
|
|
5
|
+
* Returns what this factory's type definitions and resolver paths depend on: the same key must
|
|
6
|
+
* always mean the same output. When every factory has one, the GraphQL engine runs the factories
|
|
7
|
+
* only if no schema is cached under the combined key yet. Leave it out and the factories run on
|
|
8
|
+
* every request. Use `staticSchemaKey()` for a factory whose output never changes.
|
|
9
|
+
*/
|
|
10
|
+
getSchemaKey?(): string | Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
export declare const CoreGraphQLSchemaFactory: import("@webiny/di").Abstraction<ICoreGraphQLSchemaFactory>;
|
|
13
|
+
export declare namespace CoreGraphQLSchemaFactory {
|
|
14
|
+
type Interface = ICoreGraphQLSchemaFactory;
|
|
15
|
+
type SchemaBuilder = GraphQLSchemaBuilder.Interface;
|
|
16
|
+
type Return = Promise<GraphQLSchemaBuilder.Interface>;
|
|
17
|
+
}
|
|
@@ -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\nexport interface ICoreGraphQLSchemaFactory {\n execute(builder: GraphQLSchemaBuilder.Interface): Promise<GraphQLSchemaBuilder.Interface>;\n /**\n * Returns what this factory's type definitions and resolver paths depend on: the same key must\n * always mean the same output. When every factory has one, the GraphQL engine runs the factories\n * only if no schema is cached under the combined key yet. Leave it out and the factories run on\n * every request. Use `staticSchemaKey()` for a factory whose output never changes.\n */\n getSchemaKey?(): string | Promise<string>;\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":";AAiBO,MAAMA,2BAA2BC,kBACpC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* Resolvers added here end up in a schema that is cached across requests. They must get
|
|
12
|
+
* request-scoped services through `addResolver({ dependencies })`, never from `this`.
|
|
13
|
+
*/
|
|
14
|
+
execute(builder: GraphQLSchemaBuilder.Interface): Promise<GraphQLSchemaBuilder.Interface>;
|
|
15
|
+
/**
|
|
16
|
+
* Returns what this factory's type definitions and resolver paths depend on: the same key must
|
|
17
|
+
* always mean the same output. When every factory has one, the GraphQL engine runs the factories
|
|
18
|
+
* only if no schema is cached under the combined key yet. Leave it out and the factories run on
|
|
19
|
+
* every request, but a schema with the same output is still served from the cache, with the
|
|
20
|
+
* resolvers of the request that first built it. Use `staticSchemaKey()` for a factory whose
|
|
21
|
+
* output never changes.
|
|
22
|
+
*/
|
|
23
|
+
getSchemaKey?(): string | Promise<string>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Define custom GraphQL schema extensions.
|
|
27
|
+
*
|
|
28
|
+
* The built schema is cached across requests. Constructor dependencies are injected only for the
|
|
29
|
+
* request that builds it, so a resolver must never read them (`this.identityContext` and similar):
|
|
30
|
+
* every later request served from the cache would run with that request's identity, tenant and
|
|
31
|
+
* use cases. Declare what a resolver needs in `builder.addResolver({ dependencies })`, which
|
|
32
|
+
* resolves it from the current request, and register the factory with `dependencies: []`.
|
|
33
|
+
*/
|
|
34
|
+
export declare const GraphQLSchemaFactory: import("@webiny/di").Abstraction<IGraphQLSchemaFactory>;
|
|
35
|
+
export declare namespace GraphQLSchemaFactory {
|
|
36
|
+
type Interface = IGraphQLSchemaFactory;
|
|
37
|
+
type SchemaBuilder = GraphQLSchemaBuilder.Interface;
|
|
38
|
+
type Return = Promise<GraphQLSchemaBuilder.Interface>;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql/abstractions.public.js","sources":["../../src/graphql/abstractions.public.ts"],"sourcesContent":["/**\n * This file contains abstraction for use by third party developers.\n */\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type {\n Resolvers as IResolvers,\n TypeDefs as ITypeDefs,\n ResolverDecorators as IResolverDecorators\n} from \"~/types.js\";\nimport type { GraphQLSchemaBuilder } from \"~/features/GraphQLSchemaBuilder/abstractions.js\";\n\nexport interface IGraphQLSchema {\n typeDefs?: ITypeDefs;\n resolvers?: IResolvers<any>;\n resolverDecorators?: IResolverDecorators;\n}\n\n/** Define custom GraphQL schema extensions. */\nexport interface IGraphQLSchemaFactory {\n /**\n * Resolvers added here end up in a schema that is cached across requests. They must get\n * request-scoped services through `addResolver({ dependencies })`, never from `this`.\n */\n execute(builder: GraphQLSchemaBuilder.Interface): Promise<GraphQLSchemaBuilder.Interface>;\n /**\n * Returns what this factory's type definitions and resolver paths depend on: the same key must\n * always mean the same output. When every factory has one, the GraphQL engine runs the factories\n * only if no schema is cached under the combined key yet. Leave it out and the factories run on\n * every request, but a schema with the same output is still served from the cache, with the\n * resolvers of the request that first built it. Use `staticSchemaKey()` for a factory whose\n * output never changes.\n */\n getSchemaKey?(): string | Promise<string>;\n}\n\n/**\n * Define custom GraphQL schema extensions.\n *\n * The built schema is cached across requests. Constructor dependencies are injected only for the\n * request that builds it, so a resolver must never read them (`this.identityContext` and similar):\n * every later request served from the cache would run with that request's identity, tenant and\n * use cases. Declare what a resolver needs in `builder.addResolver({ dependencies })`, which\n * resolves it from the current request, and register the factory with `dependencies: []`.\n */\nexport const GraphQLSchemaFactory =\n createAbstraction<IGraphQLSchemaFactory>(\"GraphQLSchemaFactory\");\n\nexport namespace GraphQLSchemaFactory {\n export type Interface = IGraphQLSchemaFactory;\n export type SchemaBuilder = GraphQLSchemaBuilder.Interface;\n export type Return = Promise<GraphQLSchemaBuilder.Interface>;\n}\n"],"names":["GraphQLSchemaFactory","createAbstraction"],"mappings":";AA4CO,MAAMA,uBACTC,kBAAyC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql/staticSchemaKey.js","sources":["../../src/graphql/staticSchemaKey.ts"],"sourcesContent":["/**\n * Schema key for a factory whose type definitions and resolver paths never change. The id only has\n * to be unique among factories.\n */\nexport const staticSchemaKey = (id: string) => {\n return (): string => `static:${id}`;\n};\n"],"names":["staticSchemaKey","id"],"mappings":"AAIO,MAAMA,kBAAkB,CAACC,KACrB,IAAc,CAAC,OAAO,EAAEA,IAAI"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./errors.js";
|
|
2
|
+
export * from "./responses.js";
|
|
3
|
+
export * from "./utils/index.js";
|
|
4
|
+
export * from "./plugins/index.js";
|
|
5
|
+
export * from "./createRequestBody.js";
|
|
6
|
+
export * from "./processRequestBody.js";
|
|
7
|
+
export * from "./createResolverDecorator.js";
|
|
8
|
+
export * from "./ResolverDecoration.js";
|
|
9
|
+
export * from "./engine/index.js";
|
|
10
|
+
export * from "./graphql/staticSchemaKey.js";
|
|
11
|
+
export default _default;
|
|
12
|
+
declare function _default(): never[];
|
package/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./errors.js";
|
|
2
|
+
export * from "./responses.js";
|
|
3
|
+
export * from "./utils/index.js";
|
|
4
|
+
export * from "./plugins/index.js";
|
|
5
|
+
export * from "./createRequestBody.js";
|
|
6
|
+
export * from "./processRequestBody.js";
|
|
7
|
+
export * from "./createResolverDecorator.js";
|
|
8
|
+
export * from "./ResolverDecoration.js";
|
|
9
|
+
export * from "./engine/index.js";
|
|
10
|
+
export * from "./graphql/staticSchemaKey.js";
|
|
11
|
+
const src = ()=>[];
|
|
12
|
+
export default src;
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["export * from \"./errors.js\";\nexport * from \"./responses.js\";\nexport * from \"./utils/index.js\";\nexport * from \"./plugins/index.js\";\nexport * from \"./createRequestBody.js\";\nexport * from \"./processRequestBody.js\";\nexport * from \"./createResolverDecorator.js\";\nexport * from \"./ResolverDecoration.js\";\nexport * from \"./engine/index.js\";\nexport * from \"./graphql/staticSchemaKey.js\";\n\n// Backward-compat stub — the Fastify GraphQL route was replaced by GraphQLRoute\n// registered via GraphQLEngineFeature. This default export is a no-op.\nexport default () => [];\n"],"names":[],"mappings":";;;;;;;;;;AAaA,YAAgB,IAAK,EAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/api-graphql",
|
|
3
|
+
"version": "0.0.0-unstable.0156a4c312",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.js",
|
|
7
|
+
"./*": "./*"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
13
|
+
},
|
|
14
|
+
"description": "The Server as a function.",
|
|
15
|
+
"contributors": [
|
|
16
|
+
"Pavel Denisjuk <pavel@webiny.com>",
|
|
17
|
+
"Sven Al Hamad <sven@webiny.com>",
|
|
18
|
+
"Adrian Smijulj <adrian@webiny.com>"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@graphql-tools/merge": "10.0.8",
|
|
22
|
+
"@graphql-tools/resolvers-composition": "8.0.8",
|
|
23
|
+
"@graphql-tools/schema": "11.0.8",
|
|
24
|
+
"@graphql-tools/utils": "13.2.1",
|
|
25
|
+
"@webiny/api": "0.0.0-unstable.0156a4c312",
|
|
26
|
+
"@webiny/di": "2.0.0",
|
|
27
|
+
"@webiny/error": "0.0.0-unstable.0156a4c312",
|
|
28
|
+
"@webiny/event-handler-core": "0.0.0-unstable.0156a4c312",
|
|
29
|
+
"@webiny/feature": "0.0.0-unstable.0156a4c312",
|
|
30
|
+
"@webiny/plugins": "0.0.0-unstable.0156a4c312",
|
|
31
|
+
"@webiny/utils": "0.0.0-unstable.0156a4c312",
|
|
32
|
+
"graphql": "16.14.2",
|
|
33
|
+
"graphql-scalars": "2.0.1",
|
|
34
|
+
"zod": "4.6.7"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@webiny/build-tools": "0.0.0-unstable.0156a4c312",
|
|
38
|
+
"rimraf": "6.1.3",
|
|
39
|
+
"typescript": "7.0.2",
|
|
40
|
+
"vitest": "5.0.5"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "b8aec8a1be3f25c3b428b357fe1e352c7cbff9ae",
|
|
46
|
+
"webiny": {
|
|
47
|
+
"publishFrom": "dist"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Context } from "@webiny/api/types.js";
|
|
2
|
+
import { Plugin } from "@webiny/plugins";
|
|
3
|
+
import type { GraphQLSchemaDefinition, ResolverDecorators, Resolvers, TypeDefs } from "../types.js";
|
|
4
|
+
export interface IGraphQLSchemaPlugin<TContext = Context> extends Plugin {
|
|
5
|
+
schema: GraphQLSchemaDefinition<TContext>;
|
|
6
|
+
isApplicable: (context: TContext) => boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface GraphQLSchemaPluginConfig<TContext> {
|
|
9
|
+
typeDefs?: TypeDefs;
|
|
10
|
+
resolvers?: Resolvers<TContext>;
|
|
11
|
+
resolverDecorators?: ResolverDecorators;
|
|
12
|
+
isApplicable?: (context: TContext) => boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare class GraphQLSchemaPlugin<TContext = Context> extends Plugin implements IGraphQLSchemaPlugin<TContext> {
|
|
15
|
+
static readonly type: string;
|
|
16
|
+
protected config: GraphQLSchemaPluginConfig<TContext>;
|
|
17
|
+
constructor(config: GraphQLSchemaPluginConfig<TContext>);
|
|
18
|
+
get schema(): GraphQLSchemaDefinition<TContext>;
|
|
19
|
+
isApplicable(context: TContext): boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const createGraphQLSchemaPlugin: <T = Context>(config: GraphQLSchemaPluginConfig<T>) => GraphQLSchemaPlugin<T>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
class GraphQLSchemaPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "graphql-schema";
|
|
5
|
+
}
|
|
6
|
+
constructor(config){
|
|
7
|
+
super();
|
|
8
|
+
this.config = config;
|
|
9
|
+
}
|
|
10
|
+
get schema() {
|
|
11
|
+
return {
|
|
12
|
+
typeDefs: this.config.typeDefs || "",
|
|
13
|
+
resolvers: this.config.resolvers,
|
|
14
|
+
resolverDecorators: this.config.resolverDecorators
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
isApplicable(context) {
|
|
18
|
+
if (this.config.isApplicable) return this.config.isApplicable(context);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const createGraphQLSchemaPlugin = (config)=>new GraphQLSchemaPlugin(config);
|
|
23
|
+
export { GraphQLSchemaPlugin, createGraphQLSchemaPlugin };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=GraphQLSchemaPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins/GraphQLSchemaPlugin.js","sources":["../../src/plugins/GraphQLSchemaPlugin.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types.js\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { GraphQLSchemaDefinition, ResolverDecorators, Resolvers, TypeDefs } from \"~/types.js\";\n\nexport interface IGraphQLSchemaPlugin<TContext = Context> extends Plugin {\n schema: GraphQLSchemaDefinition<TContext>;\n isApplicable: (context: TContext) => boolean;\n}\n\nexport interface GraphQLSchemaPluginConfig<TContext> {\n typeDefs?: TypeDefs;\n resolvers?: Resolvers<TContext>;\n resolverDecorators?: ResolverDecorators;\n isApplicable?: (context: TContext) => boolean;\n}\n\nexport class GraphQLSchemaPlugin<TContext = Context>\n extends Plugin\n implements IGraphQLSchemaPlugin<TContext>\n{\n public static override readonly type: string = \"graphql-schema\";\n protected config: GraphQLSchemaPluginConfig<TContext>;\n\n constructor(config: GraphQLSchemaPluginConfig<TContext>) {\n super();\n this.config = config;\n }\n\n get schema(): GraphQLSchemaDefinition<TContext> {\n return {\n typeDefs: this.config.typeDefs || \"\",\n resolvers: this.config.resolvers,\n resolverDecorators: this.config.resolverDecorators\n };\n }\n\n isApplicable(context: TContext): boolean {\n if (this.config.isApplicable) {\n return this.config.isApplicable(context);\n }\n return true;\n }\n}\n\nexport const createGraphQLSchemaPlugin = <T = Context>(config: GraphQLSchemaPluginConfig<T>) => {\n return new GraphQLSchemaPlugin<T>(config);\n};\n"],"names":["GraphQLSchemaPlugin","Plugin","config","context","createGraphQLSchemaPlugin"],"mappings":";AAgBO,MAAMA,4BACDC;;aAGwB,IAAI,GAAW;;IAG/C,YAAYC,MAA2C,CAAE;QACrD,KAAK;QACL,IAAI,CAAC,MAAM,GAAGA;IAClB;IAEA,IAAI,SAA4C;QAC5C,OAAO;YACH,UAAU,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI;YAClC,WAAW,IAAI,CAAC,MAAM,CAAC,SAAS;YAChC,oBAAoB,IAAI,CAAC,MAAM,CAAC,kBAAkB;QACtD;IACJ;IAEA,aAAaC,OAAiB,EAAW;QACrC,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,EACxB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAACA;QAEpC,OAAO;IACX;AACJ;AAEO,MAAMC,4BAA4B,CAAcF,SAC5C,IAAIF,oBAAuBE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./GraphQLSchemaPlugin.js";
|
package/plugins/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./GraphQLSchemaPlugin.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ExecutionResult, GraphQLSchema } from "graphql";
|
|
2
|
+
import type { GraphQLRequestBody } from "./types.js";
|
|
3
|
+
import type { Context } from "@webiny/api/types.js";
|
|
4
|
+
export declare const processRequestBody: <TData = Record<string, any>, TExtensions = Record<string, any>>(requestBody: GraphQLRequestBody | GraphQLRequestBody[], schema: GraphQLSchema, context: Context) => Promise<ExecutionResult<TData, TExtensions>[] | ExecutionResult<TData, TExtensions>>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { graphql } from "graphql";
|
|
2
|
+
const executeGraphQl = async (body, schema, context)=>{
|
|
3
|
+
const { query, variables, operationName } = body;
|
|
4
|
+
return graphql({
|
|
5
|
+
schema,
|
|
6
|
+
source: query,
|
|
7
|
+
rootValue: {},
|
|
8
|
+
contextValue: context,
|
|
9
|
+
variableValues: variables,
|
|
10
|
+
operationName
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
const processRequestBody = async (requestBody, schema, context)=>{
|
|
14
|
+
if (Array.isArray(requestBody)) {
|
|
15
|
+
const results = [];
|
|
16
|
+
for (const body of requestBody){
|
|
17
|
+
const result = await executeGraphQl(body, schema, context);
|
|
18
|
+
results.push(result);
|
|
19
|
+
}
|
|
20
|
+
return results;
|
|
21
|
+
}
|
|
22
|
+
return await executeGraphQl(requestBody, schema, context);
|
|
23
|
+
};
|
|
24
|
+
export { processRequestBody };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=processRequestBody.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processRequestBody.js","sources":["../src/processRequestBody.ts"],"sourcesContent":["import type { ExecutionResult, GraphQLSchema } from \"graphql\";\nimport { graphql } from \"graphql\";\nimport type { GraphQLRequestBody } from \"~/types.js\";\nimport type { Context } from \"@webiny/api/types.js\";\n\nconst executeGraphQl = async <TData = Record<string, any>, TExtensions = Record<string, any>>(\n body: GraphQLRequestBody,\n schema: GraphQLSchema,\n context: Context\n): Promise<ExecutionResult<TData, TExtensions>> => {\n const { query, variables, operationName } = body;\n return graphql({\n schema,\n source: query,\n rootValue: {},\n contextValue: context,\n variableValues: variables,\n operationName\n }) as Promise<ExecutionResult<TData, TExtensions>>;\n};\n\nexport const processRequestBody = async <\n TData = Record<string, any>,\n TExtensions = Record<string, any>\n>(\n requestBody: GraphQLRequestBody | GraphQLRequestBody[],\n schema: GraphQLSchema,\n context: Context\n): Promise<ExecutionResult<TData, TExtensions>[] | ExecutionResult<TData, TExtensions>> => {\n if (Array.isArray(requestBody)) {\n const results: ExecutionResult<TData, TExtensions>[] = [];\n for (const body of requestBody) {\n const result = await executeGraphQl<TData, TExtensions>(body, schema, context);\n results.push(result);\n }\n return results;\n }\n return await executeGraphQl<TData, TExtensions>(requestBody, schema, context);\n};\n"],"names":["executeGraphQl","body","schema","context","query","variables","operationName","graphql","processRequestBody","requestBody","Array","results","result"],"mappings":";AAKA,MAAMA,iBAAiB,OACnBC,MACAC,QACAC;IAEA,MAAM,EAAEC,KAAK,EAAEC,SAAS,EAAEC,aAAa,EAAE,GAAGL;IAC5C,OAAOM,QAAQ;QACXL;QACA,QAAQE;QACR,WAAW,CAAC;QACZ,cAAcD;QACd,gBAAgBE;QAChBC;IACJ;AACJ;AAEO,MAAME,qBAAqB,OAI9BC,aACAP,QACAC;IAEA,IAAIO,MAAM,OAAO,CAACD,cAAc;QAC5B,MAAME,UAAiD,EAAE;QACzD,KAAK,MAAMV,QAAQQ,YAAa;YAC5B,MAAMG,SAAS,MAAMZ,eAAmCC,MAAMC,QAAQC;YACtEQ,QAAQ,IAAI,CAACC;QACjB;QACA,OAAOD;IACX;IACA,OAAO,MAAMX,eAAmCS,aAAaP,QAAQC;AACzE"}
|
package/responses.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export interface IMeta {
|
|
2
|
+
hasMoreItems: boolean;
|
|
3
|
+
totalCount: number;
|
|
4
|
+
cursor?: string | null;
|
|
5
|
+
}
|
|
6
|
+
export interface ErrorResponseParams {
|
|
7
|
+
message: string;
|
|
8
|
+
code?: string;
|
|
9
|
+
data?: any;
|
|
10
|
+
stack?: string | null;
|
|
11
|
+
}
|
|
12
|
+
/** GraphQL error response helper. */
|
|
13
|
+
export declare class ErrorResponse {
|
|
14
|
+
readonly data: null;
|
|
15
|
+
readonly error: {
|
|
16
|
+
code: string;
|
|
17
|
+
message: string;
|
|
18
|
+
data: any;
|
|
19
|
+
stack: string | null;
|
|
20
|
+
};
|
|
21
|
+
constructor(params: ErrorResponseParams);
|
|
22
|
+
}
|
|
23
|
+
/** GraphQL not-found response helper. */
|
|
24
|
+
export declare class NotFoundResponse extends ErrorResponse {
|
|
25
|
+
constructor(message: string);
|
|
26
|
+
}
|
|
27
|
+
/** GraphQL list error response helper. */
|
|
28
|
+
export declare class ListErrorResponse {
|
|
29
|
+
readonly data: null;
|
|
30
|
+
readonly meta: null;
|
|
31
|
+
readonly error: {
|
|
32
|
+
code: string;
|
|
33
|
+
message: string;
|
|
34
|
+
data: any;
|
|
35
|
+
stack: string | null;
|
|
36
|
+
};
|
|
37
|
+
constructor(params: ErrorResponseParams);
|
|
38
|
+
}
|
|
39
|
+
/** GraphQL response helper. */
|
|
40
|
+
export declare class Response<T = any> {
|
|
41
|
+
readonly data: T;
|
|
42
|
+
readonly error: null;
|
|
43
|
+
constructor(data: T);
|
|
44
|
+
}
|
|
45
|
+
/** GraphQL list response helper. */
|
|
46
|
+
export declare class ListResponse<T, M = IMeta> {
|
|
47
|
+
readonly data: Array<T>;
|
|
48
|
+
readonly meta: M;
|
|
49
|
+
readonly error: null;
|
|
50
|
+
constructor(data: Array<T>, meta?: M);
|
|
51
|
+
}
|
package/responses.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const defaultParams = {
|
|
2
|
+
code: "",
|
|
3
|
+
message: "",
|
|
4
|
+
data: null,
|
|
5
|
+
stack: null
|
|
6
|
+
};
|
|
7
|
+
class ErrorResponse {
|
|
8
|
+
constructor(params){
|
|
9
|
+
this.data = null;
|
|
10
|
+
const debug = "true" === process.env.DEBUG;
|
|
11
|
+
let stack = defaultParams.stack;
|
|
12
|
+
if (debug && params.stack) stack = params.stack;
|
|
13
|
+
this.error = {
|
|
14
|
+
code: params.code || defaultParams.code,
|
|
15
|
+
message: params.message || defaultParams.message,
|
|
16
|
+
data: params.data || defaultParams.data,
|
|
17
|
+
stack: stack
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class NotFoundResponse extends ErrorResponse {
|
|
22
|
+
constructor(message){
|
|
23
|
+
super({
|
|
24
|
+
code: "NOT_FOUND",
|
|
25
|
+
message
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
class ListErrorResponse {
|
|
30
|
+
constructor(params){
|
|
31
|
+
this.meta = null;
|
|
32
|
+
this.data = null;
|
|
33
|
+
const debug = "true" === process.env.DEBUG;
|
|
34
|
+
let stack = defaultParams.stack;
|
|
35
|
+
if (debug && params.stack) stack = params.stack;
|
|
36
|
+
this.error = {
|
|
37
|
+
code: params.code || defaultParams.code,
|
|
38
|
+
message: params.message || defaultParams.message,
|
|
39
|
+
data: params.data || defaultParams.data,
|
|
40
|
+
stack: stack
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class Response {
|
|
45
|
+
constructor(data){
|
|
46
|
+
this.data = data;
|
|
47
|
+
this.error = null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
class ListResponse {
|
|
51
|
+
constructor(data, meta){
|
|
52
|
+
this.data = Array.isArray(data) ? data : [];
|
|
53
|
+
this.meta = meta || {};
|
|
54
|
+
this.error = null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export { ErrorResponse, ListErrorResponse, ListResponse, NotFoundResponse, Response };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=responses.js.map
|
package/responses.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sources":["../src/responses.ts"],"sourcesContent":["export interface IMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor?: string | null;\n}\n\nexport interface ErrorResponseParams {\n message: string;\n code?: string;\n data?: any;\n stack?: string | null;\n}\n\nconst defaultParams: Required<ErrorResponseParams> = {\n code: \"\",\n message: \"\",\n data: null,\n stack: null\n};\n\n/** GraphQL error response helper. */\nexport class ErrorResponse {\n public readonly data: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\n/** GraphQL not-found response helper. */\nexport class NotFoundResponse extends ErrorResponse {\n constructor(message: string) {\n super({\n code: \"NOT_FOUND\",\n message\n });\n }\n}\n\n/** GraphQL list error response helper. */\nexport class ListErrorResponse {\n public readonly data: null;\n public readonly meta: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.meta = null;\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\n/** GraphQL response helper. */\nexport class Response<T = any> {\n public readonly data: T;\n public readonly error: null;\n\n constructor(data: T) {\n this.data = data;\n this.error = null;\n }\n}\n\n/** GraphQL list response helper. */\nexport class ListResponse<T, M = IMeta> {\n public readonly data: Array<T>;\n public readonly meta: M;\n public readonly error: null;\n\n constructor(data: Array<T>, meta?: M) {\n this.data = Array.isArray(data) ? data : [];\n this.meta = meta || ({} as M);\n this.error = null;\n }\n}\n"],"names":["defaultParams","ErrorResponse","params","debug","process","stack","NotFoundResponse","message","ListErrorResponse","Response","data","ListResponse","meta","Array"],"mappings":"AAaA,MAAMA,gBAA+C;IACjD,MAAM;IACN,SAAS;IACT,MAAM;IACN,OAAO;AACX;AAGO,MAAMC;IAST,YAAYC,MAA2B,CAAE;QACrC,IAAI,CAAC,IAAI,GAAG;QAEZ,MAAMC,QAAQC,AAAsB,WAAtBA,QAAQ,GAAG,CAAC,KAAK;QAG/B,IAAIC,QAAQL,cAAc,KAAK;QAC/B,IAAIG,SAASD,OAAO,KAAK,EACrBG,QAAQH,OAAO,KAAK;QAGxB,IAAI,CAAC,KAAK,GAAG;YACT,MAAMA,OAAO,IAAI,IAAIF,cAAc,IAAI;YACvC,SAASE,OAAO,OAAO,IAAIF,cAAc,OAAO;YAChD,MAAME,OAAO,IAAI,IAAIF,cAAc,IAAI;YACvC,OAAOK;QACX;IACJ;AACJ;AAGO,MAAMC,yBAAyBL;IAClC,YAAYM,OAAe,CAAE;QACzB,KAAK,CAAC;YACF,MAAM;YACNA;QACJ;IACJ;AACJ;AAGO,MAAMC;IAUT,YAAYN,MAA2B,CAAE;QACrC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,IAAI,GAAG;QAEZ,MAAMC,QAAQC,AAAsB,WAAtBA,QAAQ,GAAG,CAAC,KAAK;QAG/B,IAAIC,QAAQL,cAAc,KAAK;QAC/B,IAAIG,SAASD,OAAO,KAAK,EACrBG,QAAQH,OAAO,KAAK;QAGxB,IAAI,CAAC,KAAK,GAAG;YACT,MAAMA,OAAO,IAAI,IAAIF,cAAc,IAAI;YACvC,SAASE,OAAO,OAAO,IAAIF,cAAc,OAAO;YAChD,MAAME,OAAO,IAAI,IAAIF,cAAc,IAAI;YACvC,OAAOK;QACX;IACJ;AACJ;AAGO,MAAMI;IAIT,YAAYC,IAAO,CAAE;QACjB,IAAI,CAAC,IAAI,GAAGA;QACZ,IAAI,CAAC,KAAK,GAAG;IACjB;AACJ;AAGO,MAAMC;IAKT,YAAYD,IAAc,EAAEE,IAAQ,CAAE;QAClC,IAAI,CAAC,IAAI,GAAGC,MAAM,OAAO,CAACH,QAAQA,OAAO,EAAE;QAC3C,IAAI,CAAC,IAAI,GAAGE,QAAS,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG;IACjB;AACJ"}
|