@cedarjs/graphql-server 0.6.1-next.0 → 0.6.1-next.51

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 (148) hide show
  1. package/dist/cjs/cors.d.ts +10 -0
  2. package/dist/cjs/cors.d.ts.map +1 -0
  3. package/dist/cjs/cors.js +70 -0
  4. package/dist/cjs/createGraphQLYoga.d.ts +6 -0
  5. package/dist/cjs/createGraphQLYoga.d.ts.map +1 -0
  6. package/dist/cjs/createGraphQLYoga.js +178 -0
  7. package/dist/cjs/directives/makeDirectives.d.ts +8 -0
  8. package/dist/cjs/directives/makeDirectives.d.ts.map +1 -0
  9. package/dist/cjs/directives/makeDirectives.js +89 -0
  10. package/dist/cjs/errors.d.ts +28 -0
  11. package/dist/cjs/errors.d.ts.map +1 -0
  12. package/dist/cjs/errors.js +98 -0
  13. package/dist/cjs/functions/graphql.d.ts +15 -0
  14. package/dist/cjs/functions/graphql.d.ts.map +1 -0
  15. package/dist/cjs/functions/graphql.js +141 -0
  16. package/dist/cjs/functions/useRequireAuth.d.ts +12 -0
  17. package/dist/cjs/functions/useRequireAuth.d.ts.map +1 -0
  18. package/dist/cjs/functions/useRequireAuth.js +70 -0
  19. package/dist/cjs/global.api-auto-imports.d.ts +5 -0
  20. package/dist/cjs/global.api-auto-imports.d.ts.map +1 -0
  21. package/dist/cjs/global.api-auto-imports.js +1 -0
  22. package/dist/cjs/globalContext.d.ts +25 -0
  23. package/dist/cjs/globalContext.d.ts.map +1 -0
  24. package/dist/cjs/globalContext.js +55 -0
  25. package/dist/cjs/globalContextStore.d.ts +9 -0
  26. package/dist/cjs/globalContextStore.d.ts.map +1 -0
  27. package/dist/cjs/globalContextStore.js +35 -0
  28. package/dist/cjs/graphiql.d.ts +8 -0
  29. package/dist/cjs/graphiql.d.ts.map +1 -0
  30. package/dist/cjs/graphiql.js +45 -0
  31. package/dist/cjs/index.d.ts +14 -0
  32. package/dist/cjs/index.d.ts.map +1 -0
  33. package/dist/cjs/index.js +75 -0
  34. package/dist/cjs/introspection.d.ts +7 -0
  35. package/dist/cjs/introspection.d.ts.map +1 -0
  36. package/dist/cjs/introspection.js +36 -0
  37. package/dist/cjs/makeMergedSchema.d.ts +17 -0
  38. package/dist/cjs/makeMergedSchema.d.ts.map +1 -0
  39. package/dist/cjs/makeMergedSchema.js +283 -0
  40. package/dist/cjs/package.json +1 -0
  41. package/dist/cjs/plugins/index.d.ts +10 -0
  42. package/dist/cjs/plugins/index.d.ts.map +1 -0
  43. package/dist/cjs/plugins/index.js +52 -0
  44. package/dist/cjs/plugins/useArmor.d.ts +4 -0
  45. package/dist/cjs/plugins/useArmor.d.ts.map +1 -0
  46. package/dist/cjs/plugins/useArmor.js +69 -0
  47. package/dist/cjs/plugins/useRedwoodAuthContext.d.ts +9 -0
  48. package/dist/cjs/plugins/useRedwoodAuthContext.d.ts.map +1 -0
  49. package/dist/cjs/plugins/useRedwoodAuthContext.js +61 -0
  50. package/dist/cjs/plugins/useRedwoodDirective.d.ts +83 -0
  51. package/dist/cjs/plugins/useRedwoodDirective.d.ts.map +1 -0
  52. package/dist/cjs/plugins/useRedwoodDirective.js +166 -0
  53. package/dist/cjs/plugins/useRedwoodError.d.ts +20 -0
  54. package/dist/cjs/plugins/useRedwoodError.d.ts.map +1 -0
  55. package/dist/cjs/plugins/useRedwoodError.js +63 -0
  56. package/dist/cjs/plugins/useRedwoodGlobalContextSetter.d.ts +9 -0
  57. package/dist/cjs/plugins/useRedwoodGlobalContextSetter.d.ts.map +1 -0
  58. package/dist/cjs/plugins/useRedwoodGlobalContextSetter.js +35 -0
  59. package/dist/cjs/plugins/useRedwoodLogger.d.ts +115 -0
  60. package/dist/cjs/plugins/useRedwoodLogger.d.ts.map +1 -0
  61. package/dist/cjs/plugins/useRedwoodLogger.js +149 -0
  62. package/dist/cjs/plugins/useRedwoodOpenTelemetry.d.ts +22 -0
  63. package/dist/cjs/plugins/useRedwoodOpenTelemetry.d.ts.map +1 -0
  64. package/dist/cjs/plugins/useRedwoodOpenTelemetry.js +156 -0
  65. package/dist/cjs/plugins/useRedwoodPopulateContext.d.ts +9 -0
  66. package/dist/cjs/plugins/useRedwoodPopulateContext.d.ts.map +1 -0
  67. package/dist/cjs/plugins/useRedwoodPopulateContext.js +35 -0
  68. package/dist/cjs/plugins/useRedwoodTrustedDocuments.d.ts +23 -0
  69. package/dist/cjs/plugins/useRedwoodTrustedDocuments.d.ts.map +1 -0
  70. package/dist/cjs/plugins/useRedwoodTrustedDocuments.js +80 -0
  71. package/dist/cjs/rootSchema.d.ts +25 -0
  72. package/dist/cjs/rootSchema.d.ts.map +1 -0
  73. package/dist/cjs/rootSchema.js +97 -0
  74. package/dist/cjs/subscriptions/makeSubscriptions.d.ts +18 -0
  75. package/dist/cjs/subscriptions/makeSubscriptions.d.ts.map +1 -0
  76. package/dist/cjs/subscriptions/makeSubscriptions.js +40 -0
  77. package/dist/cjs/types.d.ts +215 -0
  78. package/dist/cjs/types.d.ts.map +1 -0
  79. package/dist/cjs/types.js +16 -0
  80. package/dist/cors.js +2 -26
  81. package/dist/createGraphQLYoga.d.ts +1 -1
  82. package/dist/createGraphQLYoga.d.ts.map +1 -1
  83. package/dist/createGraphQLYoga.js +45 -59
  84. package/dist/directives/makeDirectives.d.ts +1 -1
  85. package/dist/directives/makeDirectives.d.ts.map +1 -1
  86. package/dist/directives/makeDirectives.js +9 -36
  87. package/dist/errors.js +5 -36
  88. package/dist/functions/graphql.d.ts +1 -1
  89. package/dist/functions/graphql.d.ts.map +1 -1
  90. package/dist/functions/graphql.js +6 -30
  91. package/dist/functions/useRequireAuth.d.ts +1 -1
  92. package/dist/functions/useRequireAuth.d.ts.map +1 -1
  93. package/dist/functions/useRequireAuth.js +9 -33
  94. package/dist/global.api-auto-imports.js +0 -1
  95. package/dist/globalContext.js +6 -32
  96. package/dist/globalContextStore.d.ts +1 -1
  97. package/dist/globalContextStore.d.ts.map +1 -1
  98. package/dist/globalContextStore.js +4 -28
  99. package/dist/graphiql.d.ts +1 -1
  100. package/dist/graphiql.d.ts.map +1 -1
  101. package/dist/graphiql.js +2 -26
  102. package/dist/index.d.ts +12 -11
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js +24 -82
  105. package/dist/introspection.d.ts +1 -1
  106. package/dist/introspection.d.ts.map +1 -1
  107. package/dist/introspection.js +2 -26
  108. package/dist/makeMergedSchema.d.ts +3 -3
  109. package/dist/makeMergedSchema.d.ts.map +1 -1
  110. package/dist/makeMergedSchema.js +19 -49
  111. package/dist/plugins/index.d.ts +9 -9
  112. package/dist/plugins/index.d.ts.map +1 -1
  113. package/dist/plugins/index.js +11 -43
  114. package/dist/plugins/useArmor.d.ts +2 -2
  115. package/dist/plugins/useArmor.d.ts.map +1 -1
  116. package/dist/plugins/useArmor.js +4 -28
  117. package/dist/plugins/useRedwoodAuthContext.d.ts +1 -1
  118. package/dist/plugins/useRedwoodAuthContext.d.ts.map +1 -1
  119. package/dist/plugins/useRedwoodAuthContext.js +4 -28
  120. package/dist/plugins/useRedwoodDirective.js +9 -37
  121. package/dist/plugins/useRedwoodError.d.ts +1 -1
  122. package/dist/plugins/useRedwoodError.d.ts.map +1 -1
  123. package/dist/plugins/useRedwoodError.js +10 -31
  124. package/dist/plugins/useRedwoodGlobalContextSetter.d.ts +1 -1
  125. package/dist/plugins/useRedwoodGlobalContextSetter.d.ts.map +1 -1
  126. package/dist/plugins/useRedwoodGlobalContextSetter.js +4 -28
  127. package/dist/plugins/useRedwoodLogger.d.ts +1 -1
  128. package/dist/plugins/useRedwoodLogger.d.ts.map +1 -1
  129. package/dist/plugins/useRedwoodLogger.js +10 -34
  130. package/dist/plugins/useRedwoodOpenTelemetry.d.ts +1 -1
  131. package/dist/plugins/useRedwoodOpenTelemetry.d.ts.map +1 -1
  132. package/dist/plugins/useRedwoodOpenTelemetry.js +11 -46
  133. package/dist/plugins/useRedwoodPopulateContext.d.ts +1 -1
  134. package/dist/plugins/useRedwoodPopulateContext.d.ts.map +1 -1
  135. package/dist/plugins/useRedwoodPopulateContext.js +2 -26
  136. package/dist/plugins/useRedwoodTrustedDocuments.d.ts +1 -1
  137. package/dist/plugins/useRedwoodTrustedDocuments.d.ts.map +1 -1
  138. package/dist/plugins/useRedwoodTrustedDocuments.js +4 -28
  139. package/dist/rootSchema.js +26 -54
  140. package/dist/subscriptions/makeSubscriptions.js +5 -29
  141. package/dist/types.d.ts +4 -4
  142. package/dist/types.d.ts.map +1 -1
  143. package/dist/types.js +0 -16
  144. package/package.json +27 -10
  145. package/dist/plugins/__fixtures__/common.d.ts +0 -9
  146. package/dist/plugins/__fixtures__/common.d.ts.map +0 -1
  147. package/dist/plugins/__fixtures__/envelop-testing.d.ts +0 -55
  148. package/dist/plugins/__fixtures__/envelop-testing.d.ts.map +0 -1
@@ -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"}
@@ -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.js';
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,YAAY,CAAA;AAEpD,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.js");
29
+ var import_makeDirectives = require("./directives/makeDirectives.js");
30
+ var import_graphiql = require("./graphiql.js");
31
+ var import_introspection = require("./introspection.js");
32
+ var import_makeMergedSchema = require("./makeMergedSchema.js");
33
+ var import_plugins = require("./plugins/index.js");
34
+ var import_makeSubscriptions = require("./subscriptions/makeSubscriptions.js");
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.js';
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,mCAAmC,CAAA;AAW1C,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.js");
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"}
@@ -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.js';
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,aAAa,CAAA;AAExD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,0TAsB9B,qBAAqB,aA+Gb,oBAAoB,WAClB,aAAa,KACrB,OAAO,CAAC,GAAG,CAcf,CAAA"}
@@ -0,0 +1,141 @@
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 graphql_exports = {};
20
+ __export(graphql_exports, {
21
+ createGraphQLHandler: () => createGraphQLHandler
22
+ });
23
+ module.exports = __toCommonJS(graphql_exports);
24
+ var import_store = require("@cedarjs/context/dist/store");
25
+ var import_createGraphQLYoga = require("../createGraphQLYoga.js");
26
+ const createGraphQLHandler = ({
27
+ healthCheckId,
28
+ loggerConfig,
29
+ context,
30
+ getCurrentUser,
31
+ onException,
32
+ generateGraphiQLHeader,
33
+ extraPlugins,
34
+ authDecoder,
35
+ cors,
36
+ services,
37
+ sdls,
38
+ directives = [],
39
+ armorConfig,
40
+ allowedOperations,
41
+ allowIntrospection,
42
+ allowGraphiQL,
43
+ defaultError = "Something went wrong.",
44
+ graphiQLEndpoint = "/graphql",
45
+ schemaOptions,
46
+ openTelemetryOptions,
47
+ trustedDocuments
48
+ }) => {
49
+ const { yoga, logger } = (0, import_createGraphQLYoga.createGraphQLYoga)({
50
+ healthCheckId,
51
+ loggerConfig,
52
+ context,
53
+ getCurrentUser,
54
+ onException,
55
+ generateGraphiQLHeader,
56
+ extraPlugins,
57
+ authDecoder,
58
+ cors,
59
+ services,
60
+ sdls,
61
+ directives,
62
+ armorConfig,
63
+ allowedOperations,
64
+ allowIntrospection,
65
+ allowGraphiQL,
66
+ defaultError,
67
+ graphiQLEndpoint,
68
+ schemaOptions,
69
+ openTelemetryOptions,
70
+ trustedDocuments
71
+ });
72
+ const handlerFn = async (event, requestContext) => {
73
+ requestContext.callbackWaitsForEmptyEventLoop = false;
74
+ let lambdaResponse;
75
+ try {
76
+ const [, rest = ""] = event.path.split(graphiQLEndpoint);
77
+ const url = new URL(graphiQLEndpoint + rest, "http://localhost");
78
+ if (event.queryStringParameters != null) {
79
+ for (const queryName in event.queryStringParameters) {
80
+ const queryValue = event.queryStringParameters[queryName];
81
+ if (queryValue != null) {
82
+ url.searchParams.set(queryName, queryValue);
83
+ }
84
+ }
85
+ }
86
+ const response = await yoga.fetch(
87
+ url,
88
+ {
89
+ method: event.httpMethod,
90
+ headers: event.headers,
91
+ body: event.body ? Buffer.from(event.body, event.isBase64Encoded ? "base64" : "utf8") : void 0
92
+ },
93
+ {
94
+ event,
95
+ requestContext
96
+ }
97
+ );
98
+ const responseHeaders = {};
99
+ response.headers.forEach((value, name) => {
100
+ responseHeaders[name] = value;
101
+ });
102
+ lambdaResponse = {
103
+ body: await response.text(),
104
+ statusCode: response.status,
105
+ headers: responseHeaders,
106
+ isBase64Encoded: false
107
+ };
108
+ } catch (e) {
109
+ logger.error(e);
110
+ if (onException) {
111
+ onException();
112
+ }
113
+ lambdaResponse = {
114
+ body: JSON.stringify({ error: "GraphQL execution failed" }),
115
+ statusCode: 200
116
+ // should be 500
117
+ };
118
+ }
119
+ if (!lambdaResponse.headers) {
120
+ lambdaResponse.headers = {};
121
+ }
122
+ return lambdaResponse;
123
+ };
124
+ return (event, context2) => {
125
+ const execFn = async () => {
126
+ try {
127
+ return await handlerFn(event, context2);
128
+ } catch (e) {
129
+ if (onException) {
130
+ onException();
131
+ }
132
+ throw e;
133
+ }
134
+ };
135
+ return (0, import_store.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), execFn);
136
+ };
137
+ };
138
+ // Annotate the CommonJS export names for ESM import in node:
139
+ 0 && (module.exports = {
140
+ createGraphQLHandler
141
+ });
@@ -0,0 +1,12 @@
1
+ import type { APIGatewayEvent, Context as LambdaContext } from 'aws-lambda';
2
+ import type { Decoder } from '@cedarjs/api';
3
+ import type { GetCurrentUser } from '../types.js';
4
+ interface Args {
5
+ authDecoder?: Decoder | Decoder[];
6
+ handlerFn: (event: APIGatewayEvent, context: LambdaContext, ...others: any) => any;
7
+ getCurrentUser?: GetCurrentUser;
8
+ }
9
+ export type UseRequireAuth = (args: Args) => (event: APIGatewayEvent, context: LambdaContext, ...rest: any) => Promise<ReturnType<Args['handlerFn']>>;
10
+ export declare const useRequireAuth: UseRequireAuth;
11
+ export {};
12
+ //# sourceMappingURL=useRequireAuth.d.ts.map