@webiny/handler-graphql 0.0.0-unstable.ecd8734205 → 0.0.0-unstable.f6dc066313

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/README.md +9 -5
  2. package/ResolverDecoration.d.ts +6 -0
  3. package/ResolverDecoration.js +19 -0
  4. package/ResolverDecoration.js.map +1 -0
  5. package/builtInTypes/AnyScalar.d.ts +1 -1
  6. package/builtInTypes/AnyScalar.js +4 -9
  7. package/builtInTypes/AnyScalar.js.map +1 -1
  8. package/builtInTypes/DateScalar.d.ts +1 -1
  9. package/builtInTypes/DateScalar.js +10 -13
  10. package/builtInTypes/DateScalar.js.map +1 -1
  11. package/builtInTypes/DateTimeScalar.d.ts +1 -1
  12. package/builtInTypes/DateTimeScalar.js +10 -13
  13. package/builtInTypes/DateTimeScalar.js.map +1 -1
  14. package/builtInTypes/DateTimeZScalar.d.ts +1 -1
  15. package/builtInTypes/DateTimeZScalar.js +10 -16
  16. package/builtInTypes/DateTimeZScalar.js.map +1 -1
  17. package/builtInTypes/IconScalar.d.ts +10 -0
  18. package/builtInTypes/IconScalar.js +93 -0
  19. package/builtInTypes/IconScalar.js.map +1 -0
  20. package/builtInTypes/JsonScalar.d.ts +1 -1
  21. package/builtInTypes/JsonScalar.js +3 -8
  22. package/builtInTypes/JsonScalar.js.map +1 -1
  23. package/builtInTypes/LongScalar.d.ts +2 -1
  24. package/builtInTypes/LongScalar.js +48 -8
  25. package/builtInTypes/LongScalar.js.map +1 -1
  26. package/builtInTypes/NumberScalar.d.ts +1 -1
  27. package/builtInTypes/NumberScalar.js +14 -21
  28. package/builtInTypes/NumberScalar.js.map +1 -1
  29. package/builtInTypes/RefInputScalar.d.ts +1 -1
  30. package/builtInTypes/RefInputScalar.js +40 -18
  31. package/builtInTypes/RefInputScalar.js.map +1 -1
  32. package/builtInTypes/TimeScalar.d.ts +1 -1
  33. package/builtInTypes/TimeScalar.js +11 -17
  34. package/builtInTypes/TimeScalar.js.map +1 -1
  35. package/builtInTypes/index.d.ts +10 -9
  36. package/builtInTypes/index.js +11 -103
  37. package/builtInTypes/index.js.map +1 -1
  38. package/createGraphQLHandler.d.ts +3 -3
  39. package/createGraphQLHandler.js +43 -34
  40. package/createGraphQLHandler.js.map +1 -1
  41. package/createGraphQLSchema.d.ts +4 -2
  42. package/createGraphQLSchema.js +78 -45
  43. package/createGraphQLSchema.js.map +1 -1
  44. package/createRequestBody.d.ts +2 -0
  45. package/createRequestBody.js +26 -0
  46. package/createRequestBody.js.map +1 -0
  47. package/createResolverDecorator.d.ts +2 -0
  48. package/createResolverDecorator.js +5 -0
  49. package/createResolverDecorator.js.map +1 -0
  50. package/debugPlugins.d.ts +2 -2
  51. package/debugPlugins.js +6 -11
  52. package/debugPlugins.js.map +1 -1
  53. package/errors.js +4 -10
  54. package/errors.js.map +1 -1
  55. package/exports/api/graphql.d.ts +2 -0
  56. package/exports/api/graphql.js +4 -0
  57. package/exports/api/graphql.js.map +1 -0
  58. package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.d.ts +16 -0
  59. package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js +64 -0
  60. package/features/GraphQLSchemaBuilder/GraphQLSchemaBuilder.js.map +1 -0
  61. package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.d.ts +13 -0
  62. package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js +29 -0
  63. package/features/GraphQLSchemaBuilder/GraphQLSchemaComposer.js.map +1 -0
  64. package/features/GraphQLSchemaBuilder/abstractions.d.ts +34 -0
  65. package/features/GraphQLSchemaBuilder/abstractions.js +5 -0
  66. package/features/GraphQLSchemaBuilder/abstractions.js.map +1 -0
  67. package/features/GraphQLSchemaBuilder/feature.d.ts +1 -0
  68. package/features/GraphQLSchemaBuilder/feature.js +10 -0
  69. package/features/GraphQLSchemaBuilder/feature.js.map +1 -0
  70. package/graphql/abstractions.core.d.ts +11 -0
  71. package/graphql/abstractions.core.js +10 -0
  72. package/graphql/abstractions.core.js.map +1 -0
  73. package/graphql/abstractions.d.ts +2 -0
  74. package/graphql/abstractions.js +4 -0
  75. package/graphql/abstractions.js.map +1 -0
  76. package/graphql/abstractions.public.d.ts +19 -0
  77. package/graphql/abstractions.public.js +12 -0
  78. package/graphql/abstractions.public.js.map +1 -0
  79. package/index.d.ts +10 -5
  80. package/index.js +12 -46
  81. package/index.js.map +1 -1
  82. package/interceptConsole.js +8 -13
  83. package/interceptConsole.js.map +1 -1
  84. package/package.json +23 -26
  85. package/plugins/GraphQLSchemaPlugin.d.ts +13 -5
  86. package/plugins/GraphQLSchemaPlugin.js +16 -14
  87. package/plugins/GraphQLSchemaPlugin.js.map +1 -1
  88. package/plugins/index.d.ts +1 -1
  89. package/plugins/index.js +2 -15
  90. package/plugins/index.js.map +1 -1
  91. package/processRequestBody.d.ts +4 -5
  92. package/processRequestBody.js +15 -13
  93. package/processRequestBody.js.map +1 -1
  94. package/responses.js +7 -28
  95. package/responses.js.map +1 -1
  96. package/types.d.ts +20 -13
  97. package/types.js +2 -4
  98. package/types.js.map +1 -1
  99. package/utils/index.d.ts +1 -0
  100. package/utils/index.js +3 -0
  101. package/utils/index.js.map +1 -0
  102. package/utils/resolve.d.ts +21 -0
  103. package/utils/resolve.js +19 -0
  104. package/utils/resolve.js.map +1 -0
@@ -1,25 +1,28 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createGraphQLSchema = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
10
- var _schema = require("@graphql-tools/schema");
11
- var _builtInTypes = require("./builtInTypes");
12
- const createGraphQLSchema = context => {
1
+ import gql from "graphql-tag";
2
+ import { makeExecutableSchema } from "@graphql-tools/schema";
3
+ import { mergeResolvers } from "@graphql-tools/merge";
4
+ import { RefInputScalar, NumberScalar, AnyScalar, DateScalar, DateTimeScalar, JsonScalar, TimeScalar, LongScalar, IconScalar } from "./builtInTypes/index.js";
5
+ import { ResolverDecoration } from "./ResolverDecoration.js";
6
+ import { GraphQLSchemaComposer } from "./features/GraphQLSchemaBuilder/abstractions.js";
7
+ import { GraphQLSchemaComposerFeature } from "./features/GraphQLSchemaBuilder/feature.js";
8
+ export const getSchemaPlugins = context => {
9
+ return context.plugins.byType("graphql-schema").filter(pl => {
10
+ if (typeof pl.isApplicable === "function") {
11
+ return pl.isApplicable(context);
12
+ }
13
+ return true;
14
+ });
15
+ };
16
+ export const createGraphQLSchema = async context => {
17
+ GraphQLSchemaComposerFeature.register(context.container);
13
18
  const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
14
-
15
- // TODO: once the API packages more closed, we'll have the opportunity
16
- // TODO: to maybe import the @ps directive from `api-prerendering-service` package.
17
- const typeDefs = [(0, _graphqlTag.default)`
19
+ const typeDefs = [gql`
18
20
  type Query
19
21
  type Mutation
20
22
  ${scalars.map(scalar => `scalar ${scalar.name}`).join(" ")}
21
23
  scalar JSON
22
24
  scalar Long
25
+ scalar Icon
23
26
  scalar RefInput
24
27
  scalar Number
25
28
  scalar Any
@@ -27,39 +30,69 @@ const createGraphQLSchema = context => {
27
30
  scalar DateTime
28
31
  scalar Time
29
32
 
30
- # This directive doesn't do anything on the GraphQL resolution level. It just serves
31
- # as a way to tell the Prerendering Service whether the GraphQL query needs to be
32
- # cached or not.
33
- directive @ps(cache: Boolean) on QUERY
33
+ type Error {
34
+ code: String
35
+ message: String
36
+ data: JSON
37
+ stack: String
38
+ }
39
+
40
+ type BooleanResponse {
41
+ data: Boolean
42
+ error: Error
43
+ }
34
44
  `];
35
- const resolvers = [(0, _objectSpread2.default)((0, _objectSpread2.default)({}, scalars.reduce((acc, s) => {
36
- acc[s.name] = s;
37
- return acc;
38
- }, {})), {}, {
39
- JSON: _builtInTypes.JsonScalar,
40
- Long: _builtInTypes.LongScalar,
41
- RefInput: _builtInTypes.RefInputScalar,
42
- Number: _builtInTypes.NumberScalar,
43
- Any: _builtInTypes.AnyScalar,
44
- DateTime: _builtInTypes.DateTimeScalar,
45
- Date: _builtInTypes.DateScalar,
46
- Time: _builtInTypes.TimeScalar
47
- })];
48
- const plugins = context.plugins.byType("graphql-schema");
45
+ const resolvers = [{
46
+ ...scalars.reduce((acc, s) => {
47
+ acc[s.name] = s;
48
+ return acc;
49
+ }, {}),
50
+ JSON: JsonScalar,
51
+ Long: LongScalar,
52
+ RefInput: RefInputScalar,
53
+ Number: NumberScalar,
54
+ Any: AnyScalar,
55
+ DateTime: DateTimeScalar,
56
+ Date: DateScalar,
57
+ Time: TimeScalar,
58
+ Icon: IconScalar
59
+ }];
60
+ const resolverDecoration = new ResolverDecoration();
61
+
62
+ // Process legacy plugins
63
+ const plugins = getSchemaPlugins(context);
49
64
  for (const plugin of plugins) {
50
- /**
51
- * TODO @ts-refactor
52
- * Figure out correct types on typeDefs and resolvers
53
- */
54
- // @ts-ignore
55
- typeDefs.push(plugin.schema.typeDefs);
56
- // @ts-ignore
57
- resolvers.push(plugin.schema.resolvers);
65
+ const schema = plugin.schema;
66
+ if (schema.typeDefs) {
67
+ typeDefs.push(schema.typeDefs);
68
+ }
69
+ if (schema.resolvers) {
70
+ resolvers.push(schema.resolvers);
71
+ }
72
+ if (schema.resolverDecorators) {
73
+ resolverDecoration.addDecorators(schema.resolverDecorators);
74
+ }
58
75
  }
59
- return (0, _schema.makeExecutableSchema)({
76
+
77
+ // Process new DI implementations
78
+ const graphQLSchemaComposer = context.container.resolve(GraphQLSchemaComposer);
79
+ const schema = await graphQLSchemaComposer.build();
80
+ if (schema.typeDefs) {
81
+ typeDefs.push(schema.typeDefs);
82
+ }
83
+ if (schema.resolvers) {
84
+ resolvers.push(schema.resolvers);
85
+ }
86
+ if (schema.resolverDecorators) {
87
+ resolverDecoration.addDecorators(schema.resolverDecorators);
88
+ }
89
+
90
+ // Create executable schema
91
+ return makeExecutableSchema({
60
92
  typeDefs,
61
- resolvers,
93
+ resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),
62
94
  inheritResolversFromInterfaces: true
63
95
  });
64
96
  };
65
- exports.createGraphQLSchema = createGraphQLSchema;
97
+
98
+ //# sourceMappingURL=createGraphQLSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createGraphQLSchema","context","scalars","plugins","byType","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 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 = context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\");\n for (const plugin of plugins) {\n /**\n * TODO @ts-refactor\n * Figure out correct types on typeDefs and resolvers\n */\n // @ts-ignore\n typeDefs.push(plugin.schema.typeDefs);\n // @ts-ignore\n resolvers.push(plugin.schema.resolvers);\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers,\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAGA;AAYO,MAAMA,mBAAmB,GAAIC,OAAgB,IAAK;EACrD,MAAMC,OAAO,GAAGD,OAAO,CAACE,OAAO,CAC1BC,MAAM,CAAsB,gBAAgB,CAAC,CAC7CC,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACC,MAAM,CAAC;;EAE7B;EACA;EACA,MAAMC,QAAQ,GAAG,CACb,IAAAC,mBAAG,CAAC;AACZ;AACA;AACA,cAAcP,OAAO,CAACG,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,6DAEPV,OAAO,CAACW,MAAM,CAAoC,CAACC,GAAG,EAAEC,CAAC,KAAK;IAC7DD,GAAG,CAACC,CAAC,CAACL,IAAI,CAAC,GAAGK,CAAC;IACf,OAAOD,GAAG;EACd,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;EAAU,GAEvB;EAED,MAAM5B,OAAO,GAAGF,OAAO,CAACE,OAAO,CAACC,MAAM,CAAsB,gBAAgB,CAAC;EAC7E,KAAK,MAAM4B,MAAM,IAAI7B,OAAO,EAAE;IAC1B;AACR;AACA;AACA;IACQ;IACAK,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;AAAC"}
1
+ {"version":3,"names":["gql","makeExecutableSchema","mergeResolvers","RefInputScalar","NumberScalar","AnyScalar","DateScalar","DateTimeScalar","JsonScalar","TimeScalar","LongScalar","IconScalar","ResolverDecoration","GraphQLSchemaComposer","GraphQLSchemaComposerFeature","getSchemaPlugins","context","plugins","byType","filter","pl","isApplicable","createGraphQLSchema","register","container","scalars","map","item","scalar","typeDefs","name","join","resolvers","reduce","acc","s","JSON","Long","RefInput","Number","Any","DateTime","Date","Time","Icon","resolverDecoration","plugin","schema","push","resolverDecorators","addDecorators","graphQLSchemaComposer","resolve","build","decorateResolvers","inheritResolversFromInterfaces"],"sources":["createGraphQLSchema.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { mergeResolvers } from \"@graphql-tools/merge\";\nimport type { GraphQLScalarType } from \"graphql/type/definition.js\";\nimport type { GraphQLScalarPlugin, Resolvers, TypeDefs } from \"./types.js\";\nimport type { Context } from \"@webiny/api/types.js\";\nimport {\n RefInputScalar,\n NumberScalar,\n AnyScalar,\n DateScalar,\n DateTimeScalar,\n JsonScalar,\n TimeScalar,\n LongScalar,\n IconScalar\n} from \"./builtInTypes/index.js\";\nimport { ResolverDecoration } from \"./ResolverDecoration.js\";\nimport type { GraphQLSchemaPlugin } from \"~/plugins/index.js\";\nimport { GraphQLSchemaComposer } from \"~/features/GraphQLSchemaBuilder/abstractions.js\";\nimport { GraphQLSchemaComposerFeature } from \"~/features/GraphQLSchemaBuilder/feature.js\";\n\nexport const getSchemaPlugins = (context: Context) => {\n return context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\").filter(pl => {\n if (typeof pl.isApplicable === \"function\") {\n return pl.isApplicable(context);\n }\n return true;\n });\n};\n\nexport const createGraphQLSchema = async (context: Context) => {\n GraphQLSchemaComposerFeature.register(context.container);\n\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\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 Icon\n scalar RefInput\n scalar Number\n scalar Any\n scalar Date\n scalar DateTime\n scalar Time\n\n type Error {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type BooleanResponse {\n data: Boolean\n error: Error\n }\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 Icon: IconScalar\n }\n ];\n\n const resolverDecoration = new ResolverDecoration();\n\n // Process legacy plugins\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 // Process new DI implementations\n const graphQLSchemaComposer = context.container.resolve(GraphQLSchemaComposer);\n const schema = await graphQLSchemaComposer.build();\n\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 // Create executable schema\n return makeExecutableSchema({\n typeDefs,\n resolvers: resolverDecoration.decorateResolvers(mergeResolvers(resolvers)),\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":"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","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { GraphQLRequestBody } from "./types.js";
2
+ export declare const createRequestBody: (input: unknown) => GraphQLRequestBody | GraphQLRequestBody[];
@@ -0,0 +1,26 @@
1
+ import zod from "zod";
2
+ import { WebinyError } from "@webiny/error";
3
+ import { createZodError } from "@webiny/utils/createZodError.js";
4
+ const requestBodySchema = zod.object({
5
+ query: zod.string(),
6
+ variables: zod.record(zod.any()).nullish().optional(),
7
+ operationName: zod.string().nullish().optional().transform(value => {
8
+ return value || undefined;
9
+ })
10
+ }).passthrough();
11
+ const schema = zod.union([requestBodySchema, zod.array(requestBodySchema)]);
12
+ export const createRequestBody = input => {
13
+ const body = typeof input === "string" ? JSON.parse(input) : input;
14
+ const result = schema.safeParse(body);
15
+ if (!result.success) {
16
+ const error = createZodError(result.error);
17
+ throw new WebinyError({
18
+ message: "Invalid GraphQL request! Check your query and variables.",
19
+ code: "GRAPHQL_REQUEST_INVALID",
20
+ data: error.data
21
+ });
22
+ }
23
+ return result.data;
24
+ };
25
+
26
+ //# sourceMappingURL=createRequestBody.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["zod","WebinyError","createZodError","requestBodySchema","object","query","string","variables","record","any","nullish","optional","operationName","transform","value","undefined","passthrough","schema","union","array","createRequestBody","input","body","JSON","parse","result","safeParse","success","error","message","code","data"],"sources":["createRequestBody.ts"],"sourcesContent":["import zod from \"zod\";\nimport { WebinyError } from \"@webiny/error\";\nimport { createZodError } from \"@webiny/utils/createZodError.js\";\nimport type { GraphQLRequestBody } from \"~/types.js\";\n\nconst requestBodySchema = zod\n .object({\n query: zod.string(),\n variables: zod.record(zod.any()).nullish().optional(),\n operationName: zod\n .string()\n .nullish()\n .optional()\n .transform(value => {\n return value || undefined;\n })\n })\n .passthrough();\n\nconst schema = zod.union([requestBodySchema, zod.array(requestBodySchema)]);\n\nexport const createRequestBody = (input: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n const body = typeof input === \"string\" ? JSON.parse(input) : input;\n\n const result = schema.safeParse(body);\n if (!result.success) {\n const error = createZodError(result.error);\n throw new WebinyError({\n message: \"Invalid GraphQL request! Check your query and variables.\",\n code: \"GRAPHQL_REQUEST_INVALID\",\n data: error.data\n });\n }\n return result.data;\n};\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AACrB,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,cAAc,QAAQ,iCAAiC;AAGhE,MAAMC,iBAAiB,GAAGH,GAAG,CACxBI,MAAM,CAAC;EACJC,KAAK,EAAEL,GAAG,CAACM,MAAM,CAAC,CAAC;EACnBC,SAAS,EAAEP,GAAG,CAACQ,MAAM,CAACR,GAAG,CAACS,GAAG,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACrDC,aAAa,EAAEZ,GAAG,CACbM,MAAM,CAAC,CAAC,CACRI,OAAO,CAAC,CAAC,CACTC,QAAQ,CAAC,CAAC,CACVE,SAAS,CAACC,KAAK,IAAI;IAChB,OAAOA,KAAK,IAAIC,SAAS;EAC7B,CAAC;AACT,CAAC,CAAC,CACDC,WAAW,CAAC,CAAC;AAElB,MAAMC,MAAM,GAAGjB,GAAG,CAACkB,KAAK,CAAC,CAACf,iBAAiB,EAAEH,GAAG,CAACmB,KAAK,CAAChB,iBAAiB,CAAC,CAAC,CAAC;AAE3E,OAAO,MAAMiB,iBAAiB,GAAIC,KAAc,IAAgD;EAC5F,MAAMC,IAAI,GAAG,OAAOD,KAAK,KAAK,QAAQ,GAAGE,IAAI,CAACC,KAAK,CAACH,KAAK,CAAC,GAAGA,KAAK;EAElE,MAAMI,MAAM,GAAGR,MAAM,CAACS,SAAS,CAACJ,IAAI,CAAC;EACrC,IAAI,CAACG,MAAM,CAACE,OAAO,EAAE;IACjB,MAAMC,KAAK,GAAG1B,cAAc,CAACuB,MAAM,CAACG,KAAK,CAAC;IAC1C,MAAM,IAAI3B,WAAW,CAAC;MAClB4B,OAAO,EAAE,0DAA0D;MACnEC,IAAI,EAAE,yBAAyB;MAC/BC,IAAI,EAAEH,KAAK,CAACG;IAChB,CAAC,CAAC;EACN;EACA,OAAON,MAAM,CAACM,IAAI;AACtB,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { ResolverDecorator } from "./types.js";
2
+ export declare const createResolverDecorator: <TSource = any, TContext = any, TArgs = any>(decorator: ResolverDecorator<TSource, TContext, TArgs>) => ResolverDecorator<TSource, TContext, TArgs>;
@@ -0,0 +1,5 @@
1
+ export const createResolverDecorator = decorator => {
2
+ return decorator;
3
+ };
4
+
5
+ //# sourceMappingURL=createResolverDecorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createResolverDecorator","decorator"],"sources":["createResolverDecorator.ts"],"sourcesContent":["import type { ResolverDecorator } from \"./types.js\";\n\nexport const createResolverDecorator = <TSource = any, TContext = any, TArgs = any>(\n decorator: ResolverDecorator<TSource, TContext, TArgs>\n) => {\n return decorator;\n};\n"],"mappings":"AAEA,OAAO,MAAMA,uBAAuB,GAChCC,SAAsD,IACrD;EACD,OAAOA,SAAS;AACpB,CAAC","ignoreList":[]}
package/debugPlugins.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { GraphQLAfterQueryPlugin } from "./types";
2
- import { Context } from "@webiny/api/types";
1
+ import type { GraphQLAfterQueryPlugin } from "./types.js";
2
+ import type { Context } from "@webiny/api/types.js";
3
3
  import { ContextPlugin } from "@webiny/api";
4
4
  interface Log {
5
5
  method: string;
package/debugPlugins.js CHANGED
@@ -1,19 +1,13 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _interceptConsole = require("./interceptConsole");
8
- var _api = require("@webiny/api");
9
- var _default = () => [new _api.ContextPlugin(async context => {
1
+ import { interceptConsole } from "./interceptConsole.js";
2
+ import { ContextPlugin } from "@webiny/api";
3
+ export default () => [new ContextPlugin(async context => {
10
4
  if (!context.debug) {
11
5
  context.debug = {};
12
6
  }
13
7
  if (!context.debug.logs) {
14
8
  context.debug.logs = [];
15
9
  }
16
- (0, _interceptConsole.interceptConsole)((method, args) => {
10
+ interceptConsole((method, args) => {
17
11
  context.debug.logs.push({
18
12
  method,
19
13
  args
@@ -33,4 +27,5 @@ var _default = () => [new _api.ContextPlugin(async context => {
33
27
  }
34
28
  }
35
29
  }];
36
- exports.default = _default;
30
+
31
+ //# sourceMappingURL=debugPlugins.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ContextPlugin","context","debug","logs","interceptConsole","method","args","push","type","apply","result","console","length"],"sources":["debugPlugins.ts"],"sourcesContent":["import { interceptConsole } from \"./interceptConsole\";\nimport { GraphQLAfterQueryPlugin } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\nimport { ContextPlugin } from \"@webiny/api\";\n\ninterface Log {\n method: string;\n args: any;\n}\ninterface DebugContext extends Context {\n debug: {\n logs?: Log[];\n };\n}\n\nexport default () => [\n new ContextPlugin<DebugContext>(async context => {\n if (!context.debug) {\n context.debug = {};\n }\n\n if (!context.debug.logs) {\n context.debug.logs = [];\n }\n\n interceptConsole((method, args) => {\n (context.debug.logs as Log[]).push({ method, args });\n });\n }),\n {\n type: \"graphql-after-query\",\n apply({ result, context }) {\n result[\"extensions\"] = { console: [...(context.debug.logs || [])] };\n if (context.debug.logs) {\n context.debug.logs.length = 0;\n }\n }\n } as GraphQLAfterQueryPlugin<DebugContext>\n];\n"],"mappings":";;;;;;AAAA;AAGA;AAA4C,eAY7B,MAAM,CACjB,IAAIA,kBAAa,CAAe,MAAMC,OAAO,IAAI;EAC7C,IAAI,CAACA,OAAO,CAACC,KAAK,EAAE;IAChBD,OAAO,CAACC,KAAK,GAAG,CAAC,CAAC;EACtB;EAEA,IAAI,CAACD,OAAO,CAACC,KAAK,CAACC,IAAI,EAAE;IACrBF,OAAO,CAACC,KAAK,CAACC,IAAI,GAAG,EAAE;EAC3B;EAEA,IAAAC,kCAAgB,EAAC,CAACC,MAAM,EAAEC,IAAI,KAAK;IAC9BL,OAAO,CAACC,KAAK,CAACC,IAAI,CAAWI,IAAI,CAAC;MAAEF,MAAM;MAAEC;IAAK,CAAC,CAAC;EACxD,CAAC,CAAC;AACN,CAAC,CAAC,EACF;EACIE,IAAI,EAAE,qBAAqB;EAC3BC,KAAK,CAAC;IAAEC,MAAM;IAAET;EAAQ,CAAC,EAAE;IACvBS,MAAM,CAAC,YAAY,CAAC,GAAG;MAAEC,OAAO,EAAE,CAAC,IAAIV,OAAO,CAACC,KAAK,CAACC,IAAI,IAAI,EAAE,CAAC;IAAE,CAAC;IACnE,IAAIF,OAAO,CAACC,KAAK,CAACC,IAAI,EAAE;MACpBF,OAAO,CAACC,KAAK,CAACC,IAAI,CAACS,MAAM,GAAG,CAAC;IACjC;EACJ;AACJ,CAAC,CACJ;AAAA"}
1
+ {"version":3,"names":["interceptConsole","ContextPlugin","context","debug","logs","method","args","push","type","apply","result","console","length"],"sources":["debugPlugins.ts"],"sourcesContent":["import { interceptConsole } from \"./interceptConsole.js\";\nimport type { GraphQLAfterQueryPlugin } from \"./types.js\";\nimport type { Context } from \"@webiny/api/types.js\";\nimport { ContextPlugin } from \"@webiny/api\";\n\ninterface Log {\n method: string;\n args: any;\n}\ninterface DebugContext extends Context {\n debug: {\n logs?: Log[];\n };\n}\n\nexport default () => [\n new ContextPlugin<DebugContext>(async context => {\n if (!context.debug) {\n context.debug = {};\n }\n\n if (!context.debug.logs) {\n context.debug.logs = [];\n }\n\n interceptConsole((method, args) => {\n (context.debug.logs as Log[]).push({ method, args });\n });\n }),\n {\n type: \"graphql-after-query\",\n apply({ result, context }) {\n result[\"extensions\"] = { console: [...(context.debug.logs || [])] };\n if (context.debug.logs) {\n context.debug.logs.length = 0;\n }\n }\n } as GraphQLAfterQueryPlugin<DebugContext>\n];\n"],"mappings":"AAAA,SAASA,gBAAgB;AAGzB,SAASC,aAAa,QAAQ,aAAa;AAY3C,eAAe,MAAM,CACjB,IAAIA,aAAa,CAAe,MAAMC,OAAO,IAAI;EAC7C,IAAI,CAACA,OAAO,CAACC,KAAK,EAAE;IAChBD,OAAO,CAACC,KAAK,GAAG,CAAC,CAAC;EACtB;EAEA,IAAI,CAACD,OAAO,CAACC,KAAK,CAACC,IAAI,EAAE;IACrBF,OAAO,CAACC,KAAK,CAACC,IAAI,GAAG,EAAE;EAC3B;EAEAJ,gBAAgB,CAAC,CAACK,MAAM,EAAEC,IAAI,KAAK;IAC9BJ,OAAO,CAACC,KAAK,CAACC,IAAI,CAAWG,IAAI,CAAC;MAAEF,MAAM;MAAEC;IAAK,CAAC,CAAC;EACxD,CAAC,CAAC;AACN,CAAC,CAAC,EACF;EACIE,IAAI,EAAE,qBAAqB;EAC3BC,KAAKA,CAAC;IAAEC,MAAM;IAAER;EAAQ,CAAC,EAAE;IACvBQ,MAAM,CAAC,YAAY,CAAC,GAAG;MAAEC,OAAO,EAAE,CAAC,IAAIT,OAAO,CAACC,KAAK,CAACC,IAAI,IAAI,EAAE,CAAC;IAAE,CAAC;IACnE,IAAIF,OAAO,CAACC,KAAK,CAACC,IAAI,EAAE;MACpBF,OAAO,CAACC,KAAK,CAACC,IAAI,CAACQ,MAAM,GAAG,CAAC;IACjC;EACJ;AACJ,CAAC,CACJ","ignoreList":[]}
package/errors.js CHANGED
@@ -1,14 +1,8 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.NotFoundError = void 0;
8
- var _error = _interopRequireDefault(require("@webiny/error"));
9
- class NotFoundError extends _error.default {
1
+ import WebinyError from "@webiny/error";
2
+ export class NotFoundError extends WebinyError {
10
3
  constructor(message = "Not found.") {
11
4
  super(message, "NOT_FOUND");
12
5
  }
13
6
  }
14
- exports.NotFoundError = NotFoundError;
7
+
8
+ //# sourceMappingURL=errors.js.map
package/errors.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["NotFoundError","WebinyError","constructor","message"],"sources":["errors.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport class NotFoundError extends WebinyError {\n constructor(message = \"Not found.\") {\n super(message, \"NOT_FOUND\");\n }\n}\n"],"mappings":";;;;;;;AAAA;AAEO,MAAMA,aAAa,SAASC,cAAW,CAAC;EAC3CC,WAAW,CAACC,OAAO,GAAG,YAAY,EAAE;IAChC,KAAK,CAACA,OAAO,EAAE,WAAW,CAAC;EAC/B;AACJ;AAAC"}
1
+ {"version":3,"names":["WebinyError","NotFoundError","constructor","message"],"sources":["errors.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport class NotFoundError extends WebinyError {\n constructor(message = \"Not found.\") {\n super(message, \"NOT_FOUND\");\n }\n}\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAEvC,OAAO,MAAMC,aAAa,SAASD,WAAW,CAAC;EAC3CE,WAAWA,CAACC,OAAO,GAAG,YAAY,EAAE;IAChC,KAAK,CAACA,OAAO,EAAE,WAAW,CAAC;EAC/B;AACJ","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export { GraphQLSchemaFactory } from "../../graphql/abstractions.js";
2
+ export { ErrorResponse, ListResponse, Response, NotFoundResponse, ListErrorResponse } from "../../responses.js";
@@ -0,0 +1,4 @@
1
+ export { GraphQLSchemaFactory } from "../../graphql/abstractions.js";
2
+ export { ErrorResponse, ListResponse, Response, NotFoundResponse, ListErrorResponse } from "../../responses.js";
3
+
4
+ //# sourceMappingURL=graphql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["GraphQLSchemaFactory","ErrorResponse","ListResponse","Response","NotFoundResponse","ListErrorResponse"],"sources":["graphql.ts"],"sourcesContent":["export { GraphQLSchemaFactory } from \"~/graphql/abstractions.js\";\n\nexport {\n ErrorResponse,\n ListResponse,\n Response,\n NotFoundResponse,\n ListErrorResponse\n} from \"~/responses.js\";\n"],"mappings":"AAAA,SAASA,oBAAoB;AAE7B,SACIC,aAAa,EACbC,YAAY,EACZC,QAAQ,EACRC,gBAAgB,EAChBC,iBAAiB","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ import type { GraphQLSchemaBuilder as Abstraction } from "./abstractions.js";
2
+ import type { IGraphQLSchema } from "../../graphql/abstractions.public.js";
3
+ import type { ResolverDecorator } from "../../types.js";
4
+ export declare class GraphQLSchemaBuilder implements Abstraction.Interface {
5
+ private readonly typeDefsArray;
6
+ private readonly resolvers;
7
+ private readonly resolverDecorators;
8
+ addTypeDefs(typeDefs: string): this;
9
+ addResolver<TArgs = any>(config: Abstraction.Config<TArgs>): this;
10
+ /**
11
+ * @internal This method needs revisiting, to align with DI concepts.
12
+ */
13
+ addResolverDecorator(path: string, decorator: ResolverDecorator): this;
14
+ build(): IGraphQLSchema;
15
+ private setResolverAtPath;
16
+ }
@@ -0,0 +1,64 @@
1
+ export class GraphQLSchemaBuilder {
2
+ typeDefsArray = [];
3
+ resolvers = {};
4
+ resolverDecorators = {};
5
+ addTypeDefs(typeDefs) {
6
+ this.typeDefsArray.push(typeDefs);
7
+ return this;
8
+ }
9
+ addResolver(config) {
10
+ const {
11
+ path,
12
+ dependencies = [],
13
+ resolver
14
+ } = config;
15
+ const pathParts = path.split(".");
16
+ const graphqlResolver = (parent, args, context, info) => {
17
+ const resolvedDeps = dependencies.map(dep => {
18
+ const [abstraction] = Array.isArray(dep) ? dep : [dep];
19
+ return context.container.resolve(abstraction);
20
+ });
21
+ const actualResolver = resolver(...resolvedDeps);
22
+ return actualResolver({
23
+ parent,
24
+ args,
25
+ context,
26
+ info
27
+ });
28
+ };
29
+ this.setResolverAtPath(pathParts, graphqlResolver);
30
+ return this;
31
+ }
32
+
33
+ /**
34
+ * @internal This method needs revisiting, to align with DI concepts.
35
+ */
36
+ addResolverDecorator(path, decorator) {
37
+ if (!this.resolverDecorators[path]) {
38
+ this.resolverDecorators[path] = [];
39
+ }
40
+ this.resolverDecorators[path].push(decorator);
41
+ return this;
42
+ }
43
+ build() {
44
+ return {
45
+ typeDefs: this.typeDefsArray.join("\n"),
46
+ resolvers: this.resolvers,
47
+ resolverDecorators: this.resolverDecorators
48
+ };
49
+ }
50
+ setResolverAtPath(pathParts, resolver) {
51
+ let current = this.resolvers;
52
+ for (let i = 0; i < pathParts.length - 1; i++) {
53
+ const part = pathParts[i];
54
+ if (!current[part]) {
55
+ current[part] = {};
56
+ }
57
+ current = current[part];
58
+ }
59
+ const finalKey = pathParts[pathParts.length - 1];
60
+ current[finalKey] = resolver;
61
+ }
62
+ }
63
+
64
+ //# sourceMappingURL=GraphQLSchemaBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["GraphQLSchemaBuilder","typeDefsArray","resolvers","resolverDecorators","addTypeDefs","typeDefs","push","addResolver","config","path","dependencies","resolver","pathParts","split","graphqlResolver","parent","args","context","info","resolvedDeps","map","dep","abstraction","Array","isArray","container","resolve","actualResolver","setResolverAtPath","addResolverDecorator","decorator","build","join","current","i","length","part","finalKey"],"sources":["GraphQLSchemaBuilder.ts"],"sourcesContent":["import type { GraphQLSchemaBuilder as Abstraction } from \"./abstractions.js\";\nimport type { IGraphQLSchema } from \"~/graphql/abstractions.public.js\";\nimport type { ResolverDecorator, ResolverDecorators, Resolvers } from \"~/types.js\";\nimport type { Dependency } from \"@webiny/di\";\n\nexport class GraphQLSchemaBuilder implements Abstraction.Interface {\n private readonly typeDefsArray: string[] = [];\n private readonly resolvers: Resolvers<any> = {};\n private readonly resolverDecorators: ResolverDecorators = {};\n\n addTypeDefs(typeDefs: string): this {\n this.typeDefsArray.push(typeDefs);\n return this;\n }\n\n addResolver<TArgs = any>(config: Abstraction.Config<TArgs>): this {\n const { path, dependencies = [], resolver } = config;\n\n const pathParts = path.split(\".\");\n\n const graphqlResolver = (parent: any, args: TArgs, context: any, info: any) => {\n const resolvedDeps = dependencies.map((dep: Dependency) => {\n const [abstraction] = Array.isArray(dep) ? dep : [dep];\n return context.container.resolve(abstraction);\n });\n\n const actualResolver = resolver(...resolvedDeps);\n\n return actualResolver({ parent, args, context, info });\n };\n\n this.setResolverAtPath(pathParts, graphqlResolver);\n\n return this;\n }\n\n /**\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"],"mappings":"AAKA,OAAO,MAAMA,oBAAoB,CAAkC;EAC9CC,aAAa,GAAa,EAAE;EAC5BC,SAAS,GAAmB,CAAC,CAAC;EAC9BC,kBAAkB,GAAuB,CAAC,CAAC;EAE5DC,WAAWA,CAACC,QAAgB,EAAQ;IAChC,IAAI,CAACJ,aAAa,CAACK,IAAI,CAACD,QAAQ,CAAC;IACjC,OAAO,IAAI;EACf;EAEAE,WAAWA,CAAcC,MAAiC,EAAQ;IAC9D,MAAM;MAAEC,IAAI;MAAEC,YAAY,GAAG,EAAE;MAAEC;IAAS,CAAC,GAAGH,MAAM;IAEpD,MAAMI,SAAS,GAAGH,IAAI,CAACI,KAAK,CAAC,GAAG,CAAC;IAEjC,MAAMC,eAAe,GAAGA,CAACC,MAAW,EAAEC,IAAW,EAAEC,OAAY,EAAEC,IAAS,KAAK;MAC3E,MAAMC,YAAY,GAAGT,YAAY,CAACU,GAAG,CAAEC,GAAe,IAAK;QACvD,MAAM,CAACC,WAAW,CAAC,GAAGC,KAAK,CAACC,OAAO,CAACH,GAAG,CAAC,GAAGA,GAAG,GAAG,CAACA,GAAG,CAAC;QACtD,OAAOJ,OAAO,CAACQ,SAAS,CAACC,OAAO,CAACJ,WAAW,CAAC;MACjD,CAAC,CAAC;MAEF,MAAMK,cAAc,GAAGhB,QAAQ,CAAC,GAAGQ,YAAY,CAAC;MAEhD,OAAOQ,cAAc,CAAC;QAAEZ,MAAM;QAAEC,IAAI;QAAEC,OAAO;QAAEC;MAAK,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,CAACU,iBAAiB,CAAChB,SAAS,EAAEE,eAAe,CAAC;IAElD,OAAO,IAAI;EACf;;EAEA;AACJ;AACA;EACIe,oBAAoBA,CAACpB,IAAY,EAAEqB,SAA4B,EAAQ;IACnE,IAAI,CAAC,IAAI,CAAC3B,kBAAkB,CAACM,IAAI,CAAC,EAAE;MAChC,IAAI,CAACN,kBAAkB,CAACM,IAAI,CAAC,GAAG,EAAE;IACtC;IACA,IAAI,CAACN,kBAAkB,CAACM,IAAI,CAAC,CAACH,IAAI,CAACwB,SAAS,CAAC;IAC7C,OAAO,IAAI;EACf;EAEAC,KAAKA,CAAA,EAAmB;IACpB,OAAO;MACH1B,QAAQ,EAAE,IAAI,CAACJ,aAAa,CAAC+B,IAAI,CAAC,IAAI,CAAC;MACvC9B,SAAS,EAAE,IAAI,CAACA,SAAS;MACzBC,kBAAkB,EAAE,IAAI,CAACA;IAC7B,CAAC;EACL;EAEQyB,iBAAiBA,CAAChB,SAAmB,EAAED,QAAa,EAAQ;IAChE,IAAIsB,OAAY,GAAG,IAAI,CAAC/B,SAAS;IAEjC,KAAK,IAAIgC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGtB,SAAS,CAACuB,MAAM,GAAG,CAAC,EAAED,CAAC,EAAE,EAAE;MAC3C,MAAME,IAAI,GAAGxB,SAAS,CAACsB,CAAC,CAAC;MACzB,IAAI,CAACD,OAAO,CAACG,IAAI,CAAC,EAAE;QAChBH,OAAO,CAACG,IAAI,CAAC,GAAG,CAAC,CAAC;MACtB;MACAH,OAAO,GAAGA,OAAO,CAACG,IAAI,CAAC;IAC3B;IAEA,MAAMC,QAAQ,GAAGzB,SAAS,CAACA,SAAS,CAACuB,MAAM,GAAG,CAAC,CAAC;IAChDF,OAAO,CAACI,QAAQ,CAAC,GAAG1B,QAAQ;EAChC;AACJ","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ import { GraphQLSchemaComposer as Abstraction } from "./abstractions.js";
2
+ import { GraphQLSchemaFactory, CoreGraphQLSchemaFactory } from "../../graphql/abstractions.js";
3
+ import type { IGraphQLSchema } from "../../graphql/abstractions.public.js";
4
+ declare class GraphQLSchemaComposerImpl implements Abstraction.Interface {
5
+ private coreSchemas;
6
+ private userSchemas;
7
+ constructor(coreSchemas: CoreGraphQLSchemaFactory.Interface[], userSchemas: GraphQLSchemaFactory.Interface[]);
8
+ build(): Promise<IGraphQLSchema>;
9
+ }
10
+ export declare const GraphQLSchemaComposer: typeof GraphQLSchemaComposerImpl & {
11
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGraphQLSchemaComposer>;
12
+ };
13
+ export {};
@@ -0,0 +1,29 @@
1
+ import { GraphQLSchemaComposer as Abstraction } from "./abstractions.js";
2
+ import { GraphQLSchemaFactory, CoreGraphQLSchemaFactory } from "../../graphql/abstractions.js";
3
+ import { GraphQLSchemaBuilder } from "./GraphQLSchemaBuilder.js";
4
+ class GraphQLSchemaComposerImpl {
5
+ constructor(coreSchemas, userSchemas) {
6
+ this.coreSchemas = coreSchemas;
7
+ this.userSchemas = userSchemas;
8
+ }
9
+ async build() {
10
+ const builder = new GraphQLSchemaBuilder();
11
+ for (const factory of this.coreSchemas) {
12
+ await factory.execute(builder);
13
+ }
14
+ for (const factory of this.userSchemas) {
15
+ await factory.execute(builder);
16
+ }
17
+ return builder.build();
18
+ }
19
+ }
20
+ export const GraphQLSchemaComposer = Abstraction.createImplementation({
21
+ implementation: GraphQLSchemaComposerImpl,
22
+ dependencies: [[CoreGraphQLSchemaFactory, {
23
+ multiple: true
24
+ }], [GraphQLSchemaFactory, {
25
+ multiple: true
26
+ }]]
27
+ });
28
+
29
+ //# sourceMappingURL=GraphQLSchemaComposer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["GraphQLSchemaComposer","Abstraction","GraphQLSchemaFactory","CoreGraphQLSchemaFactory","GraphQLSchemaBuilder","GraphQLSchemaComposerImpl","constructor","coreSchemas","userSchemas","build","builder","factory","execute","createImplementation","implementation","dependencies","multiple"],"sources":["GraphQLSchemaComposer.ts"],"sourcesContent":["import { GraphQLSchemaComposer as Abstraction } from \"./abstractions.js\";\nimport { GraphQLSchemaFactory, CoreGraphQLSchemaFactory } from \"~/graphql/abstractions.js\";\nimport { GraphQLSchemaBuilder } from \"./GraphQLSchemaBuilder.js\";\nimport type { IGraphQLSchema } from \"~/graphql/abstractions.public.js\";\n\nclass GraphQLSchemaComposerImpl implements Abstraction.Interface {\n constructor(\n private coreSchemas: CoreGraphQLSchemaFactory.Interface[],\n private userSchemas: GraphQLSchemaFactory.Interface[]\n ) {}\n\n async build(): Promise<IGraphQLSchema> {\n const builder = new GraphQLSchemaBuilder();\n\n for (const factory of this.coreSchemas) {\n await factory.execute(builder);\n }\n\n for (const factory of this.userSchemas) {\n await factory.execute(builder);\n }\n\n return builder.build();\n }\n}\n\nexport const GraphQLSchemaComposer = Abstraction.createImplementation({\n implementation: GraphQLSchemaComposerImpl,\n dependencies: [\n [CoreGraphQLSchemaFactory, { multiple: true }],\n [GraphQLSchemaFactory, { multiple: true }]\n ]\n});\n"],"mappings":"AAAA,SAASA,qBAAqB,IAAIC,WAAW;AAC7C,SAASC,oBAAoB,EAAEC,wBAAwB;AACvD,SAASC,oBAAoB;AAG7B,MAAMC,yBAAyB,CAAkC;EAC7DC,WAAWA,CACCC,WAAiD,EACjDC,WAA6C,EACvD;IAAA,KAFUD,WAAiD,GAAjDA,WAAiD;IAAA,KACjDC,WAA6C,GAA7CA,WAA6C;EACtD;EAEH,MAAMC,KAAKA,CAAA,EAA4B;IACnC,MAAMC,OAAO,GAAG,IAAIN,oBAAoB,CAAC,CAAC;IAE1C,KAAK,MAAMO,OAAO,IAAI,IAAI,CAACJ,WAAW,EAAE;MACpC,MAAMI,OAAO,CAACC,OAAO,CAACF,OAAO,CAAC;IAClC;IAEA,KAAK,MAAMC,OAAO,IAAI,IAAI,CAACH,WAAW,EAAE;MACpC,MAAMG,OAAO,CAACC,OAAO,CAACF,OAAO,CAAC;IAClC;IAEA,OAAOA,OAAO,CAACD,KAAK,CAAC,CAAC;EAC1B;AACJ;AAEA,OAAO,MAAMT,qBAAqB,GAAGC,WAAW,CAACY,oBAAoB,CAAC;EAClEC,cAAc,EAAET,yBAAyB;EACzCU,YAAY,EAAE,CACV,CAACZ,wBAAwB,EAAE;IAAEa,QAAQ,EAAE;EAAK,CAAC,CAAC,EAC9C,CAACd,oBAAoB,EAAE;IAAEc,QAAQ,EAAE;EAAK,CAAC,CAAC;AAElD,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,34 @@
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
+ * @internal This method needs revisiting, to align with DI concepts.
19
+ */
20
+ addResolverDecorator(path: string, decorator: ResolverDecorator): this;
21
+ build(): IGraphQLSchema;
22
+ }
23
+ export declare const GraphQLSchemaBuilder: import("@webiny/di").Abstraction<IGraphQLSchemaBuilder>;
24
+ export declare namespace GraphQLSchemaBuilder {
25
+ type Interface = IGraphQLSchemaBuilder;
26
+ type Config<TArgs = any> = ResolverConfig<TArgs>;
27
+ }
28
+ export interface IGraphQLSchemaComposer {
29
+ build(): Promise<IGraphQLSchema>;
30
+ }
31
+ export declare const GraphQLSchemaComposer: import("@webiny/di").Abstraction<IGraphQLSchemaComposer>;
32
+ export declare namespace GraphQLSchemaComposer {
33
+ type Interface = IGraphQLSchemaComposer;
34
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ export const GraphQLSchemaBuilder = createAbstraction("GraphQLSchemaBuilder");
3
+ export const GraphQLSchemaComposer = createAbstraction("GraphQLSchemaComposer");
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createAbstraction","GraphQLSchemaBuilder","GraphQLSchemaComposer"],"sources":["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 * @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\nexport const GraphQLSchemaComposer =\n createAbstraction<IGraphQLSchemaComposer>(\"GraphQLSchemaComposer\");\n\nexport namespace GraphQLSchemaComposer {\n export type Interface = IGraphQLSchemaComposer;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAuBvD,OAAO,MAAMC,oBAAoB,GAC7BD,iBAAiB,CAAwB,sBAAsB,CAAC;AAWpE,OAAO,MAAME,qBAAqB,GAC9BF,iBAAiB,CAAyB,uBAAuB,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export declare const GraphQLSchemaComposerFeature: import("@webiny/feature/api/createFeature.js").FeatureDefinition<unknown>;
@@ -0,0 +1,10 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { GraphQLSchemaComposer } from "./GraphQLSchemaComposer.js";
3
+ export const GraphQLSchemaComposerFeature = createFeature({
4
+ name: "GraphQLSchemaComposer",
5
+ register(container) {
6
+ container.register(GraphQLSchemaComposer);
7
+ }
8
+ });
9
+
10
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFeature","GraphQLSchemaComposer","GraphQLSchemaComposerFeature","name","register","container"],"sources":["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"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,qBAAqB;AAE9B,OAAO,MAAMC,4BAA4B,GAAGF,aAAa,CAAC;EACtDG,IAAI,EAAE,uBAAuB;EAC7BC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACH,qBAAqB,CAAC;EAC7C;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ import type { IGraphQLSchemaFactory } from "./abstractions.public.js";
2
+ import type { GraphQLSchemaBuilder } from "../features/GraphQLSchemaBuilder/abstractions.js";
3
+ /**
4
+ * CoreGraphQLSchemaFactory
5
+ */
6
+ export declare const CoreGraphQLSchemaFactory: import("@webiny/di").Abstraction<IGraphQLSchemaFactory>;
7
+ export declare namespace CoreGraphQLSchemaFactory {
8
+ type Interface = IGraphQLSchemaFactory;
9
+ type SchemaBuilder = GraphQLSchemaBuilder.Interface;
10
+ type Return = Promise<GraphQLSchemaBuilder.Interface>;
11
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file contains abstraction for use by the core Webiny team, or anyone contributing to the webiny-js repository.
3
+ */
4
+ import { createAbstraction } from "@webiny/feature/api";
5
+ /**
6
+ * CoreGraphQLSchemaFactory
7
+ */
8
+ export const CoreGraphQLSchemaFactory = createAbstraction("CoreGraphQLSchemaFactory");
9
+
10
+ //# sourceMappingURL=abstractions.core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createAbstraction","CoreGraphQLSchemaFactory"],"sources":["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 { IGraphQLSchemaFactory } from \"./abstractions.public.js\";\nimport type { GraphQLSchemaBuilder } from \"~/features/GraphQLSchemaBuilder/abstractions.js\";\n\n/**\n * CoreGraphQLSchemaFactory\n */\nexport const CoreGraphQLSchemaFactory = createAbstraction<IGraphQLSchemaFactory>(\n \"CoreGraphQLSchemaFactory\"\n);\nexport namespace CoreGraphQLSchemaFactory {\n export type Interface = IGraphQLSchemaFactory;\n export type SchemaBuilder = GraphQLSchemaBuilder.Interface;\n export type Return = Promise<GraphQLSchemaBuilder.Interface>;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,iBAAiB,QAAQ,qBAAqB;AAIvD;AACA;AACA;AACA,OAAO,MAAMC,wBAAwB,GAAGD,iBAAiB,CACrD,0BACJ,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./abstractions.core.js";
2
+ export * from "./abstractions.public.js";
@@ -0,0 +1,4 @@
1
+ export * from "./abstractions.core.js";
2
+ export * from "./abstractions.public.js";
3
+
4
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["abstractions.ts"],"sourcesContent":["export * from \"./abstractions.core.js\";\nexport * from \"./abstractions.public.js\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
@@ -0,0 +1,19 @@
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
+ /**
9
+ * GraphQLSchemaFactory
10
+ */
11
+ export interface IGraphQLSchemaFactory {
12
+ execute(builder: GraphQLSchemaBuilder.Interface): Promise<GraphQLSchemaBuilder.Interface>;
13
+ }
14
+ export declare const GraphQLSchemaFactory: import("@webiny/di").Abstraction<IGraphQLSchemaFactory>;
15
+ export declare namespace GraphQLSchemaFactory {
16
+ type Interface = IGraphQLSchemaFactory;
17
+ type SchemaBuilder = GraphQLSchemaBuilder.Interface;
18
+ type Return = Promise<GraphQLSchemaBuilder.Interface>;
19
+ }