@webiny/handler-graphql 5.41.0-dbt.0 → 5.41.0

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.
@@ -0,0 +1,6 @@
1
+ import { ResolverDecorators, Resolvers } from "./types";
2
+ export declare class ResolverDecoration {
3
+ private decorators;
4
+ addDecorators(resolverDecorators: ResolverDecorators): void;
5
+ decorateResolvers(resolvers: Resolvers<unknown>): Resolvers<unknown>;
6
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ResolverDecoration = void 0;
7
+ var _resolversComposition = require("@graphql-tools/resolvers-composition");
8
+ class ResolverDecoration {
9
+ decorators = {};
10
+ addDecorators(resolverDecorators) {
11
+ for (const key in resolverDecorators) {
12
+ const decorators = resolverDecorators[key];
13
+ if (!decorators) {
14
+ continue;
15
+ }
16
+ const existingDecorators = this.decorators[key] ?? [];
17
+ this.decorators[key] = [...existingDecorators, ...decorators];
18
+ }
19
+ }
20
+ decorateResolvers(resolvers) {
21
+ return (0, _resolversComposition.composeResolvers)(resolvers, this.decorators);
22
+ }
23
+ }
24
+ exports.ResolverDecoration = ResolverDecoration;
25
+
26
+ //# sourceMappingURL=ResolverDecoration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_resolversComposition","require","ResolverDecoration","decorators","addDecorators","resolverDecorators","key","existingDecorators","decorateResolvers","resolvers","composeResolvers","exports"],"sources":["ResolverDecoration.ts"],"sourcesContent":["import { composeResolvers } from \"@graphql-tools/resolvers-composition\";\nimport { ResolverDecorators, Resolvers } from \"./types\";\n\nexport class ResolverDecoration {\n private decorators: ResolverDecorators = {};\n\n addDecorators(resolverDecorators: ResolverDecorators) {\n for (const key in resolverDecorators) {\n const decorators = resolverDecorators[key];\n if (!decorators) {\n continue;\n }\n\n const existingDecorators = this.decorators[key] ?? [];\n this.decorators[key] = [...existingDecorators, ...decorators];\n }\n }\n\n decorateResolvers(resolvers: Resolvers<unknown>) {\n return composeResolvers(resolvers, this.decorators);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,OAAA;AAGO,MAAMC,kBAAkB,CAAC;EACpBC,UAAU,GAAuB,CAAC,CAAC;EAE3CC,aAAaA,CAACC,kBAAsC,EAAE;IAClD,KAAK,MAAMC,GAAG,IAAID,kBAAkB,EAAE;MAClC,MAAMF,UAAU,GAAGE,kBAAkB,CAACC,GAAG,CAAC;MAC1C,IAAI,CAACH,UAAU,EAAE;QACb;MACJ;MAEA,MAAMI,kBAAkB,GAAG,IAAI,CAACJ,UAAU,CAACG,GAAG,CAAC,IAAI,EAAE;MACrD,IAAI,CAACH,UAAU,CAACG,GAAG,CAAC,GAAG,CAAC,GAAGC,kBAAkB,EAAE,GAAGJ,UAAU,CAAC;IACjE;EACJ;EAEAK,iBAAiBA,CAACC,SAA6B,EAAE;IAC7C,OAAO,IAAAC,sCAAgB,EAACD,SAAS,EAAE,IAAI,CAACN,UAAU,CAAC;EACvD;AACJ;AAACQ,OAAA,CAAAT,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { PluginCollection } from "@webiny/plugins/types";
1
+ import { Plugin } from "@webiny/plugins/types";
2
2
  import { HandlerGraphQLOptions } from "./types";
3
- declare const _default: (options?: HandlerGraphQLOptions) => PluginCollection;
3
+ declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
4
4
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"names":["_boolean","require","_handler","_error","_interopRequireDefault","_createGraphQLSchema","_debugPlugins","_processRequestBody","DEFAULT_CACHE_MAX_AGE","createCacheKey","context","plugins","getSchemaPlugins","tenant","tenancy","getCurrentTenant","contentLocale","i18n","getContentLocale","id","code","length","toString","filter","Boolean","join","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","stringify","type","message","data","name","stack","_default","options","schema","undefined","cacheKey","debug","boolean","path","route","RoutePlugin","onPost","onOptions","_","reply","status","headers","send","hijack","request","contextCacheKey","createGraphQLSchema","ex","console","result","processRequestBody","debugPlugins","exports","default"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { boolean } from \"boolean\";\nimport { GraphQLSchema } from \"graphql\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport WebinyError from \"@webiny/error\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\nimport { Context } from \"@webiny/handler\";\nimport { GraphQLRequestBody, HandlerGraphQLOptions } from \"./types\";\nimport { createGraphQLSchema, getSchemaPlugins } from \"./createGraphQLSchema\";\nimport debugPlugins from \"./debugPlugins\";\nimport { processRequestBody } from \"./processRequestBody\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\nconst createCacheKey = (context: Context) => {\n const plugins = getSchemaPlugins(context);\n // TODO: in the near future, we have to assign a fixed name to every\n // TODO: GraphQLSchema plugin, to be able to create a reliable cache key.\n\n // TODO: `getCurrentTenant` should be injected as a parameter.\n // @ts-expect-error TODO: We should not be accessing `context` like this here.\n const tenant = context.tenancy?.getCurrentTenant();\n\n // TODO: `getContentLocale` should be injected as a parameter.\n // @ts-expect-error TODO: We should not be accessing `context` like this here.\n const contentLocale = context.i18n?.getContentLocale();\n\n return [\n tenant ? `tenant:${tenant.id}` : null,\n contentLocale ? `locale:${contentLocale.code}` : null,\n plugins.length.toString()\n ]\n .filter(Boolean)\n .join(\"#\");\n};\n\nconst createRequestBody = (body: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n /**\n * We are trusting that the body payload is correct.\n * The `processRequestBody` will fail if it is not.\n */\n return typeof body === \"string\" ? JSON.parse(body) : body;\n};\n\nconst formatErrorPayload = (error: Error): string => {\n if (error instanceof WebinyError) {\n return JSON.stringify({\n type: \"CoreGraphQLWebinyError\",\n message: error.message,\n code: error.code,\n data: error.data\n });\n }\n\n return JSON.stringify({\n type: \"Error\",\n name: error.name,\n message: error.message,\n stack: error.stack\n });\n};\n\nexport default (options: HandlerGraphQLOptions = {}): PluginCollection => {\n let schema: GraphQLSchema | undefined = undefined;\n let cacheKey: string | undefined = undefined;\n\n const debug = boolean(options.debug);\n\n const path = options?.path || \"/graphql\";\n\n const route = new RoutePlugin(async ({ onPost, onOptions, context }) => {\n onOptions(path, async (_, reply) => {\n return reply\n .status(204)\n .headers({\n \"Cache-Control\": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`\n })\n .send({})\n .hijack();\n });\n onPost(path, async (request, reply) => {\n const contextCacheKey = createCacheKey(context as Context);\n if (!schema || cacheKey !== contextCacheKey) {\n try {\n schema = createGraphQLSchema(context);\n cacheKey = contextCacheKey;\n } catch (ex) {\n return reply.code(500).send(formatErrorPayload(ex));\n }\n }\n let body: GraphQLRequestBody | GraphQLRequestBody[];\n try {\n body = createRequestBody(request.body);\n } catch (ex) {\n console.error(`Error while creating the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n try {\n const result = await processRequestBody(body, schema, context);\n return reply.status(200).send(result);\n } catch (ex) {\n console.error(`Error while processing the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n });\n\n route.name = \"handler.graphql.route.default\";\n\n return [\n ...(debug ? debugPlugins() : []),\n {\n type: \"wcp-telemetry-tracker\"\n },\n route\n ];\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAIA,IAAAI,oBAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAF,sBAAA,CAAAH,OAAA;AACA,IAAAM,mBAAA,GAAAN,OAAA;AAEA,MAAMO,qBAAqB,GAAG,QAAQ,CAAC,CAAC;;AAExC,MAAMC,cAAc,GAAIC,OAAgB,IAAK;EACzC,MAAMC,OAAO,GAAG,IAAAC,qCAAgB,EAACF,OAAO,CAAC;EACzC;EACA;;EAEA;EACA;EACA,MAAMG,MAAM,GAAGH,O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EAAE/B,OAAO,CAAC;QAC9D,OAAO0C,KAAK,CAACC,MAAM,CAAC,GAAG,CAAC,CAACE,IAAI,CAACO,MAAM,CAAC;MACzC,CAAC,CAAC,OAAOF,EAAE,EAAE;QACTC,OAAO,CAAC9B,KAAK,CAAE,0CAAyC,CAAC;QACzD8B,OAAO,CAAC9B,KAAK,CAACD,kBAAkB,CAAC8B,EAAE,CAAC,CAAC;QACrC,MAAMA,EAAE;MACZ;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFb,KAAK,CAACV,IAAI,GAAG,+BAA+B;EAE5C,OAAO,CACH,IAAIO,KAAK,GAAG,IAAAoB,qBAAY,EAAC,CAAC,GAAG,EAAE,CAAC,EAChC;IACI9B,IAAI,EAAE;EACV,CAAC,EACDa,KAAK,CACR;AACL,CAAC;AAAAkB,OAAA,CAAAC,OAAA,GAAA3B,QAAA","ignoreList":[]}
1
+ {"version":3,"names":["_boolean","require","_handler","_error","_interopRequireDefault","_createGraphQLSchema","_debugPlugins","_processRequestBody","DEFAULT_CACHE_MAX_AGE","createCacheKey","context","plugins","getSchemaPlugins","tenant","tenancy","getCurrentTenant","contentLocale","i18n","getContentLocale","id","code","length","toString","filter","Boolean","join","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","stringify","type","message","data","name","stack","_default","options","schema","undefined","cacheKey","debug","boolean","path","route","RoutePlugin","onPost","onOptions","_","reply","status","headers","send","hijack","request","contextCacheKey","createGraphQLSchema","ex","console","result","processRequestBody","debugPlugins","exports","default"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { boolean } from \"boolean\";\nimport { GraphQLSchema } from \"graphql\";\nimport { Context, RoutePlugin } from \"@webiny/handler\";\nimport WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { GraphQLRequestBody, HandlerGraphQLOptions } from \"./types\";\nimport { createGraphQLSchema, getSchemaPlugins } from \"./createGraphQLSchema\";\nimport debugPlugins from \"./debugPlugins\";\nimport { processRequestBody } from \"./processRequestBody\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\nconst createCacheKey = (context: Context) => {\n const plugins = getSchemaPlugins(context);\n // TODO: in the near future, we have to assign a fixed name to every\n // TODO: GraphQLSchema plugin, to be able to create a reliable cache key.\n\n // TODO: `getCurrentTenant` should be injected as a parameter.\n // @ts-expect-error TODO: We should not be accessing `context` like this here.\n const tenant = context.tenancy?.getCurrentTenant();\n\n // TODO: `getContentLocale` should be injected as a parameter.\n // @ts-expect-error TODO: We should not be accessing `context` like this here.\n const contentLocale = context.i18n?.getContentLocale();\n\n return [\n tenant ? `tenant:${tenant.id}` : null,\n contentLocale ? `locale:${contentLocale.code}` : null,\n plugins.length.toString()\n ]\n .filter(Boolean)\n .join(\"#\");\n};\n\nconst createRequestBody = (body: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n /**\n * We are trusting that the body payload is correct.\n * The `processRequestBody` will fail if it is not.\n */\n return typeof body === \"string\" ? JSON.parse(body) : body;\n};\n\nconst formatErrorPayload = (error: Error): string => {\n if (error instanceof WebinyError) {\n return JSON.stringify({\n type: \"CoreGraphQLWebinyError\",\n message: error.message,\n code: error.code,\n data: error.data\n });\n }\n\n return JSON.stringify({\n type: \"Error\",\n name: error.name,\n message: error.message,\n stack: error.stack\n });\n};\n\nexport default (options: HandlerGraphQLOptions = {}): Plugin[] => {\n let schema: GraphQLSchema | undefined = undefined;\n let cacheKey: string | undefined = undefined;\n\n const debug = boolean(options.debug);\n\n const path = options?.path || \"/graphql\";\n\n const route = new RoutePlugin(async ({ onPost, onOptions, context }) => {\n onOptions(path, async (_, reply) => {\n return reply\n .status(204)\n .headers({\n \"Cache-Control\": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`\n })\n .send({})\n .hijack();\n });\n onPost(path, async (request, reply) => {\n const contextCacheKey = createCacheKey(context as Context);\n if (!schema || cacheKey !== contextCacheKey) {\n try {\n schema = createGraphQLSchema(context);\n cacheKey = contextCacheKey;\n } catch (ex) {\n return reply.code(500).send(formatErrorPayload(ex));\n }\n }\n let body: GraphQLRequestBody | GraphQLRequestBody[];\n try {\n body = createRequestBody(request.body);\n } catch (ex) {\n console.error(`Error while creating the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n try {\n const result = await processRequestBody(body, schema, context);\n return reply.status(200).send(result);\n } catch (ex) {\n console.error(`Error while processing the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n });\n\n route.name = \"handler.graphql.route.default\";\n\n return [\n ...(debug ? debugPlugins() : []),\n {\n type: \"wcp-telemetry-tracker\"\n },\n route\n ];\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAGA,IAAAI,oBAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAF,sBAAA,CAAAH,OAAA;AACA,IAAAM,mBAAA,GAAAN,OAAA;AAEA,MAAMO,qBAAqB,GAAG,QAAQ,CAAC,CAAC;;AAExC,MAAMC,cAAc,GAAIC,OAAgB,IAAK;EACzC,MAAMC,OAAO,GAAG,IAAAC,qCAAgB,EAACF,OAAO,CAAC;EACzC;EACA;;EAEA;EACA;EACA,MAAMG,MAAM,GAAGH,OAAO,CAACI,OAAO,EAAEC,gBAAgB,CAAC,CAAC;;EAElD;EACA;EACA,MAAMC,aAAa,GAAGN,OAAO,CAACO,IAAI,EAAEC,gBAAgB,CAAC,CAAC;EAEtD,OAAO,CACHL,MAAM,GAAI,UAASA,MAAM,CAACM,EAAG,EAAC,GAAG,IAAI,EACrCH,aAAa,GAAI,UAASA,aAAa,CAACI,IAAK,EAAC,GAAG,IAAI,EACrDT,OAAO,CAACU,MAAM,CAACC,QAAQ,CAAC,CAAC,CAC5B,CACIC,MAAM,CAACC,OAAO,CAAC,CACfC,IAAI,CAAC,GAAG,CAAC;AAClB,CAAC;AAED,MAAMC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BAAY,EAAC,CAAC,GAAG,EAAE,CAAC,EAChC;IACI9B,IAAI,EAAE;EACV,CAAC,EACDa,KAAK,CACR;AACL,CAAC;AAAAkB,OAAA,CAAAC,OAAA,GAAA3B,QAAA","ignoreList":[]}
@@ -7,7 +7,9 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.getSchemaPlugins = exports.createGraphQLSchema = void 0;
8
8
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
9
9
  var _schema = require("@graphql-tools/schema");
10
+ var _merge = require("@graphql-tools/merge");
10
11
  var _builtInTypes = require("./builtInTypes");
12
+ var _ResolverDecoration = require("./ResolverDecoration");
11
13
  const getSchemaPlugins = context => {
12
14
  return context.plugins.byType("graphql-schema");
13
15
  };
@@ -15,7 +17,7 @@ exports.getSchemaPlugins = getSchemaPlugins;
15
17
  const createGraphQLSchema = context => {
16
18
  const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
17
19
 
18
- // TODO: once the API packages more closed, we'll have the opportunity
20
+ // TODO: once the API packages are more closed, we'll have the opportunity
19
21
  // TODO: to maybe import the @ps directive from `api-prerendering-service` package.
20
22
  const typeDefs = [(0, _graphqlTag.default)`
21
23
  type Query
@@ -49,20 +51,23 @@ const createGraphQLSchema = context => {
49
51
  Date: _builtInTypes.DateScalar,
50
52
  Time: _builtInTypes.TimeScalar
51
53
  }];
54
+ const resolverDecoration = new _ResolverDecoration.ResolverDecoration();
52
55
  const plugins = getSchemaPlugins(context);
53
56
  for (const plugin of plugins) {
54
- /**
55
- * TODO @ts-refactor
56
- * Figure out correct types on typeDefs and resolvers
57
- */
58
- // @ts-expect-error
59
- typeDefs.push(plugin.schema.typeDefs);
60
- // @ts-expect-error
61
- resolvers.push(plugin.schema.resolvers);
57
+ const schema = plugin.schema;
58
+ if (schema.typeDefs) {
59
+ typeDefs.push(schema.typeDefs);
60
+ }
61
+ if (schema.resolvers) {
62
+ resolvers.push(schema.resolvers);
63
+ }
64
+ if (schema.resolverDecorators) {
65
+ resolverDecoration.addDecorators(schema.resolverDecorators);
66
+ }
62
67
  }
63
68
  return (0, _schema.makeExecutableSchema)({
64
69
  typeDefs,
65
- resolvers,
70
+ resolvers: resolverDecoration.decorateResolvers((0, _merge.mergeResolvers)(resolvers)),
66
71
  inheritResolversFromInterfaces: true
67
72
  });
68
73
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_graphqlTag","_interopRequireDefault","require","_schema","_builtInTypes","getSchemaPlugins","context","plugins","byType","exports","createGraphQLSchema","scalars","map","item","scalar","typeDefs","gql","name","join","resolvers","reduce","acc","s","JSON","JsonScalar","Long","LongScalar","RefInput","RefInputScalar","Number","NumberScalar","Any","AnyScalar","DateTime","DateTimeScalar","Date","DateScalar","Time","TimeScalar","plugin","push","schema","makeExecutableSchema","inheritResolversFromInterfaces"],"sources":["createGraphQLSchema.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { GraphQLScalarPlugin, GraphQLSchemaPlugin } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\nimport {\n RefInputScalar,\n NumberScalar,\n AnyScalar,\n DateScalar,\n DateTimeScalar,\n JsonScalar,\n TimeScalar,\n LongScalar\n} from \"./builtInTypes\";\nimport { GraphQLScalarType } from \"graphql/type/definition\";\n\nexport const getSchemaPlugins = (context: Context) => {\n return context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\");\n};\n\nexport const createGraphQLSchema = (context: Context) => {\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\n // TODO: once the API packages more closed, we'll have the opportunity\n // TODO: to maybe import the @ps directive from `api-prerendering-service` package.\n const typeDefs = [\n gql`\n type Query\n type Mutation\n ${scalars.map(scalar => `scalar ${scalar.name}`).join(\" \")}\n scalar JSON\n scalar Long\n scalar RefInput\n scalar Number\n scalar Any\n scalar Date\n scalar DateTime\n scalar Time\n\n # This directive doesn't do anything on the GraphQL resolution level. It just serves\n # as a way to tell the Prerendering Service whether the GraphQL query needs to be\n # cached or not.\n directive @ps(cache: Boolean) on QUERY\n `\n ];\n\n const resolvers = [\n {\n ...scalars.reduce<Record<string, GraphQLScalarType>>((acc, s) => {\n acc[s.name] = s;\n return acc;\n }, {}),\n JSON: JsonScalar,\n Long: LongScalar,\n RefInput: RefInputScalar,\n Number: NumberScalar,\n Any: AnyScalar,\n DateTime: DateTimeScalar,\n Date: DateScalar,\n Time: TimeScalar\n }\n ];\n\n const plugins = getSchemaPlugins(context);\n for (const plugin of plugins) {\n /**\n * TODO @ts-refactor\n * Figure out correct types on typeDefs and resolvers\n */\n // @ts-expect-error\n typeDefs.push(plugin.schema.typeDefs);\n // @ts-expect-error\n resolvers.push(plugin.schema.resolvers);\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers,\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAGA,IAAAE,aAAA,GAAAF,OAAA;AAYO,MAAMG,gBAAgB,GAAIC,OAAgB,IAAK;EAClD,OAAOA,OAAO,CAACC,OAAO,CAACC,MAAM,CAAsB,gBAAgB,CAAC;AACxE,CAAC;AAACC,OAAA,CAAAJ,gBAAA,GAAAA,gBAAA;AAEK,MAAMK,mBAAmB,GAAIJ,OAAgB,IAAK;EACrD,MAAMK,OAAO,GAAGL,OAAO,CAACC,OAAO,CAC1BC,MAAM,CAAsB,gBAAgB,CAAC,CAC7CI,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACC,MAAM,CAAC;;EAE7B;EACA;EACA,MAAMC,QAAQ,GAAG,CACb,IAAAC,mBAAG,CAAC;AACZ;AACA;AACA,cAAcL,OAAO,CAACC,GAAG,CAACE,MAAM,IAAK,UAASA,MAAM,CAACG,IAAK,EAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAAE;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,CACJ;EAED,MAAMC,SAAS,GAAG,CACd;IACI,GAAGR,OAAO,CAACS,MAAM,CAAoC,CAACC,GAAG,EAAEC,CAAC,KAAK;MAC7DD,GAAG,CAACC,CAAC,CAACL,IAAI,CAAC,GAAGK,CAAC;MACf,OAAOD,GAAG;IACd,CAAC,EAAE,CAAC,CAAC,CAAC;IACNE,IAAI,EAAEC,wBAAU;IAChBC,IAAI,EAAEC,wBAAU;IAChBC,QAAQ,EAAEC,4BAAc;IACxBC,MAAM,EAAEC,0BAAY;IACpBC,GAAG,EAAEC,uBAAS;IACdC,QAAQ,EAAEC,4BAAc;IACxBC,IAAI,EAAEC,wBAAU;IAChBC,IAAI,EAAEC;EACV,CAAC,CACJ;EAED,MAAM/B,OAAO,GAAGF,gBAAgB,CAACC,OAAO,CAAC;EACzC,KAAK,MAAMiC,MAAM,IAAIhC,OAAO,EAAE;IAC1B;AACR;AACA;AACA;IACQ;IACAQ,QAAQ,CAACyB,IAAI,CAACD,MAAM,CAACE,MAAM,CAAC1B,QAAQ,CAAC;IACrC;IACAI,SAAS,CAACqB,IAAI,CAACD,MAAM,CAACE,MAAM,CAACtB,SAAS,CAAC;EAC3C;EAEA,OAAO,IAAAuB,4BAAoB,EAAC;IACxB3B,QAAQ;IACRI,SAAS;IACTwB,8BAA8B,EAAE;EACpC,CAAC,CAAC;AACN,CAAC;AAAClC,OAAA,CAAAC,mBAAA,GAAAA,mBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_graphqlTag","_interopRequireDefault","require","_schema","_merge","_builtInTypes","_ResolverDecoration","getSchemaPlugins","context","plugins","byType","exports","createGraphQLSchema","scalars","map","item","scalar","typeDefs","gql","name","join","resolvers","reduce","acc","s","JSON","JsonScalar","Long","LongScalar","RefInput","RefInputScalar","Number","NumberScalar","Any","AnyScalar","DateTime","DateTimeScalar","Date","DateScalar","Time","TimeScalar","resolverDecoration","ResolverDecoration","plugin","schema","push","resolverDecorators","addDecorators","makeExecutableSchema","decorateResolvers","mergeResolvers","inheritResolversFromInterfaces"],"sources":["createGraphQLSchema.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { mergeResolvers } from \"@graphql-tools/merge\";\nimport { GraphQLScalarType } from \"graphql/type/definition\";\nimport { GraphQLScalarPlugin, GraphQLSchemaPlugin, Resolvers, TypeDefs } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\nimport {\n RefInputScalar,\n NumberScalar,\n AnyScalar,\n DateScalar,\n DateTimeScalar,\n JsonScalar,\n TimeScalar,\n LongScalar\n} from \"./builtInTypes\";\nimport { ResolverDecoration } from \"./ResolverDecoration\";\n\nexport const getSchemaPlugins = (context: Context) => {\n return context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\");\n};\n\nexport const createGraphQLSchema = (context: Context) => {\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\n // TODO: once the API packages are more closed, we'll have the opportunity\n // TODO: to maybe import the @ps directive from `api-prerendering-service` package.\n const typeDefs: TypeDefs[] = [\n gql`\n type Query\n type Mutation\n ${scalars.map(scalar => `scalar ${scalar.name}`).join(\" \")}\n scalar JSON\n scalar Long\n scalar RefInput\n scalar Number\n scalar Any\n scalar Date\n scalar DateTime\n scalar Time\n\n # This directive doesn't do anything on the GraphQL resolution level. It just serves\n # as a way to tell the Prerendering Service whether the GraphQL query needs to be\n # cached or not.\n directive @ps(cache: Boolean) on QUERY\n `\n ];\n\n const resolvers: Resolvers<any>[] = [\n {\n ...scalars.reduce<Record<string, GraphQLScalarType>>((acc, s) => {\n acc[s.name] = s;\n return acc;\n }, {}),\n JSON: JsonScalar,\n Long: LongScalar,\n RefInput: RefInputScalar,\n Number: NumberScalar,\n Any: AnyScalar,\n DateTime: DateTimeScalar,\n Date: DateScalar,\n Time: TimeScalar\n }\n ];\n\n const resolverDecoration = new ResolverDecoration();\n\n const plugins = getSchemaPlugins(context);\n\n for (const plugin of plugins) {\n const schema = plugin.schema;\n if (schema.typeDefs) {\n typeDefs.push(schema.typeDefs);\n }\n if (schema.resolvers) {\n resolvers.push(schema.resolvers);\n }\n if (schema.resolverDecorators) {\n resolverDecoration.addDecorators(schema.resolverDecorators);\n }\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAIA,IAAAG,aAAA,GAAAH,OAAA;AAUA,IAAAI,mBAAA,GAAAJ,OAAA;AAEO,MAAMK,gBAAgB,GAAIC,OAAgB,IAAK;EAClD,OAAOA,OAAO,CAACC,OAAO,CAACC,MAAM,CAAsB,gBAAgB,CAAC;AACxE,CAAC;AAACC,OAAA,CAAAJ,gBAAA,GAAAA,gBAAA;AAEK,MAAMK,mBAAmB,GAAIJ,OAAgB,IAAK;EACrD,MAAMK,OAAO,GAAGL,OAAO,CAACC,OAAO,CAC1BC,MAAM,CAAsB,gBAAgB,CAAC,CAC7CI,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACC,MAAM,CAAC;;EAE7B;EACA;EACA,MAAMC,QAAoB,GAAG,CACzB,IAAAC,mBAAG,CAAC;AACZ;AACA;AACA,cAAcL,OAAO,CAACC,GAAG,CAACE,MAAM,IAAK,UAASA,MAAM,CAACG,IAAK,EAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAAE;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,CACJ;EAED,MAAMC,SAA2B,GAAG,CAChC;IACI,GAAGR,OAAO,CAACS,MAAM,CAAoC,CAACC,GAAG,EAAEC,CAAC,KAAK;MAC7DD,GAAG,CAACC,CAAC,CAACL,IAAI,CAAC,GAAGK,CAAC;MACf,OAAOD,GAAG;IACd,CAAC,EAAE,CAAC,CAAC,CAAC;IACNE,IAAI,EAAEC,wBAAU;IAChBC,IAAI,EAAEC,wBAAU;IAChBC,QAAQ,EAAEC,4BAAc;IACxBC,MAAM,EAAEC,0BAAY;IACpBC,GAAG,EAAEC,uBAAS;IACdC,QAAQ,EAAEC,4BAAc;IACxBC,IAAI,EAAEC,wBAAU;IAChBC,IAAI,EAAEC;EACV,CAAC,CACJ;EAED,MAAMC,kBAAkB,GAAG,IAAIC,sCAAkB,CAAC,CAAC;EAEnD,MAAMjC,OAAO,GAAGF,gBAAgB,CAACC,OAAO,CAAC;EAEzC,KAAK,MAAMmC,MAAM,IAAIlC,OAAO,EAAE;IAC1B,MAAMmC,MAAM,GAAGD,MAAM,CAACC,MAAM;IAC5B,IAAIA,MAAM,CAAC3B,QAAQ,EAAE;MACjBA,QAAQ,CAAC4B,IAAI,CAACD,MAAM,CAAC3B,QAAQ,CAAC;IAClC;IACA,IAAI2B,MAAM,CAACvB,SAAS,EAAE;MAClBA,SAAS,CAACwB,IAAI,CAACD,MAAM,CAACvB,SAAS,CAAC;IACpC;IACA,IAAIuB,MAAM,CAACE,kBAAkB,EAAE;MAC3BL,kBAAkB,CAACM,aAAa,CAACH,MAAM,CAACE,kBAAkB,CAAC;IAC/D;EACJ;EAEA,OAAO,IAAAE,4BAAoB,EAAC;IACxB/B,QAAQ;IACRI,SAAS,EAAEoB,kBAAkB,CAACQ,iBAAiB,CAAC,IAAAC,qBAAc,EAAC7B,SAAS,CAAC,CAAC;IAC1E8B,8BAA8B,EAAE;EACpC,CAAC,CAAC;AACN,CAAC;AAACxC,OAAA,CAAAC,mBAAA,GAAAA,mBAAA","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import { ResolverDecorator } from "./types";
2
+ export declare const createResolverDecorator: <TSource = any, TContext = any, TArgs = any>(decorator: ResolverDecorator<TSource, TContext, TArgs>) => ResolverDecorator<TSource, TContext, TArgs>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createResolverDecorator = void 0;
7
+ const createResolverDecorator = decorator => {
8
+ return decorator;
9
+ };
10
+ exports.createResolverDecorator = createResolverDecorator;
11
+
12
+ //# sourceMappingURL=createResolverDecorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createResolverDecorator","decorator","exports"],"sources":["createResolverDecorator.ts"],"sourcesContent":["import { ResolverDecorator } from \"./types\";\n\nexport const createResolverDecorator = <TSource = any, TContext = any, TArgs = any>(\n decorator: ResolverDecorator<TSource, TContext, TArgs>\n) => {\n return decorator;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,uBAAuB,GAChCC,SAAsD,IACrD;EACD,OAAOA,SAAS;AACpB,CAAC;AAACC,OAAA,CAAAF,uBAAA,GAAAA,uBAAA","ignoreList":[]}
package/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
+ import { Plugin } from "@webiny/plugins/types";
1
2
  import { HandlerGraphQLOptions } from "./types";
2
3
  export * from "./errors";
3
4
  export * from "./responses";
5
+ export * from "./utils";
4
6
  export * from "./plugins";
5
7
  export * from "./processRequestBody";
6
- declare const _default: (options?: HandlerGraphQLOptions) => import("@webiny/plugins/types").PluginCollection[];
8
+ export * from "./createResolverDecorator";
9
+ export * from "./ResolverDecoration";
10
+ declare const _default: (options?: HandlerGraphQLOptions) => Plugin[];
7
11
  export default _default;
package/index.js CHANGED
@@ -31,6 +31,18 @@ Object.keys(_responses).forEach(function (key) {
31
31
  }
32
32
  });
33
33
  });
34
+ var _utils = require("./utils");
35
+ Object.keys(_utils).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
38
+ if (key in exports && exports[key] === _utils[key]) return;
39
+ Object.defineProperty(exports, key, {
40
+ enumerable: true,
41
+ get: function () {
42
+ return _utils[key];
43
+ }
44
+ });
45
+ });
34
46
  var _plugins = require("./plugins");
35
47
  Object.keys(_plugins).forEach(function (key) {
36
48
  if (key === "default" || key === "__esModule") return;
@@ -55,7 +67,33 @@ Object.keys(_processRequestBody).forEach(function (key) {
55
67
  }
56
68
  });
57
69
  });
58
- var _default = (options = {}) => [(0, _createGraphQLHandler.default)(options)];
70
+ var _createResolverDecorator = require("./createResolverDecorator");
71
+ Object.keys(_createResolverDecorator).forEach(function (key) {
72
+ if (key === "default" || key === "__esModule") return;
73
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
74
+ if (key in exports && exports[key] === _createResolverDecorator[key]) return;
75
+ Object.defineProperty(exports, key, {
76
+ enumerable: true,
77
+ get: function () {
78
+ return _createResolverDecorator[key];
79
+ }
80
+ });
81
+ });
82
+ var _ResolverDecoration = require("./ResolverDecoration");
83
+ Object.keys(_ResolverDecoration).forEach(function (key) {
84
+ if (key === "default" || key === "__esModule") return;
85
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
86
+ if (key in exports && exports[key] === _ResolverDecoration[key]) return;
87
+ Object.defineProperty(exports, key, {
88
+ enumerable: true,
89
+ get: function () {
90
+ return _ResolverDecoration[key];
91
+ }
92
+ });
93
+ });
94
+ var _default = (options = {}) => {
95
+ return (0, _createGraphQLHandler.default)(options);
96
+ };
59
97
  exports.default = _default;
60
98
 
61
99
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_createGraphQLHandler","_interopRequireDefault","require","_errors","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_responses","_plugins","_processRequestBody","_default","options","createGraphQLHandler","default"],"sources":["index.ts"],"sourcesContent":["import { HandlerGraphQLOptions } from \"./types\";\nimport createGraphQLHandler from \"./createGraphQLHandler\";\n\nexport * from \"./errors\";\nexport * from \"./responses\";\nexport * from \"./plugins\";\nexport * from \"./processRequestBody\";\n\nexport default (options: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GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAU,QAAA,CAAAV,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,QAAA,CAAAV,GAAA;IAAA;EAAA;AAAA;AACA,IAAAW,mBAAA,GAAAhB,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAa,mBAAA,EAAAZ,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAW,mBAAA,CAAAX,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAG,mBAAA,CAAAX,GAAA;IAAA;EAAA;AAAA;AAAqC,IAAAY,QAAA,GAEtBA,CAACC,OAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,IAAAC,6BAAoB,EAACD,OAAO,CAAC,CAAC;AAAAR,OAAA,CAAAU,OAAA,GAAAH,QAAA","ignoreList":[]}
1
+ {"version":3,"names":["_createGraphQLHandler","_interopRequireDefault","require","_errors","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_responses","_utils","_plugins","_processRequestBody","_createResolverDecorator","_ResolverDecoration","_default","options","createGraphQLHandler","default"],"sources":["index.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/types\";\nimport { HandlerGraphQLOptions } from \"./types\";\nimport createGraphQLHandler from \"./createGraphQLHandler\";\n\nexport * from \"./errors\";\nexport * from \"./responses\";\nexport * from \"./utils\";\nexport * from \"./plugins\";\nexport * from \"./processRequestBody\";\nexport * from \"./createResolverDecor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CAAAe,wBAAA,EAAAd,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAa,wBAAA,CAAAb,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAK,wBAAA,CAAAb,GAAA;IAAA;EAAA;AAAA;AACA,IAAAc,mBAAA,GAAAnB,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAgB,mBAAA,EAAAf,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAc,mBAAA,CAAAd,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAM,mBAAA,CAAAd,GAAA;IAAA;EAAA;AAAA;AAAqC,IAAAe,QAAA,GAEtBA,CAACC,OAA8B,GAAG,CAAC,CAAC,KAAe;EAC9D,OAAO,IAAAC,6BAAoB,EAACD,OAAO,CAAC;AACxC,CAAC;AAAAX,OAAA,CAAAa,OAAA,GAAAH,QAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/handler-graphql",
3
- "version": "5.41.0-dbt.0",
3
+ "version": "5.41.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -15,11 +15,14 @@
15
15
  ],
16
16
  "dependencies": {
17
17
  "@babel/runtime": "7.24.1",
18
- "@graphql-tools/schema": "10.0.6",
19
- "@webiny/api": "5.41.0-dbt.0",
20
- "@webiny/error": "5.41.0-dbt.0",
21
- "@webiny/handler": "5.41.0-dbt.0",
22
- "@webiny/plugins": "5.41.0-dbt.0",
18
+ "@graphql-tools/merge": "9.0.8",
19
+ "@graphql-tools/resolvers-composition": "7.0.2",
20
+ "@graphql-tools/schema": "10.0.7",
21
+ "@graphql-tools/utils": "10.5.5",
22
+ "@webiny/api": "5.41.0",
23
+ "@webiny/error": "5.41.0",
24
+ "@webiny/handler": "5.41.0",
25
+ "@webiny/plugins": "5.41.0",
23
26
  "boolean": "3.2.0",
24
27
  "graphql": "15.8.0",
25
28
  "graphql-scalars": "1.12.0",
@@ -29,9 +32,9 @@
29
32
  "@babel/cli": "7.24.1",
30
33
  "@babel/core": "7.24.3",
31
34
  "@babel/preset-env": "7.24.3",
32
- "@webiny/cli": "5.41.0-dbt.0",
33
- "@webiny/handler-aws": "5.41.0-dbt.0",
34
- "@webiny/project-utils": "5.41.0-dbt.0",
35
+ "@webiny/cli": "5.41.0",
36
+ "@webiny/handler-aws": "5.41.0",
37
+ "@webiny/project-utils": "5.41.0",
35
38
  "jest": "29.7.0",
36
39
  "jest-mock-console": "1.3.0",
37
40
  "rimraf": "5.0.5",
@@ -46,5 +49,5 @@
46
49
  "build": "yarn webiny run build",
47
50
  "watch": "yarn webiny run watch"
48
51
  },
49
- "gitHead": "bbaec4dd1685579548c08bbde386aee5d96b80f8"
52
+ "gitHead": "a542f4d0806744c5e2333b3786478c4af3b6b750"
50
53
  }
@@ -1,12 +1,13 @@
1
- import { Plugin } from "@webiny/plugins";
2
- import { GraphQLSchemaDefinition, Resolvers, Types } from "../types";
3
1
  import { Context } from "@webiny/api/types";
2
+ import { Plugin } from "@webiny/plugins";
3
+ import { GraphQLSchemaDefinition, ResolverDecorators, Resolvers, TypeDefs } from "../types";
4
4
  export interface IGraphQLSchemaPlugin<TContext = Context> extends Plugin {
5
5
  schema: GraphQLSchemaDefinition<TContext>;
6
6
  }
7
7
  export interface GraphQLSchemaPluginConfig<TContext> {
8
- typeDefs?: Types;
8
+ typeDefs?: TypeDefs;
9
9
  resolvers?: Resolvers<TContext>;
10
+ resolverDecorators?: ResolverDecorators;
10
11
  }
11
12
  export declare class GraphQLSchemaPlugin<TContext = Context> extends Plugin implements IGraphQLSchemaPlugin<TContext> {
12
13
  static readonly type: string;
@@ -14,7 +14,8 @@ class GraphQLSchemaPlugin extends _plugins.Plugin {
14
14
  get schema() {
15
15
  return {
16
16
  typeDefs: this.config.typeDefs || "",
17
- resolvers: this.config.resolvers
17
+ resolvers: this.config.resolvers,
18
+ resolverDecorators: this.config.resolverDecorators
18
19
  };
19
20
  }
20
21
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_plugins","require","GraphQLSchemaPlugin","Plugin","type","constructor","config","schema","typeDefs","resolvers","exports","createGraphQLSchemaPlugin"],"sources":["GraphQLSchemaPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { GraphQLSchemaDefinition, Resolvers, Types } from \"~/types\";\nimport { Context } from \"@webiny/api/types\";\n\nexport interface IGraphQLSchemaPlugin<TContext = Context> extends Plugin {\n schema: GraphQLSchemaDefinition<TContext>;\n}\n\nexport interface GraphQLSchemaPluginConfig<TContext> {\n typeDefs?: Types;\n resolvers?: Resolvers<TContext>;\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 };\n }\n}\n\nexport const createGraphQLSchemaPlugin = <T = Context>(config: GraphQLSchemaPluginConfig<T>) => {\n return new GraphQLSchemaPlugin<T>(config);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAaO,MAAMC,mBAAmB,SACpBC,eAAM,CAElB;EACI,OAAgCC,IAAI,GAAW,gBAAgB;EAG/DC,WAAWA,CAACC,MAA2C,EAAE;IACrD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,MAAM,GAAGA,MAAM;EACxB;EAEA,IAAIC,MAAMA,CAAA,EAAsC;IAC5C,OAAO;MACHC,QAAQ,EAAE,IAAI,CAACF,MAAM,CAACE,QAAQ,IAAI,EAAE;MACpCC,SAAS,EAAE,IAAI,CAACH,MAAM,CAACG;IAC3B,CAAC;EACL;AACJ;AAACC,OAAA,CAAAR,mBAAA,GAAAA,mBAAA;AAEM,MAAMS,yBAAyB,GAAiBL,MAAoC,IAAK;EAC5F,OAAO,IAAIJ,mBAAmB,CAAII,MAAM,CAAC;AAC7C,CAAC;AAACI,OAAA,CAAAC,yBAAA,GAAAA,yBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_plugins","require","GraphQLSchemaPlugin","Plugin","type","constructor","config","schema","typeDefs","resolvers","resolverDecorators","exports","createGraphQLSchemaPlugin"],"sources":["GraphQLSchemaPlugin.ts"],"sourcesContent":["import { Context } from \"@webiny/api/types\";\nimport { Plugin } from \"@webiny/plugins\";\nimport { GraphQLSchemaDefinition, ResolverDecorators, Resolvers, TypeDefs } from \"~/types\";\n\nexport interface IGraphQLSchemaPlugin<TContext = Context> extends Plugin {\n schema: GraphQLSchemaDefinition<TContext>;\n}\n\nexport interface GraphQLSchemaPluginConfig<TContext> {\n typeDefs?: TypeDefs;\n resolvers?: Resolvers<TContext>;\n resolverDecorators?: ResolverDecorators;\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\nexport const createGraphQLSchemaPlugin = <T = Context>(config: GraphQLSchemaPluginConfig<T>) => {\n return new GraphQLSchemaPlugin<T>(config);\n};\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAaO,MAAMC,mBAAmB,SACpBC,eAAM,CAElB;EACI,OAAgCC,IAAI,GAAW,gBAAgB;EAG/DC,WAAWA,CAACC,MAA2C,EAAE;IACrD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,MAAM,GAAGA,MAAM;EACxB;EAEA,IAAIC,MAAMA,CAAA,EAAsC;IAC5C,OAAO;MACHC,QAAQ,EAAE,IAAI,CAACF,MAAM,CAACE,QAAQ,IAAI,EAAE;MACpCC,SAAS,EAAE,IAAI,CAACH,MAAM,CAACG,SAAS;MAChCC,kBAAkB,EAAE,IAAI,CAACJ,MAAM,CAACI;IACpC,CAAC;EACL;AACJ;AAACC,OAAA,CAAAT,mBAAA,GAAAA,mBAAA;AAEM,MAAMU,yBAAyB,GAAiBN,MAAoC,IAAK;EAC5F,OAAO,IAAIJ,mBAAmB,CAAII,MAAM,CAAC;AAC7C,CAAC;AAACK,OAAA,CAAAC,yBAAA,GAAAA,yBAAA","ignoreList":[]}
package/types.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { GraphQLScalarType, GraphQLFieldResolver as BaseGraphQLFieldResolver, GraphQLSchema } from "graphql";
2
2
  import { Plugin } from "@webiny/plugins/types";
3
- import { Context } from "@webiny/api/types";
3
+ import { Context, GenericRecord } from "@webiny/api/types";
4
4
  import { RouteMethodPath } from "@webiny/handler/types";
5
+ import { ResolversComposition } from "@graphql-tools/resolvers-composition";
6
+ import { IResolvers, TypeSource } from "@graphql-tools/utils";
5
7
  export interface GraphQLScalarPlugin extends Plugin {
6
8
  type: "graphql-scalar";
7
9
  scalar: GraphQLScalarType;
@@ -11,18 +13,23 @@ export interface HandlerGraphQLOptions {
11
13
  debug?: boolean | string;
12
14
  }
13
15
  export type GraphQLFieldResolver<TSource = any, TArgs = any, TContext = Context> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;
14
- export type Types = string | string[] | (() => string | string[] | Promise<string | string[]>);
16
+ /**
17
+ * @deprecated Use `TypeDefs` instead.
18
+ */
19
+ export type Types = TypeDefs;
20
+ export type TypeDefs = TypeSource;
15
21
  export interface GraphQLSchemaPluginTypeArgs {
16
22
  context?: any;
17
23
  args?: any;
18
24
  source?: any;
19
25
  }
20
- export type Resolvers<TContext> = GraphQLScalarType | GraphQLFieldResolver<any, Record<string, any>, TContext> | {
21
- [property: string]: Resolvers<TContext>;
22
- } | undefined;
26
+ export type Resolvers<TContext> = IResolvers<any, TContext>;
27
+ export type ResolverDecorator<TSource = any, TContext = any, TArgs = any> = ResolversComposition<GraphQLFieldResolver<TSource, TContext, TArgs>>;
28
+ export type ResolverDecorators = GenericRecord<string, ResolverDecorator[]>;
23
29
  export interface GraphQLSchemaDefinition<TContext> {
24
- typeDefs: Types;
30
+ typeDefs: TypeDefs;
25
31
  resolvers?: Resolvers<TContext>;
32
+ resolverDecorators?: ResolverDecorators;
26
33
  }
27
34
  export interface GraphQLSchemaPlugin<TContext extends Context = Context> extends Plugin {
28
35
  type: "graphql-schema";
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {\n GraphQLScalarType,\n GraphQLFieldResolver as BaseGraphQLFieldResolver,\n GraphQLSchema\n} from \"graphql\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { Context } from \"@webiny/api/types\";\nimport { RouteMethodPath } from \"@webiny/handler/types\";\n\nexport interface GraphQLScalarPlugin extends Plugin {\n type: \"graphql-scalar\";\n scalar: GraphQLScalarType;\n}\n\nexport interface HandlerGraphQLOptions {\n path?: RouteMethodPath;\n debug?: boolean | string;\n}\n\nexport type GraphQLFieldResolver<\n TSource = any,\n TArgs = any,\n TContext = Context\n> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;\n\n// `GraphQLSchemaPlugin` types.\nexport type Types = string | string[] | (() => string | string[] | Promise<string | string[]>);\n\nexport interface GraphQLSchemaPluginTypeArgs {\n context?: any;\n args?: any;\n source?: any;\n}\n\nexport type Resolvers<TContext> =\n | GraphQLScalarType\n | GraphQLFieldResolver<any, Record<string, any>, TContext>\n | { [property: string]: Resolvers<TContext> }\n | undefined;\n\nexport interface GraphQLSchemaDefinition<TContext> {\n typeDefs: Types;\n resolvers?: Resolvers<TContext>;\n}\n\nexport interface GraphQLSchemaPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-schema\";\n schema: GraphQLSchemaDefinition<TContext>;\n}\n\nexport interface GraphQLRequestBody {\n query: string;\n variables: Record<string, any>;\n operationName: string;\n}\n\nexport interface GraphQLBeforeQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-before-query\";\n apply(params: { body: GraphQLRequestBody; schema: GraphQLSchema; context: TContext }): void;\n}\n\nexport interface GraphQLAfterQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-after-query\";\n apply(params: {\n result: any;\n body: GraphQLRequestBody;\n schema: GraphQLSchema;\n context: TContext;\n }): void;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {\n GraphQLScalarType,\n GraphQLFieldResolver as BaseGraphQLFieldResolver,\n GraphQLSchema\n} from \"graphql\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { Context, GenericRecord } from \"@webiny/api/types\";\nimport { RouteMethodPath } from \"@webiny/handler/types\";\nimport { ResolversComposition } from \"@graphql-tools/resolvers-composition\";\nimport { IResolvers, TypeSource } from \"@graphql-tools/utils\";\n\nexport interface GraphQLScalarPlugin extends Plugin {\n type: \"graphql-scalar\";\n scalar: GraphQLScalarType;\n}\n\nexport interface HandlerGraphQLOptions {\n path?: RouteMethodPath;\n debug?: boolean | string;\n}\n\nexport type GraphQLFieldResolver<\n TSource = any,\n TArgs = any,\n TContext = Context\n> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;\n\n/**\n * @deprecated Use `TypeDefs` instead.\n */\nexport type Types = TypeDefs;\nexport type TypeDefs = TypeSource;\n\nexport interface GraphQLSchemaPluginTypeArgs {\n context?: any;\n args?: any;\n source?: any;\n}\n\nexport type Resolvers<TContext> = IResolvers<any, TContext>;\n\nexport type ResolverDecorator<TSource = any, TContext = any, TArgs = any> = ResolversComposition<\n GraphQLFieldResolver<TSource, TContext, TArgs>\n>;\n\nexport type ResolverDecorators = GenericRecord<string, ResolverDecorator[]>;\n\nexport interface GraphQLSchemaDefinition<TContext> {\n typeDefs: TypeDefs;\n resolvers?: Resolvers<TContext>;\n resolverDecorators?: ResolverDecorators;\n}\n\nexport interface GraphQLSchemaPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-schema\";\n schema: GraphQLSchemaDefinition<TContext>;\n}\n\nexport interface GraphQLRequestBody {\n query: string;\n variables: Record<string, any>;\n operationName: string;\n}\n\nexport interface GraphQLBeforeQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-before-query\";\n apply(params: { body: GraphQLRequestBody; schema: GraphQLSchema; context: TContext }): void;\n}\n\nexport interface GraphQLAfterQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-after-query\";\n apply(params: {\n result: any;\n body: GraphQLRequestBody;\n schema: GraphQLSchema;\n context: TContext;\n }): void;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export * from "./resolve";
package/utils/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _resolve = require("./resolve");
7
+ Object.keys(_resolve).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _resolve[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _resolve[key];
14
+ }
15
+ });
16
+ });
17
+
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_resolve","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["index.ts"],"sourcesContent":["export * from \"./resolve\";\n"],"mappings":";;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,QAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,QAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,QAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,21 @@
1
+ import { ErrorResponse, ListErrorResponse, ListResponse, Response } from "../responses";
2
+ import { GenericRecord } from "@webiny/api/types";
3
+ export interface Meta {
4
+ totalCount: number;
5
+ hasMoreItems: boolean;
6
+ cursor: string | null;
7
+ }
8
+ export declare const emptyResolver: () => {};
9
+ interface ResolveCallable<T = GenericRecord> {
10
+ (): Promise<T>;
11
+ }
12
+ export declare const resolve: <T = GenericRecord<PropertyKey, any>>(fn: ResolveCallable<T>) => Promise<ErrorResponse | Response<Awaited<T>>>;
13
+ interface ResolveListCallable<T> {
14
+ (): Promise<IListResult<T>>;
15
+ }
16
+ interface IListResult<T = GenericRecord> {
17
+ items: T[];
18
+ meta: Meta;
19
+ }
20
+ export declare const resolveList: <T = GenericRecord<PropertyKey, any>>(fn: ResolveListCallable<T>) => Promise<ListErrorResponse | ListResponse<T, Meta>>;
21
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.resolveList = exports.resolve = exports.emptyResolver = void 0;
7
+ var _responses = require("../responses");
8
+ const emptyResolver = () => ({});
9
+ exports.emptyResolver = emptyResolver;
10
+ const resolve = async fn => {
11
+ try {
12
+ return new _responses.Response(await fn());
13
+ } catch (ex) {
14
+ return new _responses.ErrorResponse(ex);
15
+ }
16
+ };
17
+ exports.resolve = resolve;
18
+ const resolveList = async fn => {
19
+ try {
20
+ const result = await fn();
21
+ return new _responses.ListResponse(result.items, result.meta);
22
+ } catch (ex) {
23
+ return new _responses.ListErrorResponse(ex);
24
+ }
25
+ };
26
+ exports.resolveList = resolveList;
27
+
28
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_responses","require","emptyResolver","exports","resolve","fn","Response","ex","ErrorResponse","resolveList","result","ListResponse","items","meta","ListErrorResponse"],"sources":["resolve.ts"],"sourcesContent":["import { ErrorResponse, ListErrorResponse, ListResponse, Response } from \"~/responses\";\nimport { GenericRecord } from \"@webiny/api/types\";\n\nexport interface Meta {\n totalCount: number;\n hasMoreItems: boolean;\n cursor: string | null;\n}\n\nexport const emptyResolver = () => ({});\n\ninterface ResolveCallable<T = GenericRecord> {\n (): Promise<T>;\n}\n\nexport const resolve = async <T = GenericRecord>(fn: ResolveCallable<T>) => {\n try {\n return new Response(await fn());\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n};\n\ninterface ResolveListCallable<T> {\n (): Promise<IListResult<T>>;\n}\n\ninterface IListResult<T = GenericRecord> {\n items: T[];\n meta: Meta;\n}\n\nexport const resolveList = async <T = GenericRecord>(fn: ResolveListCallable<T>) => {\n try {\n const result = (await fn()) as IListResult<T>;\n return new ListResponse(result.items, result.meta);\n } catch (ex) {\n return new ListErrorResponse(ex);\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AASO,MAAMC,aAAa,GAAGA,CAAA,MAAO,CAAC,CAAC,CAAC;AAACC,OAAA,CAAAD,aAAA,GAAAA,aAAA;AAMjC,MAAME,OAAO,GAAG,MAA0BC,EAAsB,IAAK;EACxE,IAAI;IACA,OAAO,IAAIC,mBAAQ,CAAC,MAAMD,EAAE,CAAC,CAAC,CAAC;EACnC,CAAC,CAAC,OAAOE,EAAE,EAAE;IACT,OAAO,IAAIC,wBAAa,CAACD,EAAE,CAAC;EAChC;AACJ,CAAC;AAACJ,OAAA,CAAAC,OAAA,GAAAA,OAAA;AAWK,MAAMK,WAAW,GAAG,MAA0BJ,EAA0B,IAAK;EAChF,IAAI;IACA,MAAMK,MAAM,GAAI,MAAML,EAAE,CAAC,CAAoB;IAC7C,OAAO,IAAIM,uBAAY,CAACD,MAAM,CAACE,KAAK,EAAEF,MAAM,CAACG,IAAI,CAAC;EACtD,CAAC,CAAC,OAAON,EAAE,EAAE;IACT,OAAO,IAAIO,4BAAiB,CAACP,EAAE,CAAC;EACpC;AACJ,CAAC;AAACJ,OAAA,CAAAM,WAAA,GAAAA,WAAA","ignoreList":[]}