@cedarjs/graphql-server 0.6.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,283 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var makeMergedSchema_exports = {};
30
+ __export(makeMergedSchema_exports, {
31
+ makeMergedSchema: () => makeMergedSchema
32
+ });
33
+ module.exports = __toCommonJS(makeMergedSchema_exports);
34
+ var import_merge = require("@graphql-tools/merge");
35
+ var import_schema = require("@graphql-tools/schema");
36
+ var opentelemetry = __toESM(require("@opentelemetry/api"), 1);
37
+ var import_lodash = __toESM(require("lodash"), 1);
38
+ var rootGqlSchema = __toESM(require("./rootSchema.js"), 1);
39
+ const { merge, omitBy } = import_lodash.default;
40
+ const wrapWithOpenTelemetry = async (func, args, root, context, info, name) => {
41
+ const tracer = opentelemetry.trace.getTracer("redwoodjs");
42
+ const parentSpan = context !== null && context["OPEN_TELEMETRY_GRAPHQL"];
43
+ const parentContext = parentSpan ? opentelemetry.trace.setSpan(opentelemetry.context.active(), parentSpan) : opentelemetry.context.active();
44
+ return await tracer.startActiveSpan(
45
+ `redwoodjs:graphql:resolver:${name}`,
46
+ {},
47
+ parentContext,
48
+ async (span) => {
49
+ span.setAttribute(
50
+ "graphql.execute.operationName",
51
+ `${args.operationName || "Anonymous Operation"}`
52
+ );
53
+ try {
54
+ const result = await func(args, {
55
+ root,
56
+ context,
57
+ info
58
+ });
59
+ span.end();
60
+ return result;
61
+ } catch (ex) {
62
+ span.recordException(ex);
63
+ span.setStatus({ code: opentelemetry.SpanStatusCode.ERROR });
64
+ span.end();
65
+ throw ex;
66
+ }
67
+ }
68
+ );
69
+ };
70
+ const mapFieldsToService = ({
71
+ fields = {},
72
+ resolvers: unmappedResolvers,
73
+ services
74
+ }) => Object.keys(fields).reduce((resolvers, name) => {
75
+ if (resolvers?.[name]) {
76
+ return resolvers;
77
+ }
78
+ if (services?.[name]) {
79
+ return {
80
+ ...resolvers,
81
+ // Map the arguments from GraphQL to an ordinary function a service would
82
+ // expect.
83
+ [name]: async (root, args, context, info) => {
84
+ const captureResolvers = (
85
+ // @ts-expect-error context is unknown
86
+ context && context["OPEN_TELEMETRY_GRAPHQL"] !== void 0
87
+ );
88
+ if (captureResolvers) {
89
+ return wrapWithOpenTelemetry(
90
+ services[name],
91
+ args,
92
+ root,
93
+ context,
94
+ info,
95
+ name
96
+ );
97
+ }
98
+ return services[name](args, { root, context, info });
99
+ }
100
+ };
101
+ }
102
+ return resolvers;
103
+ }, unmappedResolvers);
104
+ const resolveUnionType = (types) => ({
105
+ __resolveType(obj) {
106
+ if (Object.hasOwn(obj, "__typename")) {
107
+ for (const type of types) {
108
+ if (type.name === obj["__typename"]) {
109
+ return type.name;
110
+ }
111
+ }
112
+ }
113
+ const fieldIntersections = new Array(types.length).fill(0);
114
+ let maxIntersectionFields = 0;
115
+ let maxIntersectionType;
116
+ let maxIntersectionIdx = 0;
117
+ for (let i = 0; i < types.length; i++) {
118
+ const type = types[i];
119
+ const fieldIntersection = Object.keys(type.getFields()).filter(
120
+ (field) => field in obj
121
+ );
122
+ fieldIntersections[i] = fieldIntersection.length;
123
+ if (fieldIntersection.length > maxIntersectionFields) {
124
+ maxIntersectionFields = fieldIntersection.length;
125
+ maxIntersectionType = type;
126
+ maxIntersectionIdx = i;
127
+ }
128
+ }
129
+ if (fieldIntersections.includes(maxIntersectionFields, maxIntersectionIdx + 1)) {
130
+ throw Error(
131
+ "Unable to resolve correct type for union. Try adding unique fields to each type or __typename to each resolver"
132
+ );
133
+ }
134
+ return maxIntersectionType?.name ?? null;
135
+ }
136
+ });
137
+ const mergeResolversWithServices = ({
138
+ schema,
139
+ resolvers,
140
+ services
141
+ }) => {
142
+ const mergedServices = merge(
143
+ {},
144
+ ...Object.keys(services).map((name) => services[name])
145
+ );
146
+ const typesWithFields = Object.keys(schema.getTypeMap()).filter((name) => !name.startsWith("_")).filter(
147
+ (name) => typeof schema.getType(name).getFields !== "undefined"
148
+ ).map((name) => {
149
+ return schema.getType(name);
150
+ }).filter(
151
+ (type) => type !== void 0 && type !== null
152
+ );
153
+ const unionTypes = Object.keys(schema.getTypeMap()).filter(
154
+ (name) => typeof schema.getType(name).getTypes !== "undefined"
155
+ ).map((name) => {
156
+ return schema.getType(name);
157
+ }).filter(
158
+ (type) => type !== void 0 && type !== null
159
+ );
160
+ const mappedResolvers = typesWithFields.reduce((acc, type) => {
161
+ let servicesForType = mergedServices;
162
+ if (!["Query", "Mutation", "Subscription"].includes(type.name)) {
163
+ servicesForType = mergedServices?.[type.name];
164
+ }
165
+ return {
166
+ ...acc,
167
+ [type.name]: mapFieldsToService({
168
+ fields: type.getFields(),
169
+ resolvers: resolvers?.[type.name],
170
+ services: servicesForType
171
+ })
172
+ };
173
+ }, {});
174
+ const mappedUnionResolvers = unionTypes.reduce((acc, type) => {
175
+ return {
176
+ ...acc,
177
+ [type.name]: resolveUnionType(type.getTypes())
178
+ };
179
+ }, {});
180
+ return omitBy(
181
+ {
182
+ ...resolvers,
183
+ ...mappedResolvers,
184
+ ...mappedUnionResolvers
185
+ },
186
+ (v) => typeof v === "undefined"
187
+ );
188
+ };
189
+ const mergeResolvers = (schemas) => omitBy(
190
+ merge(
191
+ {},
192
+ ...[
193
+ rootGqlSchema.resolvers,
194
+ ...Object.values(schemas).map(({ resolvers }) => resolvers)
195
+ ]
196
+ ),
197
+ (v) => typeof v === "undefined"
198
+ );
199
+ const mergeTypes = (types, options) => {
200
+ const schemaDefinition = options && typeof options.schemaDefinition === "boolean" ? options.schemaDefinition : true;
201
+ return (0, import_merge.mergeTypeDefs)(types, {
202
+ useSchemaDefinition: schemaDefinition,
203
+ forceSchemaDefinition: schemaDefinition,
204
+ throwOnConflict: true,
205
+ commentDescriptions: true,
206
+ reverseDirectives: true,
207
+ ...options
208
+ });
209
+ };
210
+ const mergeResolversWithSubscriptions = ({
211
+ schema,
212
+ subscriptions,
213
+ resolverValidationOptions,
214
+ inheritResolversFromInterfaces
215
+ }) => {
216
+ if (subscriptions && subscriptions.length > 0) {
217
+ const subscriptionResolvers = { Subscription: {} };
218
+ subscriptions?.forEach((subscription) => {
219
+ subscriptionResolvers["Subscription"] = {
220
+ ...subscriptionResolvers["Subscription"],
221
+ ...subscription.resolvers
222
+ };
223
+ });
224
+ return (0, import_schema.addResolversToSchema)({
225
+ schema,
226
+ resolvers: subscriptionResolvers,
227
+ resolverValidationOptions,
228
+ inheritResolversFromInterfaces
229
+ });
230
+ }
231
+ return schema;
232
+ };
233
+ const makeMergedSchema = ({
234
+ sdls,
235
+ services,
236
+ schemaOptions = {},
237
+ directives,
238
+ subscriptions = [],
239
+ includeScalars
240
+ }) => {
241
+ const sdlSchemas = Object.values(sdls).map(({ schema: schema2 }) => schema2);
242
+ const rootEntries = [rootGqlSchema.schema];
243
+ if (includeScalars?.File !== false) {
244
+ rootEntries.push(rootGqlSchema.scalarSchemas.File);
245
+ }
246
+ const typeDefs = mergeTypes(
247
+ [
248
+ ...rootEntries,
249
+ ...directives.map((directive) => directive.schema),
250
+ // pick out schemas from directives
251
+ ...subscriptions.map((subscription) => subscription.schema),
252
+ // pick out schemas from subscriptions
253
+ ...sdlSchemas
254
+ // pick out the schemas from sdls
255
+ ],
256
+ { all: true }
257
+ );
258
+ const { typeDefs: schemaOptionsTypeDefs = [], ...otherSchemaOptions } = schemaOptions;
259
+ const schema = (0, import_schema.makeExecutableSchema)({
260
+ typeDefs: [typeDefs, schemaOptionsTypeDefs],
261
+ ...otherSchemaOptions
262
+ });
263
+ const resolvers = mergeResolversWithServices({
264
+ schema,
265
+ resolvers: mergeResolvers(sdls),
266
+ services
267
+ });
268
+ const schemaWithSubscriptions = mergeResolversWithSubscriptions({
269
+ schema,
270
+ subscriptions
271
+ });
272
+ const { resolverValidationOptions, inheritResolversFromInterfaces } = schemaOptions || {};
273
+ return (0, import_schema.addResolversToSchema)({
274
+ schema: schemaWithSubscriptions,
275
+ resolvers,
276
+ resolverValidationOptions,
277
+ inheritResolversFromInterfaces
278
+ });
279
+ };
280
+ // Annotate the CommonJS export names for ESM import in node:
281
+ 0 && (module.exports = {
282
+ makeMergedSchema
283
+ });
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,10 @@
1
+ export { useArmor } from './useArmor.js';
2
+ export { useRedwoodAuthContext } from './useRedwoodAuthContext.js';
3
+ export { useRedwoodDirective } from './useRedwoodDirective.js';
4
+ export { useRedwoodError } from './useRedwoodError.js';
5
+ export { useRedwoodGlobalContextSetter } from './useRedwoodGlobalContextSetter.js';
6
+ export { useRedwoodLogger } from './useRedwoodLogger.js';
7
+ export { useRedwoodTrustedDocuments } from './useRedwoodTrustedDocuments.js';
8
+ export { useRedwoodPopulateContext } from './useRedwoodPopulateContext.js';
9
+ export { useRedwoodOpenTelemetry } from './useRedwoodOpenTelemetry.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAA;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAA;AAE5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA"}
@@ -0,0 +1,52 @@
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 plugins_exports = {};
20
+ __export(plugins_exports, {
21
+ useArmor: () => import_useArmor.useArmor,
22
+ useRedwoodAuthContext: () => import_useRedwoodAuthContext.useRedwoodAuthContext,
23
+ useRedwoodDirective: () => import_useRedwoodDirective.useRedwoodDirective,
24
+ useRedwoodError: () => import_useRedwoodError.useRedwoodError,
25
+ useRedwoodGlobalContextSetter: () => import_useRedwoodGlobalContextSetter.useRedwoodGlobalContextSetter,
26
+ useRedwoodLogger: () => import_useRedwoodLogger.useRedwoodLogger,
27
+ useRedwoodOpenTelemetry: () => import_useRedwoodOpenTelemetry.useRedwoodOpenTelemetry,
28
+ useRedwoodPopulateContext: () => import_useRedwoodPopulateContext.useRedwoodPopulateContext,
29
+ useRedwoodTrustedDocuments: () => import_useRedwoodTrustedDocuments.useRedwoodTrustedDocuments
30
+ });
31
+ module.exports = __toCommonJS(plugins_exports);
32
+ var import_useArmor = require("./useArmor.js");
33
+ var import_useRedwoodAuthContext = require("./useRedwoodAuthContext.js");
34
+ var import_useRedwoodDirective = require("./useRedwoodDirective.js");
35
+ var import_useRedwoodError = require("./useRedwoodError.js");
36
+ var import_useRedwoodGlobalContextSetter = require("./useRedwoodGlobalContextSetter.js");
37
+ var import_useRedwoodLogger = require("./useRedwoodLogger.js");
38
+ var import_useRedwoodTrustedDocuments = require("./useRedwoodTrustedDocuments.js");
39
+ var import_useRedwoodPopulateContext = require("./useRedwoodPopulateContext.js");
40
+ var import_useRedwoodOpenTelemetry = require("./useRedwoodOpenTelemetry.js");
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ useArmor,
44
+ useRedwoodAuthContext,
45
+ useRedwoodDirective,
46
+ useRedwoodError,
47
+ useRedwoodGlobalContextSetter,
48
+ useRedwoodLogger,
49
+ useRedwoodOpenTelemetry,
50
+ useRedwoodPopulateContext,
51
+ useRedwoodTrustedDocuments
52
+ });
@@ -0,0 +1,4 @@
1
+ import type { Logger } from '@cedarjs/api/logger';
2
+ import type { ArmorConfig } from '../types.js';
3
+ export declare const useArmor: (logger: Logger, config?: ArmorConfig) => import("@envelop/types").Plugin<{}>;
4
+ //# sourceMappingURL=useArmor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useArmor.d.ts","sourceRoot":"","sources":["../../../src/plugins/useArmor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAEjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAO9C,eAAO,MAAM,QAAQ,WAAY,MAAM,WAAW,WAAW,wCAsC5D,CAAA"}
@@ -0,0 +1,69 @@
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 useArmor_exports = {};
20
+ __export(useArmor_exports, {
21
+ useArmor: () => useArmor
22
+ });
23
+ module.exports = __toCommonJS(useArmor_exports);
24
+ var import_graphql_armor = require("@escape.tech/graphql-armor");
25
+ const armorConfigDefaultOptions = {
26
+ logContext: false,
27
+ logErrors: true
28
+ };
29
+ const useArmor = (logger, config) => {
30
+ const logRejection = (ctx, error) => {
31
+ if (config?.logContext ?? armorConfigDefaultOptions.logContext) {
32
+ if (ctx) {
33
+ logger.debug({ custom: ctx }, `Armor rejection context`);
34
+ }
35
+ }
36
+ if (config?.logErrors ?? armorConfigDefaultOptions.logErrors) {
37
+ logger.error(error, `Armor rejected request: ${error.message}`);
38
+ }
39
+ };
40
+ return (0, import_graphql_armor.EnvelopArmorPlugin)({
41
+ ...config,
42
+ costLimit: {
43
+ ...config?.costLimit,
44
+ onReject: [logRejection]
45
+ },
46
+ maxAliases: {
47
+ allowList: [],
48
+ ...config?.maxAliases,
49
+ onReject: [logRejection]
50
+ },
51
+ maxDepth: {
52
+ ...config?.maxDepth,
53
+ flattenFragments: true,
54
+ onReject: [logRejection]
55
+ },
56
+ maxDirectives: {
57
+ ...config?.maxDirectives,
58
+ onReject: [logRejection]
59
+ },
60
+ maxTokens: {
61
+ ...config?.maxTokens,
62
+ onReject: [logRejection]
63
+ }
64
+ });
65
+ };
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ useArmor
69
+ });
@@ -0,0 +1,9 @@
1
+ import type { Plugin } from 'graphql-yoga';
2
+ import type { Decoder } from '@cedarjs/api';
3
+ import type { RedwoodGraphQLContext, GraphQLHandlerOptions } from '../types.js';
4
+ /**
5
+ * Envelop plugin for injecting the current user into the GraphQL Context,
6
+ * based on custom getCurrentUser function.
7
+ */
8
+ export declare const useRedwoodAuthContext: (getCurrentUser: GraphQLHandlerOptions["getCurrentUser"], authDecoder?: Decoder | Decoder[]) => Plugin<RedwoodGraphQLContext>;
9
+ //# sourceMappingURL=useRedwoodAuthContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRedwoodAuthContext.d.ts","sourceRoot":"","sources":["../../../src/plugins/useRedwoodAuthContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,EAAsB,OAAO,EAAE,MAAM,cAAc,CAAA;AAG/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAE/E;;;GAGG;AACH,eAAO,MAAM,qBAAqB,mBAChB,qBAAqB,CAAC,gBAAgB,CAAC,gBACzC,OAAO,GAAG,OAAO,EAAE,KAChC,MAAM,CAAC,qBAAqB,CAsC9B,CAAA"}
@@ -0,0 +1,61 @@
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 useRedwoodAuthContext_exports = {};
20
+ __export(useRedwoodAuthContext_exports, {
21
+ useRedwoodAuthContext: () => useRedwoodAuthContext
22
+ });
23
+ module.exports = __toCommonJS(useRedwoodAuthContext_exports);
24
+ var import_api = require("@cedarjs/api");
25
+ const useRedwoodAuthContext = (getCurrentUser, authDecoder) => {
26
+ return {
27
+ async onContextBuilding({ context, extendContext }) {
28
+ const { requestContext } = context;
29
+ let authContext = void 0;
30
+ try {
31
+ authContext = await (0, import_api.getAuthenticationContext)({
32
+ authDecoder,
33
+ event: context.event,
34
+ context: requestContext
35
+ });
36
+ } catch (error) {
37
+ throw new Error(
38
+ `Exception in getAuthenticationContext: ${error.message}`
39
+ );
40
+ }
41
+ try {
42
+ if (authContext) {
43
+ const currentUser = getCurrentUser ? await getCurrentUser(
44
+ authContext[0],
45
+ authContext[1],
46
+ authContext[2]
47
+ ) : null;
48
+ if (currentUser) {
49
+ extendContext({ currentUser });
50
+ }
51
+ }
52
+ } catch (error) {
53
+ throw new Error(`Exception in getCurrentUser: ${error.message}`);
54
+ }
55
+ }
56
+ };
57
+ };
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ useRedwoodAuthContext
61
+ });
@@ -0,0 +1,83 @@
1
+ import type { DirectiveNode, DocumentNode, GraphQLFieldConfig, GraphQLResolveInfo } from 'graphql';
2
+ import type { Plugin } from 'graphql-yoga';
3
+ import type { GlobalContext } from '@cedarjs/context';
4
+ export interface DirectiveParams<FieldType = any, DirectiveArgs = Record<string, any>> {
5
+ root: unknown;
6
+ args: Record<string, unknown>;
7
+ context: GlobalContext;
8
+ info: GraphQLResolveInfo;
9
+ directiveNode?: DirectiveNode;
10
+ directiveArgs: DirectiveArgs;
11
+ resolvedValue: FieldType;
12
+ }
13
+ /**
14
+ * Generic Type for the arguments/parameters passed to the validate function for validator directives
15
+ *
16
+ * You have to pass in the type of directiveArgs
17
+ * @example ValidateArgs<{ roles?: string[] }>
18
+ */
19
+ export declare type ValidateArgs<DirectiveArgs = Record<string, any>> = Omit<DirectiveParams<never, DirectiveArgs>, // we remove resolvedValue anyway in this type
20
+ 'resolvedValue'>;
21
+ /**
22
+ * Write your validation logic inside this function.
23
+ * Validator directives do not have access to the field value, i.e. they are called before resolving the value
24
+ *
25
+ * - Throw an error, if you want to stop executing e.g. not sufficient permissions
26
+ * - Validator directives can be async or sync
27
+ * - Returned value will be ignored
28
+ *
29
+ * You have to pass in the type of directiveArgs
30
+ * @example ValidatorDirectiveFunc<{ roles?: string[] }>
31
+ *
32
+ */
33
+ export type ValidatorDirectiveFunc<TDirectiveArgs = Record<string, any>> = (args: ValidateArgs<TDirectiveArgs>) => Promise<void> | void;
34
+ /**
35
+ * Generic Type for the arguments/parameters passed to the transform function for transformer directives
36
+ *
37
+ * You have to pass in the type of directiveArgs, and the resolverValue (i.e. the type of the field you are transforming)
38
+ * @example TransformArgs<Post, { allowedRoles: string[] }>
39
+ */
40
+ export declare type TransformArgs<TField = any, TDirectiveArgs = Record<string, any>> = DirectiveParams<TField, TDirectiveArgs>;
41
+ /**
42
+ * Write your transformation logic inside this function.
43
+ * Transformer directives run **after** resolving the value
44
+ *
45
+ * - You can also throw an error, if you want to stop executing, but note that the value has already been resolved
46
+ * - Transformer directives **must** be synchronous, and return a value
47
+ *
48
+ * You have to pass in the type of directiveArgs, and the resolverValue (i.e. the type of the field you are transforming)
49
+ * @example TransformerDirectiveFunc<Post, { allowedRoles: string[] }>
50
+ *
51
+ */
52
+ export type TransformerDirectiveFunc<TField = any, TDirectiveArgs = Record<string, any>> = (args: TransformArgs<TField, TDirectiveArgs>) => TField;
53
+ export declare enum DirectiveType {
54
+ VALIDATOR = "VALIDATOR_DIRECTIVE",
55
+ TRANSFORMER = "TRANSFORMER_DIRECTIVE"
56
+ }
57
+ export type RedwoodDirective = ValidatorDirective | TransformerDirective;
58
+ export interface ValidatorDirective extends ValidatorDirectiveOptions {
59
+ schema: DocumentNode;
60
+ }
61
+ export interface TransformerDirective extends TransformerDirectiveOptions {
62
+ schema: DocumentNode;
63
+ }
64
+ interface ValidatorDirectiveOptions {
65
+ onResolvedValue: ValidatorDirectiveFunc;
66
+ type: DirectiveType.VALIDATOR;
67
+ name: string;
68
+ }
69
+ interface TransformerDirectiveOptions {
70
+ onResolvedValue: TransformerDirectiveFunc;
71
+ type: DirectiveType.TRANSFORMER;
72
+ name: string;
73
+ }
74
+ export type DirectivePluginOptions = ValidatorDirectiveOptions | TransformerDirectiveOptions;
75
+ export declare function hasDirective(info: GraphQLResolveInfo): boolean;
76
+ export declare function getDirectiveByName(fieldConfig: GraphQLFieldConfig<any, any, any>, directiveName: string): null | DirectiveNode;
77
+ export declare function isPromise(value: any): value is Promise<unknown>;
78
+ export type useRedwoodDirectiveReturn = Plugin<{
79
+ onResolvedValue: ValidatorDirectiveFunc | TransformerDirectiveFunc;
80
+ }>;
81
+ export declare const useRedwoodDirective: (options: DirectivePluginOptions) => useRedwoodDirectiveReturn;
82
+ export {};
83
+ //# sourceMappingURL=useRedwoodDirective.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRedwoodDirective.d.ts","sourceRoot":"","sources":["../../../src/plugins/useRedwoodDirective.ts"],"names":[],"mappings":"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"}