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

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,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 = 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
+ });
@@ -0,0 +1,20 @@
1
+ import type { Plugin } from 'graphql-yoga';
2
+ import type { Logger } from '@cedarjs/api/logger';
3
+ import type { RedwoodGraphQLContext } from '../types.js';
4
+ /**
5
+ * Converts RedwoodErrors to GraphQLErrors
6
+ *
7
+ * This is a workaround for the fact that graphql-yoga doesn't support custom error types.
8
+ *
9
+ * Yoga automatically masks unexpected errors and prevents leaking sensitive information to clients.
10
+ *
11
+ * Since RedwoodErrors (such as ServiceValidation errors) are expected,
12
+ * we need to convert them to GraphQLErrors so that they are not masked.
13
+ *
14
+ * See: https://the-guild.dev/graphql/yoga-server/docs/features/error-masking
15
+ *
16
+ * @param logger
17
+ * @returns ExecutionResult
18
+ */
19
+ export declare const useRedwoodError: (logger: Logger) => Plugin<RedwoodGraphQLContext>;
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,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,eAAe,WAClB,MAAM,KACb,MAAM,CAAC,qBAAqB,CAyC9B,CAAA"}
@@ -0,0 +1,63 @@
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 && 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
+ originalError: error
43
+ });
44
+ } else {
45
+ return error;
46
+ }
47
+ });
48
+ setResult({
49
+ ...result,
50
+ errors,
51
+ extensions: result.extensions || {}
52
+ });
53
+ }
54
+ );
55
+ }
56
+ };
57
+ }
58
+ };
59
+ };
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ useRedwoodError
63
+ });
@@ -0,0 +1,9 @@
1
+ import type { Plugin } from 'graphql-yoga';
2
+ import type { RedwoodGraphQLContext } from '../types.js';
3
+ /**
4
+ * This Envelop plugin waits until the GraphQL context is done building and sets
5
+ * the CedarJS global context which can be imported with:
6
+ * `import { context } from '@cedarjs/context'`
7
+ */
8
+ export declare const useRedwoodGlobalContextSetter: () => Plugin<RedwoodGraphQLContext>;
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,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,QACpC,MAAM,CAAC,qBAAqB,CAM9B,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
+ });
@@ -0,0 +1,115 @@
1
+ import type { Plugin } from 'graphql-yoga';
2
+ import type { Logger, LevelWithSilent } from '@cedarjs/api/logger';
3
+ import type { RedwoodGraphQLContext } from '../types.js';
4
+ /**
5
+ * Options for request and response information to include in the log statements
6
+ * output by UseRedwoodLogger around the execution event
7
+ *
8
+ * @param level - Sets log level specific to GraphQL log output. Defaults to current logger level.
9
+ * @param data - Include response data sent to client.
10
+ * @param operationName - Include operation name.
11
+ * @param requestId - Include the event's requestId, or if none, generate a uuid as an identifier.
12
+ * @param query - Include the query. This is the query or mutation (with fields) made in the request.
13
+ * @param tracing - Include the tracing and timing information.
14
+ * @param userAgent - Include the browser (or client's) user agent.
15
+ * @param excludeOperations - Exclude the specified operations from being logged.
16
+ *
17
+ */
18
+ type GraphQLLoggerOptions = {
19
+ /**
20
+ * Sets log level for GraphQL logging.
21
+ * This level setting can be different from the one used in api side logging.
22
+ * Defaults to the same level as the logger unless set here.
23
+ *
24
+ * Available log levels:
25
+ *
26
+ * - 'fatal'
27
+ * - 'error'
28
+ * - 'warn'
29
+ * - 'info'
30
+ * - 'debug'
31
+ * - 'trace'
32
+ * - 'silent'
33
+ *
34
+ * The logging level is a __minimum__ level. For instance if `logger.level` is `'info'` then all `'fatal'`, `'error'`, `'warn'`,
35
+ * and `'info'` logs will be enabled.
36
+ *
37
+ * You can pass `'silent'` to disable logging.
38
+ *
39
+ * @default level of the logger set in LoggerConfig
40
+ *
41
+ */
42
+ level?: LevelWithSilent | string;
43
+ /**
44
+ * @description Include response data sent to client.
45
+ */
46
+ data?: boolean;
47
+ /**
48
+ * @description Include operation name.
49
+ *
50
+ * The operation name is a meaningful and explicit name for your operation. It is only required in multi-operation documents,
51
+ * but its use is encouraged because it is very helpful for debugging and server-side logging.
52
+ * When something goes wrong (you see errors either in your network logs, or in the logs of your GraphQL server)
53
+ * it is easier to identify a query in your codebase by name instead of trying to decipher the contents.
54
+ * Think of this just like a function name in your favorite programming language.
55
+ *
56
+ * @see https://graphql.org/learn/queries/#operation-name
57
+ */
58
+ operationName?: boolean;
59
+ /**
60
+ * @description Include the event's requestId, or if none, generate a uuid as an identifier.
61
+ *
62
+ * The requestId can be helpful when contacting your deployment provider to resolve issues when encountering errors or unexpected behavior.
63
+ */
64
+ requestId?: boolean;
65
+ /**
66
+ * @description Include the query. This is the query or mutation (with fields) made in the request.
67
+ */
68
+ query?: boolean;
69
+ /**
70
+ * @description Include the tracing and timing information.
71
+ *
72
+ * This will log various performance timings within the GraphQL event lifecycle (parsing, validating, executing, etc).
73
+ */
74
+ tracing?: boolean;
75
+ /**
76
+ * @description Include the browser (or client's) user agent.
77
+ *
78
+ * This can be helpful to know what type of client made the request to resolve issues when encountering errors or unexpected behavior.
79
+ */
80
+ userAgent?: boolean;
81
+ /**
82
+ * @description Exclude operation from the log output.
83
+ *
84
+ * This is useful when you want to filter out certain operations from the log output.
85
+ * For example `IntrospectionQuery` from GraphQL playground.
86
+ */
87
+ excludeOperations?: string[];
88
+ };
89
+ /**
90
+ * Configure the logger used by the GraphQL server.
91
+ *
92
+ * @param logger your logger
93
+ * @param options the GraphQLLoggerOptions such as tracing, operationName, etc
94
+ */
95
+ export type LoggerConfig = {
96
+ logger: Logger;
97
+ options?: GraphQLLoggerOptions;
98
+ };
99
+ /**
100
+ * This plugin logs every time an operation is being executed and
101
+ * when the execution of the operation is done.
102
+ *
103
+ * It adds information using a child logger from the context
104
+ * such as the operation name, request id, errors, and header info
105
+ * to help trace and diagnose issues.
106
+ *
107
+ * Tracing and timing information can be enabled via the
108
+ * GraphQLHandlerOptions traction option.
109
+ *
110
+ * @see https://www.envelop.dev/docs/plugins/lifecycle
111
+ * @returns
112
+ */
113
+ export declare const useRedwoodLogger: (loggerConfig: LoggerConfig) => Plugin<RedwoodGraphQLContext>;
114
+ export {};
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,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD;;;;;;;;;;;;;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,iBACb,YAAY,KACzB,MAAM,CAAC,qBAAqB,CAsG9B,CAAA"}
@@ -0,0 +1,149 @@
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"] = args.contextValue.requestContext?.awsRequestId || args.contextValue.event?.requestContext?.requestId || (0, import_uuid.v4)();
126
+ }
127
+ if (includeUserAgent) {
128
+ options["userAgent"] = args.contextValue.event?.headers["user-agent"];
129
+ }
130
+ const envelopLogger = childLogger.child({
131
+ ...options
132
+ });
133
+ envelopLogger.debug(`GraphQL execution started: ${operationName}`);
134
+ const handleResult = logResult(loggerConfig, envelopLogger, operationName);
135
+ return {
136
+ onExecuteDone: (payload) => {
137
+ (0, import_graphql_yoga.handleStreamOrSingleExecutionResult)(payload, ({ result }) => {
138
+ handleResult({ result });
139
+ return void 0;
140
+ });
141
+ }
142
+ };
143
+ }
144
+ };
145
+ };
146
+ // Annotate the CommonJS export names for ESM import in node:
147
+ 0 && (module.exports = {
148
+ useRedwoodLogger
149
+ });
@@ -0,0 +1,22 @@
1
+ import type { Plugin } from '@envelop/core';
2
+ import * as opentelemetry from '@opentelemetry/api';
3
+ import type { RedwoodOpenTelemetryConfig } from '../types.js';
4
+ export declare enum AttributeName {
5
+ EXECUTION_ERROR = "graphql.execute.error",
6
+ EXECUTION_RESULT = "graphql.execute.result",
7
+ RESOLVER_EXCEPTION = "graphql.resolver.exception",
8
+ RESOLVER_FIELD_NAME = "graphql.resolver.fieldName",
9
+ RESOLVER_TYPE_NAME = "graphql.resolver.typeName",
10
+ RESOLVER_RESULT_TYPE = "graphql.resolver.resultType",
11
+ RESOLVER_ARGS = "graphql.resolver.args",
12
+ EXECUTION_OPERATION_NAME = "graphql.execute.operationName",
13
+ EXECUTION_OPERATION_DOCUMENT = "graphql.execute.document",
14
+ EXECUTION_VARIABLES = "graphql.execute.variables"
15
+ }
16
+ declare const tracingSpanSymbol = "OPEN_TELEMETRY_GRAPHQL";
17
+ type PluginContext = {
18
+ [tracingSpanSymbol]: opentelemetry.Span;
19
+ };
20
+ export declare const useRedwoodOpenTelemetry: (options: RedwoodOpenTelemetryConfig) => Plugin<PluginContext>;
21
+ export {};
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,YACzB,0BAA0B,KAClC,MAAM,CAAC,aAAa,CAgHtB,CAAA"}