@cedarjs/graphql-server 0.0.4

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 (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/dist/cors.d.ts +10 -0
  4. package/dist/cors.d.ts.map +1 -0
  5. package/dist/cors.js +70 -0
  6. package/dist/createGraphQLYoga.d.ts +6 -0
  7. package/dist/createGraphQLYoga.d.ts.map +1 -0
  8. package/dist/createGraphQLYoga.js +178 -0
  9. package/dist/directives/makeDirectives.d.ts +8 -0
  10. package/dist/directives/makeDirectives.d.ts.map +1 -0
  11. package/dist/directives/makeDirectives.js +89 -0
  12. package/dist/errors.d.ts +28 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/errors.js +98 -0
  15. package/dist/functions/graphql.d.ts +15 -0
  16. package/dist/functions/graphql.d.ts.map +1 -0
  17. package/dist/functions/graphql.js +141 -0
  18. package/dist/functions/useRequireAuth.d.ts +12 -0
  19. package/dist/functions/useRequireAuth.d.ts.map +1 -0
  20. package/dist/functions/useRequireAuth.js +70 -0
  21. package/dist/global.api-auto-imports.d.ts +5 -0
  22. package/dist/global.api-auto-imports.d.ts.map +1 -0
  23. package/dist/global.api-auto-imports.js +1 -0
  24. package/dist/globalContext.d.ts +25 -0
  25. package/dist/globalContext.d.ts.map +1 -0
  26. package/dist/globalContext.js +55 -0
  27. package/dist/globalContextStore.d.ts +9 -0
  28. package/dist/globalContextStore.d.ts.map +1 -0
  29. package/dist/globalContextStore.js +35 -0
  30. package/dist/graphiql.d.ts +8 -0
  31. package/dist/graphiql.d.ts.map +1 -0
  32. package/dist/graphiql.js +45 -0
  33. package/dist/index.d.ts +13 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +91 -0
  36. package/dist/introspection.d.ts +7 -0
  37. package/dist/introspection.d.ts.map +1 -0
  38. package/dist/introspection.js +36 -0
  39. package/dist/makeMergedSchema.d.ts +17 -0
  40. package/dist/makeMergedSchema.d.ts.map +1 -0
  41. package/dist/makeMergedSchema.js +282 -0
  42. package/dist/plugins/__fixtures__/common.d.ts +9 -0
  43. package/dist/plugins/__fixtures__/common.d.ts.map +1 -0
  44. package/dist/plugins/__fixtures__/envelop-testing.d.ts +55 -0
  45. package/dist/plugins/__fixtures__/envelop-testing.d.ts.map +1 -0
  46. package/dist/plugins/index.d.ts +10 -0
  47. package/dist/plugins/index.d.ts.map +1 -0
  48. package/dist/plugins/index.js +52 -0
  49. package/dist/plugins/useArmor.d.ts +4 -0
  50. package/dist/plugins/useArmor.d.ts.map +1 -0
  51. package/dist/plugins/useArmor.js +69 -0
  52. package/dist/plugins/useRedwoodAuthContext.d.ts +9 -0
  53. package/dist/plugins/useRedwoodAuthContext.d.ts.map +1 -0
  54. package/dist/plugins/useRedwoodAuthContext.js +61 -0
  55. package/dist/plugins/useRedwoodDirective.d.ts +83 -0
  56. package/dist/plugins/useRedwoodDirective.d.ts.map +1 -0
  57. package/dist/plugins/useRedwoodDirective.js +166 -0
  58. package/dist/plugins/useRedwoodError.d.ts +20 -0
  59. package/dist/plugins/useRedwoodError.d.ts.map +1 -0
  60. package/dist/plugins/useRedwoodError.js +63 -0
  61. package/dist/plugins/useRedwoodGlobalContextSetter.d.ts +10 -0
  62. package/dist/plugins/useRedwoodGlobalContextSetter.d.ts.map +1 -0
  63. package/dist/plugins/useRedwoodGlobalContextSetter.js +35 -0
  64. package/dist/plugins/useRedwoodLogger.d.ts +115 -0
  65. package/dist/plugins/useRedwoodLogger.d.ts.map +1 -0
  66. package/dist/plugins/useRedwoodLogger.js +149 -0
  67. package/dist/plugins/useRedwoodOpenTelemetry.d.ts +22 -0
  68. package/dist/plugins/useRedwoodOpenTelemetry.d.ts.map +1 -0
  69. package/dist/plugins/useRedwoodOpenTelemetry.js +156 -0
  70. package/dist/plugins/useRedwoodPopulateContext.d.ts +9 -0
  71. package/dist/plugins/useRedwoodPopulateContext.d.ts.map +1 -0
  72. package/dist/plugins/useRedwoodPopulateContext.js +35 -0
  73. package/dist/plugins/useRedwoodTrustedDocuments.d.ts +23 -0
  74. package/dist/plugins/useRedwoodTrustedDocuments.d.ts.map +1 -0
  75. package/dist/plugins/useRedwoodTrustedDocuments.js +67 -0
  76. package/dist/rootSchema.d.ts +25 -0
  77. package/dist/rootSchema.d.ts.map +1 -0
  78. package/dist/rootSchema.js +98 -0
  79. package/dist/subscriptions/makeSubscriptions.d.ts +18 -0
  80. package/dist/subscriptions/makeSubscriptions.d.ts.map +1 -0
  81. package/dist/subscriptions/makeSubscriptions.js +40 -0
  82. package/dist/types.d.ts +215 -0
  83. package/dist/types.d.ts.map +1 -0
  84. package/dist/types.js +16 -0
  85. package/package.json +69 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Cedar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # GraphQL Server
2
+
3
+ ## Authentication
4
+
5
+ ### Secure by default
6
+
7
+ TODO
package/dist/cors.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { CorsConfig } from '@cedarjs/api';
2
+ export declare const mapRwCorsOptionsToYoga: (rwCorsConfig?: CorsConfig, requestOrigin?: string | null) => false | {
3
+ origin?: string[] | string;
4
+ methods?: string[];
5
+ allowedHeaders?: string[];
6
+ exposedHeaders?: string[];
7
+ credentials?: boolean;
8
+ maxAge?: number;
9
+ };
10
+ //# sourceMappingURL=cors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../src/cors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE9C,eAAO,MAAM,sBAAsB,kBAClB,UAAU,kBACT,MAAM,GAAG,IAAI;;;;;;;CAoD9B,CAAA"}
package/dist/cors.js ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var cors_exports = {};
20
+ __export(cors_exports, {
21
+ mapRwCorsOptionsToYoga: () => mapRwCorsOptionsToYoga
22
+ });
23
+ module.exports = __toCommonJS(cors_exports);
24
+ const mapRwCorsOptionsToYoga = (rwCorsConfig, requestOrigin) => {
25
+ const yogaCORSOptions = {};
26
+ if (!rwCorsConfig) {
27
+ return false;
28
+ }
29
+ if (rwCorsConfig?.methods) {
30
+ if (typeof rwCorsConfig.methods === "string") {
31
+ yogaCORSOptions.methods = [rwCorsConfig.methods];
32
+ } else if (Array.isArray(rwCorsConfig.methods)) {
33
+ yogaCORSOptions.methods = rwCorsConfig.methods;
34
+ }
35
+ }
36
+ if (rwCorsConfig?.allowedHeaders) {
37
+ if (typeof rwCorsConfig.allowedHeaders === "string") {
38
+ yogaCORSOptions.allowedHeaders = [rwCorsConfig.allowedHeaders];
39
+ } else if (Array.isArray(rwCorsConfig.allowedHeaders)) {
40
+ yogaCORSOptions.allowedHeaders = rwCorsConfig.allowedHeaders;
41
+ }
42
+ }
43
+ if (rwCorsConfig?.exposedHeaders) {
44
+ if (typeof rwCorsConfig.exposedHeaders === "string") {
45
+ yogaCORSOptions.exposedHeaders = [rwCorsConfig.exposedHeaders];
46
+ } else if (Array.isArray(rwCorsConfig.exposedHeaders)) {
47
+ yogaCORSOptions.exposedHeaders = rwCorsConfig.exposedHeaders;
48
+ }
49
+ }
50
+ if (rwCorsConfig?.credentials) {
51
+ yogaCORSOptions.credentials = rwCorsConfig.credentials;
52
+ }
53
+ if (rwCorsConfig?.maxAge) {
54
+ yogaCORSOptions.maxAge = rwCorsConfig.maxAge;
55
+ }
56
+ if (rwCorsConfig?.origin) {
57
+ if (typeof rwCorsConfig.origin === "string") {
58
+ yogaCORSOptions.origin = [rwCorsConfig.origin];
59
+ } else if (rwCorsConfig.origin === true) {
60
+ yogaCORSOptions.origin = [requestOrigin || "*"];
61
+ } else {
62
+ yogaCORSOptions.origin = rwCorsConfig.origin;
63
+ }
64
+ }
65
+ return yogaCORSOptions;
66
+ };
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ mapRwCorsOptionsToYoga
70
+ });
@@ -0,0 +1,6 @@
1
+ import type { GraphQLYogaOptions } from './types';
2
+ export declare const createGraphQLYoga: ({ healthCheckId, loggerConfig, context, getCurrentUser, onException, generateGraphiQLHeader, extraPlugins, authDecoder, cors, services, sdls, directives, armorConfig, allowedOperations, allowIntrospection, allowGraphiQL, defaultError, graphiQLEndpoint, schemaOptions, realtime, trustedDocuments, openTelemetryOptions, includeScalars, }: GraphQLYogaOptions) => {
3
+ yoga: ServerAdapter<TServerContext, import("graphql-yoga").YogaServer<TServerContext, TUserContext>>;
4
+ logger: import("@cedarjs/api/logger").Logger;
5
+ };
6
+ //# sourceMappingURL=createGraphQLYoga.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createGraphQLYoga.d.ts","sourceRoot":"","sources":["../src/createGraphQLYoga.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAEjD,eAAO,MAAM,iBAAiB,oVAwB3B,kBAAkB;;;CAmKpB,CAAA"}
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var createGraphQLYoga_exports = {};
20
+ __export(createGraphQLYoga_exports, {
21
+ createGraphQLYoga: () => createGraphQLYoga
22
+ });
23
+ module.exports = __toCommonJS(createGraphQLYoga_exports);
24
+ var import_disable_introspection = require("@envelop/disable-introspection");
25
+ var import_filter_operation_type = require("@envelop/filter-operation-type");
26
+ var import_graphql = require("graphql");
27
+ var import_graphql_yoga = require("graphql-yoga");
28
+ var import_cors = require("./cors");
29
+ var import_makeDirectives = require("./directives/makeDirectives");
30
+ var import_graphiql = require("./graphiql");
31
+ var import_introspection = require("./introspection");
32
+ var import_makeMergedSchema = require("./makeMergedSchema");
33
+ var import_plugins = require("./plugins");
34
+ var import_makeSubscriptions = require("./subscriptions/makeSubscriptions");
35
+ const createGraphQLYoga = ({
36
+ healthCheckId = "yoga",
37
+ loggerConfig,
38
+ context,
39
+ getCurrentUser,
40
+ onException,
41
+ generateGraphiQLHeader,
42
+ extraPlugins,
43
+ authDecoder,
44
+ cors,
45
+ services,
46
+ sdls,
47
+ directives = [],
48
+ armorConfig,
49
+ allowedOperations,
50
+ allowIntrospection,
51
+ allowGraphiQL,
52
+ defaultError = "Something went wrong.",
53
+ graphiQLEndpoint = "/graphql",
54
+ schemaOptions,
55
+ realtime,
56
+ trustedDocuments,
57
+ openTelemetryOptions,
58
+ includeScalars
59
+ }) => {
60
+ let schema;
61
+ let redwoodDirectivePlugins = [];
62
+ const logger = loggerConfig.logger;
63
+ const isDevEnv = process.env.NODE_ENV === "development";
64
+ try {
65
+ const projectDirectives = (0, import_makeDirectives.makeDirectivesForPlugin)(directives);
66
+ if (projectDirectives.length > 0) {
67
+ ;
68
+ redwoodDirectivePlugins = projectDirectives.map(
69
+ (directive) => (0, import_plugins.useRedwoodDirective)(directive)
70
+ );
71
+ }
72
+ let projectSubscriptions = [];
73
+ if (realtime?.subscriptions?.subscriptions) {
74
+ projectSubscriptions = (0, import_makeSubscriptions.makeSubscriptions)(
75
+ realtime.subscriptions.subscriptions
76
+ );
77
+ }
78
+ schema = (0, import_makeMergedSchema.makeMergedSchema)({
79
+ sdls,
80
+ services,
81
+ directives: projectDirectives,
82
+ subscriptions: projectSubscriptions,
83
+ schemaOptions,
84
+ includeScalars
85
+ });
86
+ } catch (e) {
87
+ logger.fatal(e, "\n \u26A0\uFE0F GraphQL server crashed \n");
88
+ if (onException) {
89
+ onException();
90
+ }
91
+ process.exit(1);
92
+ }
93
+ try {
94
+ const plugins = [];
95
+ const { disableIntrospection } = (0, import_introspection.configureGraphQLIntrospection)({
96
+ allowIntrospection
97
+ });
98
+ if (disableIntrospection) {
99
+ plugins.push((0, import_disable_introspection.useDisableIntrospection)());
100
+ }
101
+ plugins.push((0, import_plugins.useRedwoodAuthContext)(getCurrentUser, authDecoder));
102
+ plugins.push((0, import_plugins.useRedwoodGlobalContextSetter)());
103
+ if (context) {
104
+ plugins.push((0, import_plugins.useRedwoodPopulateContext)(context));
105
+ }
106
+ plugins.push(...redwoodDirectivePlugins);
107
+ if (openTelemetryOptions !== void 0) {
108
+ plugins.push((0, import_plugins.useRedwoodOpenTelemetry)(openTelemetryOptions));
109
+ }
110
+ plugins.push((0, import_plugins.useArmor)(logger, armorConfig));
111
+ const defaultAllowedOperations = [
112
+ import_graphql.OperationTypeNode.QUERY,
113
+ import_graphql.OperationTypeNode.MUTATION
114
+ ];
115
+ if (realtime?.subscriptions?.subscriptions) {
116
+ defaultAllowedOperations.push(import_graphql.OperationTypeNode.SUBSCRIPTION);
117
+ }
118
+ plugins.push(
119
+ (0, import_filter_operation_type.useFilterAllowedOperations)(allowedOperations || defaultAllowedOperations)
120
+ );
121
+ if (trustedDocuments && !trustedDocuments.disabled) {
122
+ plugins.push((0, import_plugins.useRedwoodTrustedDocuments)(trustedDocuments));
123
+ }
124
+ if (extraPlugins && extraPlugins.length > 0) {
125
+ plugins.push(...extraPlugins);
126
+ }
127
+ plugins.push((0, import_plugins.useRedwoodError)(logger));
128
+ plugins.push(
129
+ (0, import_graphql_yoga.useReadinessCheck)({
130
+ endpoint: graphiQLEndpoint + "/readiness",
131
+ check: async ({ request }) => {
132
+ try {
133
+ const response = await yoga.fetch(
134
+ new URL(graphiQLEndpoint + "/health", request.url)
135
+ );
136
+ const status = response.headers.get("x-yoga-id") === healthCheckId && request.headers.get("x-yoga-id") === healthCheckId;
137
+ return status;
138
+ } catch (err) {
139
+ logger.error(err);
140
+ return false;
141
+ }
142
+ }
143
+ })
144
+ );
145
+ plugins.push((0, import_plugins.useRedwoodLogger)(loggerConfig));
146
+ const yoga = (0, import_graphql_yoga.createYoga)({
147
+ id: healthCheckId,
148
+ landingPage: isDevEnv,
149
+ schema,
150
+ plugins,
151
+ maskedErrors: {
152
+ errorMessage: defaultError,
153
+ isDev: isDevEnv
154
+ },
155
+ logging: logger,
156
+ healthCheckEndpoint: graphiQLEndpoint + "/health",
157
+ graphqlEndpoint: graphiQLEndpoint,
158
+ graphiql: (0, import_graphiql.configureGraphiQLPlayground)({
159
+ allowGraphiQL,
160
+ generateGraphiQLHeader
161
+ }),
162
+ cors: (request) => {
163
+ const requestOrigin = request.headers.get("origin");
164
+ return (0, import_cors.mapRwCorsOptionsToYoga)(cors, requestOrigin);
165
+ }
166
+ });
167
+ return { yoga, logger };
168
+ } catch (e) {
169
+ if (onException) {
170
+ onException();
171
+ }
172
+ throw e;
173
+ }
174
+ };
175
+ // Annotate the CommonJS export names for ESM import in node:
176
+ 0 && (module.exports = {
177
+ createGraphQLYoga
178
+ });
@@ -0,0 +1,8 @@
1
+ import { type DocumentNode } from 'graphql';
2
+ import type { RedwoodDirective, TransformerDirective, TransformerDirectiveFunc, ValidatorDirective, ValidatorDirectiveFunc } from '../plugins/useRedwoodDirective';
3
+ export type DirectiveGlobImports = Record<string, any>;
4
+ export declare const makeDirectivesForPlugin: (directiveGlobs: DirectiveGlobImports) => RedwoodDirective[];
5
+ export declare const getDirectiveName: (schema: DocumentNode) => string | undefined;
6
+ export declare const createValidatorDirective: (schema: DocumentNode, directiveFunc: ValidatorDirectiveFunc) => ValidatorDirective;
7
+ export declare const createTransformerDirective: (schema: DocumentNode, directiveFunc: TransformerDirectiveFunc) => TransformerDirective;
8
+ //# sourceMappingURL=makeDirectives.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeDirectives.d.ts","sourceRoot":"","sources":["../../src/directives/makeDirectives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,YAAY,EAAE,MAAM,SAAS,CAAA;AAEjD,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,gCAAgC,CAAA;AAWvC,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAEtD,eAAO,MAAM,uBAAuB,mBAClB,oBAAoB,KACnC,gBAAgB,EAwBlB,CAAA;AAED,eAAO,MAAM,gBAAgB,WAAY,YAAY,uBAMpD,CAAA;AAED,eAAO,MAAM,wBAAwB,WAC3B,YAAY,iBACL,sBAAsB,KACpC,kBAmBF,CAAA;AAED,eAAO,MAAM,0BAA0B,WAC7B,YAAY,iBACL,wBAAwB,KACtC,oBAmBF,CAAA"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var makeDirectives_exports = {};
20
+ __export(makeDirectives_exports, {
21
+ createTransformerDirective: () => createTransformerDirective,
22
+ createValidatorDirective: () => createValidatorDirective,
23
+ getDirectiveName: () => getDirectiveName,
24
+ makeDirectivesForPlugin: () => makeDirectivesForPlugin
25
+ });
26
+ module.exports = __toCommonJS(makeDirectives_exports);
27
+ var import_graphql = require("graphql");
28
+ var import_useRedwoodDirective = require("../plugins/useRedwoodDirective");
29
+ const makeDirectivesForPlugin = (directiveGlobs) => {
30
+ return Object.entries(directiveGlobs).flatMap(
31
+ ([importedGlobName, exports2]) => {
32
+ const [directiveNameFromFile] = importedGlobName.split("_").slice(-2);
33
+ const directive = exports2[directiveNameFromFile] || exports2.default;
34
+ if (!directive.type) {
35
+ throw new Error(
36
+ "Please use `createValidatorDirective` or `createTransformerDirective` functions to define your directive"
37
+ );
38
+ }
39
+ return [directive];
40
+ }
41
+ );
42
+ };
43
+ const getDirectiveName = (schema) => {
44
+ const definition = schema.definitions.find(
45
+ (definition2) => definition2.kind === import_graphql.Kind.DIRECTIVE_DEFINITION
46
+ );
47
+ return definition?.name?.value;
48
+ };
49
+ const createValidatorDirective = (schema, directiveFunc) => {
50
+ const directiveName = getDirectiveName(schema);
51
+ if (!directiveName) {
52
+ throw new Error("Could not parse directive schema");
53
+ }
54
+ if (typeof directiveFunc !== "function") {
55
+ throw new Error(
56
+ `Directive validation function not implemented for @${directiveName}`
57
+ );
58
+ }
59
+ return {
60
+ name: directiveName,
61
+ schema,
62
+ onResolvedValue: directiveFunc,
63
+ type: import_useRedwoodDirective.DirectiveType.VALIDATOR
64
+ };
65
+ };
66
+ const createTransformerDirective = (schema, directiveFunc) => {
67
+ const directiveName = getDirectiveName(schema);
68
+ if (!directiveName) {
69
+ throw new Error("Could not parse directive schema");
70
+ }
71
+ if (typeof directiveFunc !== "function") {
72
+ throw new Error(
73
+ `Directive transformer function not implemented for @${directiveName}`
74
+ );
75
+ }
76
+ return {
77
+ name: directiveName,
78
+ schema,
79
+ onResolvedValue: directiveFunc,
80
+ type: import_useRedwoodDirective.DirectiveType.TRANSFORMER
81
+ };
82
+ };
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ createTransformerDirective,
86
+ createValidatorDirective,
87
+ getDirectiveName,
88
+ makeDirectivesForPlugin
89
+ });
@@ -0,0 +1,28 @@
1
+ import { GraphQLError } from 'graphql';
2
+ export declare class RedwoodGraphQLError extends GraphQLError {
3
+ constructor(message: string, extensions?: Record<string, any>, originalError?: Error & {
4
+ readonly extensions?: unknown;
5
+ });
6
+ }
7
+ export declare class SyntaxError extends RedwoodGraphQLError {
8
+ constructor(message: string);
9
+ }
10
+ export declare class ValidationError extends RedwoodGraphQLError {
11
+ constructor(message: string);
12
+ }
13
+ export declare class AuthenticationError extends RedwoodGraphQLError {
14
+ constructor(message: string);
15
+ }
16
+ export declare class ForbiddenError extends RedwoodGraphQLError {
17
+ constructor(message: string);
18
+ }
19
+ export declare class PersistedQueryNotFoundError extends RedwoodGraphQLError {
20
+ constructor();
21
+ }
22
+ export declare class PersistedQueryNotSupportedError extends RedwoodGraphQLError {
23
+ constructor();
24
+ }
25
+ export declare class UserInputError extends RedwoodGraphQLError {
26
+ constructor(message: string, properties?: Record<string, any>);
27
+ }
28
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,qBAAa,mBAAoB,SAAQ,YAAY;gBAEjD,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,aAAa,CAAC,EAAE,KAAK,GAAG;QACtB,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;KAC9B;CAYJ;AAED,qBAAa,WAAY,SAAQ,mBAAmB;gBACtC,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,eAAgB,SAAQ,mBAAmB;gBAC1C,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,mBAAoB,SAAQ,mBAAmB;gBAC9C,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,cAAe,SAAQ,mBAAmB;gBACzC,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,2BAA4B,SAAQ,mBAAmB;;CAMnE;AAED,qBAAa,+BAAgC,SAAQ,mBAAmB;;CAQvE;AAED,qBAAa,cAAe,SAAQ,mBAAmB;gBACzC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAK9D"}
package/dist/errors.js ADDED
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var errors_exports = {};
20
+ __export(errors_exports, {
21
+ AuthenticationError: () => AuthenticationError,
22
+ ForbiddenError: () => ForbiddenError,
23
+ PersistedQueryNotFoundError: () => PersistedQueryNotFoundError,
24
+ PersistedQueryNotSupportedError: () => PersistedQueryNotSupportedError,
25
+ RedwoodGraphQLError: () => RedwoodGraphQLError,
26
+ SyntaxError: () => SyntaxError,
27
+ UserInputError: () => UserInputError,
28
+ ValidationError: () => ValidationError
29
+ });
30
+ module.exports = __toCommonJS(errors_exports);
31
+ var import_graphql = require("graphql");
32
+ class RedwoodGraphQLError extends import_graphql.GraphQLError {
33
+ constructor(message, extensions, originalError) {
34
+ super(message, {
35
+ extensions: {
36
+ ...extensions,
37
+ code: extensions?.code || "REDWOODJS_ERROR"
38
+ },
39
+ originalError
40
+ });
41
+ Object.setPrototypeOf(this, import_graphql.GraphQLError.prototype);
42
+ }
43
+ }
44
+ class SyntaxError extends RedwoodGraphQLError {
45
+ constructor(message) {
46
+ super(message, { code: "GRAPHQL_PARSE_FAILED" });
47
+ Object.setPrototypeOf(this, SyntaxError.prototype);
48
+ }
49
+ }
50
+ class ValidationError extends RedwoodGraphQLError {
51
+ constructor(message) {
52
+ super(message, { code: "GRAPHQL_VALIDATION_FAILED" });
53
+ Object.setPrototypeOf(this, ValidationError.prototype);
54
+ }
55
+ }
56
+ class AuthenticationError extends RedwoodGraphQLError {
57
+ constructor(message) {
58
+ super(message, { code: "UNAUTHENTICATED" });
59
+ Object.setPrototypeOf(this, AuthenticationError.prototype);
60
+ }
61
+ }
62
+ class ForbiddenError extends RedwoodGraphQLError {
63
+ constructor(message) {
64
+ super(message, { code: "FORBIDDEN" });
65
+ Object.setPrototypeOf(this, ForbiddenError.prototype);
66
+ }
67
+ }
68
+ class PersistedQueryNotFoundError extends RedwoodGraphQLError {
69
+ constructor() {
70
+ super("PersistedQueryNotFound", { code: "PERSISTED_QUERY_NOT_FOUND" });
71
+ Object.setPrototypeOf(this, PersistedQueryNotFoundError.prototype);
72
+ }
73
+ }
74
+ class PersistedQueryNotSupportedError extends RedwoodGraphQLError {
75
+ constructor() {
76
+ super("PersistedQueryNotSupported", {
77
+ code: "PERSISTED_QUERY_NOT_SUPPORTED"
78
+ });
79
+ Object.setPrototypeOf(this, PersistedQueryNotSupportedError.prototype);
80
+ }
81
+ }
82
+ class UserInputError extends RedwoodGraphQLError {
83
+ constructor(message, properties) {
84
+ super(message, { code: "BAD_USER_INPUT", properties });
85
+ Object.setPrototypeOf(this, UserInputError.prototype);
86
+ }
87
+ }
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ AuthenticationError,
91
+ ForbiddenError,
92
+ PersistedQueryNotFoundError,
93
+ PersistedQueryNotSupportedError,
94
+ RedwoodGraphQLError,
95
+ SyntaxError,
96
+ UserInputError,
97
+ ValidationError
98
+ });
@@ -0,0 +1,15 @@
1
+ import type { APIGatewayProxyEvent, Context as LambdaContext } from 'aws-lambda';
2
+ import type { GraphQLHandlerOptions } from '../types';
3
+ /**
4
+ * Creates an Enveloped GraphQL Server, configured with default Redwood plugins
5
+ *
6
+ * You can add your own plugins by passing them to the extraPlugins object
7
+ *
8
+ * @see https://www.envelop.dev/ for information about envelop
9
+ * @see https://www.envelop.dev/plugins for available envelop plugins
10
+ * ```js
11
+ * export const handler = createGraphQLHandler({ schema, context, getCurrentUser })
12
+ * ```
13
+ */
14
+ export declare const createGraphQLHandler: ({ healthCheckId, loggerConfig, context, getCurrentUser, onException, generateGraphiQLHeader, extraPlugins, authDecoder, cors, services, sdls, directives, armorConfig, allowedOperations, allowIntrospection, allowGraphiQL, defaultError, graphiQLEndpoint, schemaOptions, openTelemetryOptions, trustedDocuments, }: GraphQLHandlerOptions) => (event: APIGatewayProxyEvent, context: LambdaContext) => Promise<any>;
15
+ //# sourceMappingURL=graphql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/functions/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EAEpB,OAAO,IAAI,aAAa,EACzB,MAAM,YAAY,CAAA;AAMnB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAErD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,0TAsB9B,qBAAqB,aA+Gb,oBAAoB,WAClB,aAAa,KACrB,OAAO,CAAC,GAAG,CAcf,CAAA"}