@cedarjs/graphql-server 5.0.7-next.338 → 5.0.7

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 (127) 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 +193 -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 +32 -0
  11. package/dist/cjs/errors.d.ts.map +1 -0
  12. package/dist/cjs/errors.js +101 -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 +201 -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 +7 -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/{plugins/useCedarAuthContext.d.ts → cjs/plugins/useRedwoodAuthContext.d.ts} +2 -2
  48. package/dist/cjs/plugins/useRedwoodAuthContext.d.ts.map +1 -0
  49. package/dist/cjs/plugins/useRedwoodAuthContext.js +74 -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/{plugins/useCedarError.d.ts → cjs/plugins/useRedwoodError.d.ts} +4 -4
  54. package/dist/cjs/plugins/useRedwoodError.d.ts.map +1 -0
  55. package/dist/cjs/plugins/useRedwoodError.js +62 -0
  56. package/dist/{plugins/useCedarGlobalContextSetter.d.ts → cjs/plugins/useRedwoodGlobalContextSetter.d.ts} +2 -2
  57. package/dist/cjs/plugins/useRedwoodGlobalContextSetter.d.ts.map +1 -0
  58. package/dist/cjs/plugins/useRedwoodGlobalContextSetter.js +35 -0
  59. package/dist/{plugins/useCedarLogger.d.ts → cjs/plugins/useRedwoodLogger.d.ts} +2 -2
  60. package/dist/cjs/plugins/useRedwoodLogger.d.ts.map +1 -0
  61. package/dist/cjs/plugins/useRedwoodLogger.js +156 -0
  62. package/dist/{plugins/useCedarOpenTelemetry.d.ts → cjs/plugins/useRedwoodOpenTelemetry.d.ts} +3 -3
  63. package/dist/cjs/plugins/useRedwoodOpenTelemetry.d.ts.map +1 -0
  64. package/dist/cjs/plugins/useRedwoodOpenTelemetry.js +156 -0
  65. package/dist/{plugins/useCedarPopulateContext.d.ts → cjs/plugins/useRedwoodPopulateContext.d.ts} +2 -2
  66. package/dist/cjs/plugins/useRedwoodPopulateContext.d.ts.map +1 -0
  67. package/dist/cjs/plugins/useRedwoodPopulateContext.js +35 -0
  68. package/dist/{plugins/useCedarTrustedDocuments.d.ts → cjs/plugins/useRedwoodTrustedDocuments.d.ts} +3 -5
  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 +108 -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 +231 -0
  78. package/dist/cjs/types.d.ts.map +1 -0
  79. package/dist/cjs/types.js +16 -0
  80. package/dist/createGraphQLYoga.js +19 -19
  81. package/dist/directives/makeDirectives.d.ts +2 -2
  82. package/dist/directives/makeDirectives.d.ts.map +1 -1
  83. package/dist/index.d.ts +2 -2
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +0 -2
  86. package/dist/makeMergedSchema.d.ts +6 -6
  87. package/dist/makeMergedSchema.d.ts.map +1 -1
  88. package/dist/plugins/index.d.ts +8 -8
  89. package/dist/plugins/index.d.ts.map +1 -1
  90. package/dist/plugins/index.js +16 -20
  91. package/dist/plugins/useRedwoodAuthContext.d.ts +9 -0
  92. package/dist/plugins/useRedwoodAuthContext.d.ts.map +1 -0
  93. package/dist/plugins/useRedwoodAuthContext.js +50 -0
  94. package/dist/plugins/useRedwoodDirective.d.ts +3 -9
  95. package/dist/plugins/useRedwoodDirective.d.ts.map +1 -1
  96. package/dist/plugins/useRedwoodDirective.js +1 -3
  97. package/dist/plugins/useRedwoodError.d.ts +20 -0
  98. package/dist/plugins/useRedwoodError.d.ts.map +1 -0
  99. package/dist/plugins/{useCedarError.js → useRedwoodError.js} +5 -5
  100. package/dist/plugins/useRedwoodGlobalContextSetter.d.ts +9 -0
  101. package/dist/plugins/useRedwoodGlobalContextSetter.d.ts.map +1 -0
  102. package/dist/plugins/{useCedarGlobalContextSetter.js → useRedwoodGlobalContextSetter.js} +2 -2
  103. package/dist/plugins/useRedwoodLogger.d.ts +115 -0
  104. package/dist/plugins/useRedwoodLogger.d.ts.map +1 -0
  105. package/dist/plugins/{useCedarLogger.js → useRedwoodLogger.js} +2 -2
  106. package/dist/plugins/useRedwoodOpenTelemetry.d.ts +22 -0
  107. package/dist/plugins/useRedwoodOpenTelemetry.d.ts.map +1 -0
  108. package/dist/plugins/{useCedarOpenTelemetry.js → useRedwoodOpenTelemetry.js} +3 -3
  109. package/dist/plugins/useRedwoodPopulateContext.d.ts +9 -0
  110. package/dist/plugins/useRedwoodPopulateContext.d.ts.map +1 -0
  111. package/dist/plugins/{useCedarPopulateContext.js → useRedwoodPopulateContext.js} +2 -2
  112. package/dist/plugins/useRedwoodTrustedDocuments.d.ts +23 -0
  113. package/dist/plugins/useRedwoodTrustedDocuments.d.ts.map +1 -0
  114. package/dist/plugins/{useCedarTrustedDocuments.js → useRedwoodTrustedDocuments.js} +13 -20
  115. package/dist/subscriptions/makeSubscriptions.d.ts +3 -3
  116. package/dist/subscriptions/makeSubscriptions.d.ts.map +1 -1
  117. package/dist/types.d.ts +9 -13
  118. package/dist/types.d.ts.map +1 -1
  119. package/package.json +24 -16
  120. package/dist/plugins/useCedarAuthContext.d.ts.map +0 -1
  121. package/dist/plugins/useCedarAuthContext.js +0 -30
  122. package/dist/plugins/useCedarError.d.ts.map +0 -1
  123. package/dist/plugins/useCedarGlobalContextSetter.d.ts.map +0 -1
  124. package/dist/plugins/useCedarLogger.d.ts.map +0 -1
  125. package/dist/plugins/useCedarOpenTelemetry.d.ts.map +0 -1
  126. package/dist/plugins/useCedarPopulateContext.d.ts.map +0 -1
  127. package/dist/plugins/useCedarTrustedDocuments.d.ts.map +0 -1
@@ -0,0 +1,166 @@
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 useRedwoodDirective_exports = {};
20
+ __export(useRedwoodDirective_exports, {
21
+ DirectiveType: () => DirectiveType,
22
+ getDirectiveByName: () => getDirectiveByName,
23
+ hasDirective: () => hasDirective,
24
+ isPromise: () => isPromise,
25
+ useRedwoodDirective: () => useRedwoodDirective
26
+ });
27
+ module.exports = __toCommonJS(useRedwoodDirective_exports);
28
+ var import_utils = require("@graphql-tools/utils");
29
+ var import_graphql = require("graphql");
30
+ var DirectiveType = /* @__PURE__ */ ((DirectiveType2) => {
31
+ DirectiveType2["VALIDATOR"] = "VALIDATOR_DIRECTIVE";
32
+ DirectiveType2["TRANSFORMER"] = "TRANSFORMER_DIRECTIVE";
33
+ return DirectiveType2;
34
+ })(DirectiveType || {});
35
+ function hasDirective(info) {
36
+ try {
37
+ const { parentType, fieldName, schema } = info;
38
+ const schemaType = schema.getType(parentType.name);
39
+ const field = schemaType.getFields()[fieldName];
40
+ const astNode = field.astNode;
41
+ return !!astNode?.directives?.length;
42
+ } catch (error) {
43
+ console.error(error);
44
+ return false;
45
+ }
46
+ }
47
+ function getDirectiveByName(fieldConfig, directiveName) {
48
+ const associatedDirective = fieldConfig.astNode?.directives?.find(
49
+ (directive) => directive.name.value === directiveName
50
+ );
51
+ return associatedDirective ?? null;
52
+ }
53
+ function isPromise(value) {
54
+ return typeof value?.then === "function";
55
+ }
56
+ function wrapAffectedResolvers(schema, options) {
57
+ return (0, import_utils.mapSchema)(schema, {
58
+ [import_utils.MapperKind.OBJECT_FIELD](fieldConfig, _, __, schema2) {
59
+ const directiveNode = getDirectiveByName(fieldConfig, options.name);
60
+ const directive = directiveNode ? schema2.getDirective(directiveNode.name.value) : null;
61
+ if (directiveNode && directive) {
62
+ const directiveArgs = (0, import_graphql.getDirectiveValues)(directive, { directives: [directiveNode] }) || {};
63
+ const originalResolve = fieldConfig.resolve ?? import_graphql.defaultFieldResolver;
64
+ const originalSubscribe = fieldConfig.subscribe ?? import_graphql.defaultFieldResolver;
65
+ if (_isValidator(options)) {
66
+ return {
67
+ ...fieldConfig,
68
+ resolve: function useRedwoodDirectiveValidatorResolver(root, args, context, info) {
69
+ const result = options.onResolvedValue({
70
+ root,
71
+ args,
72
+ context,
73
+ info,
74
+ directiveNode,
75
+ directiveArgs
76
+ });
77
+ if (isPromise(result)) {
78
+ return result.then(
79
+ () => originalResolve(root, args, context, info)
80
+ );
81
+ }
82
+ return originalResolve(root, args, context, info);
83
+ },
84
+ subscribe: function useRedwoodDirectiveValidatorResolver(root, args, context, info) {
85
+ const result = options.onResolvedValue({
86
+ root,
87
+ args,
88
+ context,
89
+ info,
90
+ directiveNode,
91
+ directiveArgs
92
+ });
93
+ if (isPromise(result)) {
94
+ return result.then(
95
+ () => originalSubscribe(root, args, context, info)
96
+ );
97
+ }
98
+ return originalSubscribe(root, args, context, info);
99
+ }
100
+ };
101
+ }
102
+ if (_isTransformer(options)) {
103
+ return {
104
+ ...fieldConfig,
105
+ resolve: function useRedwoodDirectiveTransformerResolver(root, args, context, info) {
106
+ const resolvedValue = originalResolve(root, args, context, info);
107
+ if (isPromise(resolvedValue)) {
108
+ return resolvedValue.then(
109
+ (resolvedValue2) => options.onResolvedValue({
110
+ root,
111
+ args,
112
+ context,
113
+ info,
114
+ directiveNode,
115
+ directiveArgs,
116
+ resolvedValue: resolvedValue2
117
+ })
118
+ );
119
+ }
120
+ return options.onResolvedValue({
121
+ root,
122
+ args,
123
+ context,
124
+ info,
125
+ directiveNode,
126
+ directiveArgs,
127
+ resolvedValue
128
+ });
129
+ }
130
+ };
131
+ }
132
+ }
133
+ return fieldConfig;
134
+ }
135
+ });
136
+ }
137
+ const useRedwoodDirective = (options) => {
138
+ const wasDirectiveApplied = /* @__PURE__ */ Symbol.for(`useRedwoodDirective.${options.name}}`);
139
+ return {
140
+ onSchemaChange({ schema, replaceSchema }) {
141
+ if (schema.extensions?.[wasDirectiveApplied] === true) {
142
+ return;
143
+ }
144
+ const transformedSchema = wrapAffectedResolvers(schema, options);
145
+ transformedSchema.extensions = {
146
+ ...schema.extensions,
147
+ [wasDirectiveApplied]: true
148
+ };
149
+ replaceSchema(transformedSchema);
150
+ }
151
+ };
152
+ };
153
+ const _isValidator = (options) => {
154
+ return options.type === "VALIDATOR_DIRECTIVE" /* VALIDATOR */;
155
+ };
156
+ const _isTransformer = (options) => {
157
+ return options.type === "TRANSFORMER_DIRECTIVE" /* TRANSFORMER */;
158
+ };
159
+ // Annotate the CommonJS export names for ESM import in node:
160
+ 0 && (module.exports = {
161
+ DirectiveType,
162
+ getDirectiveByName,
163
+ hasDirective,
164
+ isPromise,
165
+ useRedwoodDirective
166
+ });
@@ -2,13 +2,13 @@ import type { Plugin } from 'graphql-yoga';
2
2
  import type { Logger } from '@cedarjs/api/logger';
3
3
  import type { CedarGraphQLContext } from '../types.js';
4
4
  /**
5
- * Converts CedarErrors to GraphQLErrors
5
+ * Converts RedwoodErrors to GraphQLErrors
6
6
  *
7
7
  * This is a workaround for the fact that graphql-yoga doesn't support custom error types.
8
8
  *
9
9
  * Yoga automatically masks unexpected errors and prevents leaking sensitive information to clients.
10
10
  *
11
- * Since CedarErrors (such as ServiceValidation errors) are expected,
11
+ * Since RedwoodErrors (such as ServiceValidation errors) are expected,
12
12
  * we need to convert them to GraphQLErrors so that they are not masked.
13
13
  *
14
14
  * See: https://the-guild.dev/graphql/yoga-server/docs/features/error-masking
@@ -16,5 +16,5 @@ import type { CedarGraphQLContext } from '../types.js';
16
16
  * @param logger
17
17
  * @returns ExecutionResult
18
18
  */
19
- export declare const useCedarError: (logger: Logger) => Plugin<CedarGraphQLContext>;
20
- //# sourceMappingURL=useCedarError.d.ts.map
19
+ export declare const useRedwoodError: (logger: Logger) => Plugin<CedarGraphQLContext>;
20
+ //# sourceMappingURL=useRedwoodError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRedwoodError.d.ts","sourceRoot":"","sources":["../../../src/plugins/useRedwoodError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAO1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,eAAe,GAC1B,QAAQ,MAAM,KACb,MAAM,CAAC,mBAAmB,CAsC5B,CAAA"}
@@ -0,0 +1,62 @@
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 useRedwoodError_exports = {};
20
+ __export(useRedwoodError_exports, {
21
+ useRedwoodError: () => useRedwoodError
22
+ });
23
+ module.exports = __toCommonJS(useRedwoodError_exports);
24
+ var import_graphql_yoga = require("graphql-yoga");
25
+ var import_api = require("@cedarjs/api");
26
+ const useRedwoodError = (logger) => {
27
+ return {
28
+ async onExecute() {
29
+ return {
30
+ onExecuteDone(payload) {
31
+ return (0, import_graphql_yoga.handleStreamOrSingleExecutionResult)(
32
+ payload,
33
+ ({ result, setResult }) => {
34
+ const errors = result.errors?.map((error) => {
35
+ if (error.originalError instanceof import_api.RedwoodError) {
36
+ logger.debug(
37
+ { custom: { name: error.originalError.name } },
38
+ "Converting RedwoodError to GraphQLError"
39
+ );
40
+ return (0, import_graphql_yoga.createGraphQLError)(error.message, {
41
+ extensions: error.extensions
42
+ });
43
+ } else {
44
+ return error;
45
+ }
46
+ });
47
+ setResult({
48
+ ...result,
49
+ errors,
50
+ extensions: result.extensions || {}
51
+ });
52
+ }
53
+ );
54
+ }
55
+ };
56
+ }
57
+ };
58
+ };
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ useRedwoodError
62
+ });
@@ -5,5 +5,5 @@ import type { CedarGraphQLContext } from '../types.js';
5
5
  * the CedarJS global context which can be imported with:
6
6
  * `import { context } from '@cedarjs/context'`
7
7
  */
8
- export declare const useCedarGlobalContextSetter: () => Plugin<CedarGraphQLContext>;
9
- //# sourceMappingURL=useCedarGlobalContextSetter.d.ts.map
8
+ export declare const useRedwoodGlobalContextSetter: () => Plugin<CedarGraphQLContext>;
9
+ //# sourceMappingURL=useRedwoodGlobalContextSetter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRedwoodGlobalContextSetter.d.ts","sourceRoot":"","sources":["../../../src/plugins/useRedwoodGlobalContextSetter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAI1C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,QACpC,MAAM,CAAC,mBAAmB,CAM5B,CAAA"}
@@ -0,0 +1,35 @@
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 useRedwoodGlobalContextSetter_exports = {};
20
+ __export(useRedwoodGlobalContextSetter_exports, {
21
+ useRedwoodGlobalContextSetter: () => useRedwoodGlobalContextSetter
22
+ });
23
+ module.exports = __toCommonJS(useRedwoodGlobalContextSetter_exports);
24
+ var import_context = require("@cedarjs/context");
25
+ const useRedwoodGlobalContextSetter = () => ({
26
+ onContextBuilding() {
27
+ return ({ context }) => {
28
+ (0, import_context.setContext)(context);
29
+ };
30
+ }
31
+ });
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ useRedwoodGlobalContextSetter
35
+ });
@@ -110,6 +110,6 @@ export type LoggerConfig = {
110
110
  * @see https://www.envelop.dev/docs/plugins/lifecycle
111
111
  * @returns
112
112
  */
113
- export declare const useCedarLogger: (loggerConfig: LoggerConfig) => Plugin<CedarGraphQLContext>;
113
+ export declare const useRedwoodLogger: (loggerConfig: LoggerConfig) => Plugin<CedarGraphQLContext>;
114
114
  export {};
115
- //# sourceMappingURL=useCedarLogger.d.ts.map
115
+ //# sourceMappingURL=useRedwoodLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRedwoodLogger.d.ts","sourceRoot":"","sources":["../../../src/plugins/useRedwoodLogger.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAI1C,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAGlE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD;;;;;;;;;;;;;GAaG;AACH,KAAK,oBAAoB,GAAG;IAC1B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAC,EAAE,eAAe,GAAG,MAAM,CAAA;IAEhC;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IAEd;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC7B,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,oBAAoB,CAAA;CAC/B,CAAA;AA+DD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAC3B,cAAc,YAAY,KACzB,MAAM,CAAC,mBAAmB,CAgH5B,CAAA"}
@@ -0,0 +1,156 @@
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 useRedwoodLogger_exports = {};
20
+ __export(useRedwoodLogger_exports, {
21
+ useRedwoodLogger: () => useRedwoodLogger
22
+ });
23
+ module.exports = __toCommonJS(useRedwoodLogger_exports);
24
+ var import_graphql = require("graphql");
25
+ var import_graphql_yoga = require("graphql-yoga");
26
+ var import_uuid = require("uuid");
27
+ var import_errors = require("../errors.js");
28
+ const logResult = (loggerConfig, envelopLogger, operationName) => ({ result }) => {
29
+ const includeTracing = loggerConfig?.options?.tracing;
30
+ const includeData = loggerConfig?.options?.data;
31
+ const options = {};
32
+ if (result?.errors && result?.errors.length > 0) {
33
+ result.errors.forEach((error) => {
34
+ if (error.originalError && (error.originalError instanceof import_errors.AuthenticationError || error.originalError instanceof import_errors.ForbiddenError)) {
35
+ envelopLogger.warn(
36
+ error,
37
+ `'${error?.extensions?.code || "authentication"}' error '${error.message}' occurred in ${operationName}`
38
+ );
39
+ } else {
40
+ envelopLogger.error(
41
+ error,
42
+ error?.originalError?.message || error.message || `Error in GraphQL execution: ${operationName}`
43
+ );
44
+ }
45
+ });
46
+ }
47
+ if (result?.data) {
48
+ if (includeData) {
49
+ options["data"] = result.data;
50
+ }
51
+ if (result.extensions?.responseCache) {
52
+ options["responseCache"] = result.extensions?.responseCache;
53
+ }
54
+ if (includeTracing) {
55
+ options["tracing"] = result.extensions?.envelopTracing;
56
+ }
57
+ envelopLogger.debug(
58
+ {
59
+ ...options
60
+ },
61
+ `GraphQL execution completed: ${operationName}`
62
+ );
63
+ }
64
+ };
65
+ const useRedwoodLogger = (loggerConfig) => {
66
+ const logger = loggerConfig.logger;
67
+ const level = loggerConfig.options?.level || logger.level || "warn";
68
+ const childLogger = logger.child({
69
+ name: "graphql-server"
70
+ });
71
+ childLogger.level = level;
72
+ const includeOperationName = loggerConfig?.options?.operationName;
73
+ const includeRequestId = loggerConfig?.options?.requestId;
74
+ const includeUserAgent = loggerConfig?.options?.userAgent;
75
+ const includeQuery = loggerConfig?.options?.query;
76
+ const excludeOperations = loggerConfig.options?.excludeOperations;
77
+ return {
78
+ onPluginInit(context) {
79
+ context.registerContextErrorHandler(({ error }) => {
80
+ if (error) {
81
+ childLogger.error(`Error building context. ${error}`);
82
+ }
83
+ });
84
+ },
85
+ onParse({ params }) {
86
+ const options = params.options;
87
+ const envelopLogger = childLogger.child({
88
+ ...options
89
+ });
90
+ return ({ result }) => {
91
+ if (result instanceof Error) {
92
+ envelopLogger.error(result);
93
+ }
94
+ };
95
+ },
96
+ onValidate({ params }) {
97
+ const options = params.options;
98
+ const envelopLogger = childLogger.child({
99
+ ...options
100
+ });
101
+ return ({ result }) => {
102
+ result.forEach((item) => {
103
+ if (item.message) {
104
+ envelopLogger.error(item.message);
105
+ }
106
+ });
107
+ };
108
+ },
109
+ onExecute({ args }) {
110
+ const options = {};
111
+ const rootOperation = args.document.definitions.find(
112
+ (o) => o.kind === import_graphql.Kind.OPERATION_DEFINITION
113
+ );
114
+ const operationName = args.operationName || rootOperation.name?.value || "Anonymous Operation";
115
+ if (excludeOperations?.includes(operationName)) {
116
+ return;
117
+ }
118
+ if (includeOperationName) {
119
+ options["operationName"] = operationName;
120
+ }
121
+ if (includeQuery) {
122
+ options["query"] = args.variableValues;
123
+ }
124
+ if (includeRequestId) {
125
+ options["requestId"] = // x-request-id is a widely adopted (though informal) HTTP header for
126
+ // distributed tracing. Load balancers, API gateways, and clients set
127
+ // it on each request so that all log lines for a single request can
128
+ // be correlated across services. We check it first so that an
129
+ // externally assigned ID is preserved end-to-end; if it is absent we
130
+ // fall back to the Lambda/API-Gateway request ID, and finally
131
+ // generate a UUID so there is always something to correlate on.
132
+ args.contextValue.request?.headers.get("x-request-id") || args.contextValue.requestContext?.awsRequestId || args.contextValue.event?.requestContext?.requestId || (0, import_uuid.v4)();
133
+ }
134
+ if (includeUserAgent) {
135
+ options["userAgent"] = args.contextValue.request?.headers.get("user-agent") || args.contextValue.event?.headers["user-agent"];
136
+ }
137
+ const envelopLogger = childLogger.child({
138
+ ...options
139
+ });
140
+ envelopLogger.debug(`GraphQL execution started: ${operationName}`);
141
+ const handleResult = logResult(loggerConfig, envelopLogger, operationName);
142
+ return {
143
+ onExecuteDone: (payload) => {
144
+ (0, import_graphql_yoga.handleStreamOrSingleExecutionResult)(payload, ({ result }) => {
145
+ handleResult({ result });
146
+ return void 0;
147
+ });
148
+ }
149
+ };
150
+ }
151
+ };
152
+ };
153
+ // Annotate the CommonJS export names for ESM import in node:
154
+ 0 && (module.exports = {
155
+ useRedwoodLogger
156
+ });
@@ -1,6 +1,6 @@
1
1
  import type { Plugin } from '@envelop/core';
2
2
  import * as opentelemetry from '@opentelemetry/api';
3
- import type { CedarOpenTelemetryConfig } from '../types.js';
3
+ import type { RedwoodOpenTelemetryConfig } from '../types.js';
4
4
  export declare enum AttributeName {
5
5
  EXECUTION_ERROR = "graphql.execute.error",
6
6
  EXECUTION_RESULT = "graphql.execute.result",
@@ -17,6 +17,6 @@ declare const tracingSpanSymbol = "OPEN_TELEMETRY_GRAPHQL";
17
17
  type PluginContext = {
18
18
  [tracingSpanSymbol]: opentelemetry.Span;
19
19
  };
20
- export declare const useCedarOpenTelemetry: (options: CedarOpenTelemetryConfig) => Plugin<PluginContext>;
20
+ export declare const useRedwoodOpenTelemetry: (options: RedwoodOpenTelemetryConfig) => Plugin<PluginContext>;
21
21
  export {};
22
- //# sourceMappingURL=useCedarOpenTelemetry.d.ts.map
22
+ //# sourceMappingURL=useRedwoodOpenTelemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRedwoodOpenTelemetry.d.ts","sourceRoot":"","sources":["../../../src/plugins/useRedwoodOpenTelemetry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAuB,MAAM,eAAe,CAAA;AAKhE,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAGnD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AAE7D,oBAAY,aAAa;IACvB,eAAe,0BAA0B;IACzC,gBAAgB,2BAA2B;IAC3C,kBAAkB,+BAA+B;IACjD,mBAAmB,+BAA+B;IAClD,kBAAkB,8BAA8B;IAChD,oBAAoB,gCAAgC;IACpD,aAAa,0BAA0B;IACvC,wBAAwB,kCAAkC;IAC1D,4BAA4B,6BAA6B;IACzD,mBAAmB,8BAA8B;CAClD;AAGD,QAAA,MAAM,iBAAiB,2BAA2B,CAAA;AAElD,KAAK,aAAa,GAAG;IACnB,CAAC,iBAAiB,CAAC,EAAE,aAAa,CAAC,IAAI,CAAA;CACxC,CAAA;AAED,eAAO,MAAM,uBAAuB,GAClC,SAAS,0BAA0B,KAClC,MAAM,CAAC,aAAa,CAgHtB,CAAA"}
@@ -0,0 +1,156 @@
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 useRedwoodOpenTelemetry_exports = {};
30
+ __export(useRedwoodOpenTelemetry_exports, {
31
+ AttributeName: () => AttributeName,
32
+ useRedwoodOpenTelemetry: () => useRedwoodOpenTelemetry
33
+ });
34
+ module.exports = __toCommonJS(useRedwoodOpenTelemetry_exports);
35
+ var import_core = require("@envelop/core");
36
+ var import_on_resolve = require("@envelop/on-resolve");
37
+ var import_api = require("@opentelemetry/api");
38
+ var opentelemetry = __toESM(require("@opentelemetry/api"), 1);
39
+ var import_graphql = require("graphql");
40
+ var AttributeName = /* @__PURE__ */ ((AttributeName2) => {
41
+ AttributeName2["EXECUTION_ERROR"] = "graphql.execute.error";
42
+ AttributeName2["EXECUTION_RESULT"] = "graphql.execute.result";
43
+ AttributeName2["RESOLVER_EXCEPTION"] = "graphql.resolver.exception";
44
+ AttributeName2["RESOLVER_FIELD_NAME"] = "graphql.resolver.fieldName";
45
+ AttributeName2["RESOLVER_TYPE_NAME"] = "graphql.resolver.typeName";
46
+ AttributeName2["RESOLVER_RESULT_TYPE"] = "graphql.resolver.resultType";
47
+ AttributeName2["RESOLVER_ARGS"] = "graphql.resolver.args";
48
+ AttributeName2["EXECUTION_OPERATION_NAME"] = "graphql.execute.operationName";
49
+ AttributeName2["EXECUTION_OPERATION_DOCUMENT"] = "graphql.execute.document";
50
+ AttributeName2["EXECUTION_VARIABLES"] = "graphql.execute.variables";
51
+ return AttributeName2;
52
+ })(AttributeName || {});
53
+ const tracingSpanSymbol = "OPEN_TELEMETRY_GRAPHQL";
54
+ const useRedwoodOpenTelemetry = (options) => {
55
+ const spanKind = import_api.SpanKind.SERVER;
56
+ const spanAdditionalAttributes = {};
57
+ const tracer = opentelemetry.trace.getTracer("redwoodjs");
58
+ return {
59
+ onPluginInit({ addPlugin }) {
60
+ if (options.resolvers) {
61
+ addPlugin(
62
+ (0, import_on_resolve.useOnResolve)(({ info, context, args }) => {
63
+ if (context && typeof context === "object" && context[tracingSpanSymbol]) {
64
+ const ctx = opentelemetry.trace.setSpan(
65
+ opentelemetry.context.active(),
66
+ context[tracingSpanSymbol]
67
+ );
68
+ const { fieldName, returnType, parentType } = info;
69
+ return tracer.startActiveSpan(
70
+ `${parentType.name}.${fieldName}`,
71
+ {
72
+ attributes: {
73
+ ["graphql.resolver.fieldName" /* RESOLVER_FIELD_NAME */]: fieldName,
74
+ ["graphql.resolver.typeName" /* RESOLVER_TYPE_NAME */]: parentType.toString(),
75
+ ["graphql.resolver.resultType" /* RESOLVER_RESULT_TYPE */]: returnType.toString(),
76
+ ["graphql.resolver.args" /* RESOLVER_ARGS */]: JSON.stringify(args || {})
77
+ }
78
+ },
79
+ ctx,
80
+ (resolverSpan) => {
81
+ resolverSpan.spanContext();
82
+ return ({ result }) => {
83
+ if (result instanceof Error) {
84
+ resolverSpan.recordException({
85
+ name: "graphql.resolver.exception" /* RESOLVER_EXCEPTION */,
86
+ message: JSON.stringify(result)
87
+ });
88
+ }
89
+ resolverSpan.end();
90
+ };
91
+ }
92
+ );
93
+ }
94
+ return () => {
95
+ };
96
+ })
97
+ );
98
+ }
99
+ },
100
+ onExecute({ args, extendContext }) {
101
+ return tracer.startActiveSpan(
102
+ `${args.operationName || "Anonymous Operation"}`,
103
+ {
104
+ kind: spanKind,
105
+ attributes: {
106
+ ...spanAdditionalAttributes,
107
+ ["graphql.execute.operationName" /* EXECUTION_OPERATION_NAME */]: args.operationName ?? void 0,
108
+ ["graphql.execute.document" /* EXECUTION_OPERATION_DOCUMENT */]: (0, import_graphql.print)(args.document),
109
+ ...options.variables ? {
110
+ ["graphql.execute.variables" /* EXECUTION_VARIABLES */]: JSON.stringify(
111
+ args.variableValues ?? {}
112
+ )
113
+ } : {}
114
+ }
115
+ },
116
+ (executionSpan) => {
117
+ const resultCbs = {
118
+ onExecuteDone({ result }) {
119
+ if ((0, import_core.isAsyncIterable)(result)) {
120
+ executionSpan.end();
121
+ console.warn(
122
+ `Plugin "RedwoodOpenTelemetry" encountered an AsyncIterator which is not supported yet, so tracing data is not available for the operation.`
123
+ );
124
+ return;
125
+ }
126
+ if (result.data && options.result) {
127
+ executionSpan.setAttribute(
128
+ "graphql.execute.result" /* EXECUTION_RESULT */,
129
+ JSON.stringify(result)
130
+ );
131
+ }
132
+ if (result.errors && result.errors.length > 0) {
133
+ executionSpan.recordException({
134
+ name: "graphql.execute.error" /* EXECUTION_ERROR */,
135
+ message: JSON.stringify(result.errors)
136
+ });
137
+ }
138
+ executionSpan.end();
139
+ }
140
+ };
141
+ if (options.resolvers) {
142
+ extendContext({
143
+ [tracingSpanSymbol]: executionSpan
144
+ });
145
+ }
146
+ return resultCbs;
147
+ }
148
+ );
149
+ }
150
+ };
151
+ };
152
+ // Annotate the CommonJS export names for ESM import in node:
153
+ 0 && (module.exports = {
154
+ AttributeName,
155
+ useRedwoodOpenTelemetry
156
+ });
@@ -5,5 +5,5 @@ import type { CedarGraphQLContext, GraphQLHandlerOptions } from '../types.js';
5
5
  * by populating it with the results of a custom function
6
6
  * @returns
7
7
  */
8
- export declare const useCedarPopulateContext: (populateContextBuilder: NonNullable<GraphQLHandlerOptions["context"]>) => Plugin<CedarGraphQLContext>;
9
- //# sourceMappingURL=useCedarPopulateContext.d.ts.map
8
+ export declare const useRedwoodPopulateContext: (populateContextBuilder: NonNullable<GraphQLHandlerOptions["context"]>) => Plugin<CedarGraphQLContext>;
9
+ //# sourceMappingURL=useRedwoodPopulateContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRedwoodPopulateContext.d.ts","sourceRoot":"","sources":["../../../src/plugins/useRedwoodPopulateContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAE7E;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GACpC,wBAAwB,WAAW,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,KACpE,MAAM,CAAC,mBAAmB,CAW5B,CAAA"}