@leaven-graphql/plugins 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Pegasus Heavy Industries LLC
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,244 @@
1
+ # @leaven-graphql/plugins
2
+
3
+ Plugin system for extending Leaven with caching, logging, tracing, and more.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @leaven-graphql/plugins
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { createLoggingPlugin, createDepthLimitPlugin } from '@leaven-graphql/plugins';
15
+ import { LeavenExecutor } from '@leaven-graphql/core';
16
+
17
+ const executor = new LeavenExecutor({
18
+ schema,
19
+ plugins: [
20
+ createLoggingPlugin({ logger: console }),
21
+ createDepthLimitPlugin({ maxDepth: 10 }),
22
+ ],
23
+ });
24
+ ```
25
+
26
+ ## Built-in Plugins
27
+
28
+ ### Logging Plugin
29
+
30
+ ```typescript
31
+ import { createLoggingPlugin } from '@leaven-graphql/plugins';
32
+
33
+ const loggingPlugin = createLoggingPlugin({
34
+ logger: console,
35
+ logLevel: 'info',
36
+ includeVariables: false,
37
+ includeResult: false,
38
+ });
39
+
40
+ // Output:
41
+ // [GraphQL] Query getUser started
42
+ // [GraphQL] Query getUser completed in 15ms
43
+ ```
44
+
45
+ ### Tracing Plugin
46
+
47
+ ```typescript
48
+ import { createTracingPlugin } from '@leaven-graphql/plugins';
49
+
50
+ const tracingPlugin = createTracingPlugin({
51
+ includeResolvers: true,
52
+ includeValidation: true,
53
+ });
54
+
55
+ // Adds tracing to response extensions:
56
+ // {
57
+ // extensions: {
58
+ // tracing: {
59
+ // version: 1,
60
+ // startTime: "2026-01-01T12:00:00.000Z",
61
+ // duration: 15000000,
62
+ // execution: { ... }
63
+ // }
64
+ // }
65
+ // }
66
+ ```
67
+
68
+ ### Depth Limit Plugin
69
+
70
+ ```typescript
71
+ import { createDepthLimitPlugin } from '@leaven-graphql/plugins';
72
+
73
+ const depthLimitPlugin = createDepthLimitPlugin({
74
+ maxDepth: 10,
75
+ ignoreIntrospection: true,
76
+ });
77
+
78
+ // Rejects queries that are too deeply nested
79
+ ```
80
+
81
+ ### Complexity Plugin
82
+
83
+ ```typescript
84
+ import { createComplexityPlugin } from '@leaven-graphql/plugins';
85
+
86
+ const complexityPlugin = createComplexityPlugin({
87
+ maxComplexity: 1000,
88
+ defaultFieldComplexity: 1,
89
+ scalarCost: 0,
90
+ objectCost: 1,
91
+ listFactor: 10,
92
+ });
93
+
94
+ // Calculates and enforces query complexity
95
+ ```
96
+
97
+ ### Caching Plugin
98
+
99
+ ```typescript
100
+ import { createCachingPlugin } from '@leaven-graphql/plugins';
101
+
102
+ const cachingPlugin = createCachingPlugin({
103
+ ttl: 60000, // Cache TTL in ms
104
+ maxSize: 100, // Max cached responses
105
+ keyGenerator: (request) => {
106
+ return `${request.query}:${JSON.stringify(request.variables)}`;
107
+ },
108
+ });
109
+ ```
110
+
111
+ ## Creating Custom Plugins
112
+
113
+ ```typescript
114
+ import { createPlugin } from '@leaven-graphql/plugins';
115
+
116
+ const metricsPlugin = createPlugin({
117
+ name: 'metrics',
118
+ version: '1.0.0',
119
+
120
+ beforeParse: (query, context) => {
121
+ context.startTime = performance.now();
122
+ return query;
123
+ },
124
+
125
+ afterExecute: (result, context) => {
126
+ const duration = performance.now() - context.startTime;
127
+
128
+ metrics.record({
129
+ operation: context.operationName,
130
+ duration,
131
+ errors: result.errors?.length ?? 0,
132
+ });
133
+
134
+ return result;
135
+ },
136
+
137
+ onError: (error, context) => {
138
+ metrics.recordError({
139
+ operation: context.operationName,
140
+ error: error.message,
141
+ });
142
+ },
143
+ });
144
+ ```
145
+
146
+ ## Plugin Manager
147
+
148
+ ```typescript
149
+ import { PluginManager, createPluginManager } from '@leaven-graphql/plugins';
150
+
151
+ const manager = createPluginManager({
152
+ schema,
153
+ plugins: [
154
+ createLoggingPlugin({ logger: console }),
155
+ createTracingPlugin(),
156
+ createDepthLimitPlugin({ maxDepth: 10 }),
157
+ ],
158
+ });
159
+
160
+ // Register additional plugins
161
+ manager.register(myCustomPlugin);
162
+
163
+ // Unregister plugins
164
+ manager.unregister('logging');
165
+
166
+ // Get registered plugin names
167
+ const plugins = manager.getPluginNames();
168
+ ```
169
+
170
+ ## Composing Plugins
171
+
172
+ ```typescript
173
+ import { composePlugins } from '@leaven-graphql/plugins';
174
+
175
+ const combinedPlugin = composePlugins([
176
+ createLoggingPlugin({ logger: console }),
177
+ createTracingPlugin(),
178
+ createDepthLimitPlugin({ maxDepth: 10 }),
179
+ createComplexityPlugin({ maxComplexity: 500 }),
180
+ ]);
181
+
182
+ const executor = new LeavenExecutor({
183
+ schema,
184
+ plugins: [combinedPlugin],
185
+ });
186
+ ```
187
+
188
+ ## Plugin Hooks
189
+
190
+ | Hook | Description |
191
+ |------|-------------|
192
+ | `beforeParse` | Called before parsing the query string |
193
+ | `afterParse` | Called after parsing, receives DocumentNode |
194
+ | `beforeValidate` | Called before schema validation |
195
+ | `afterValidate` | Called after validation with results |
196
+ | `beforeExecute` | Called before resolver execution |
197
+ | `afterExecute` | Called after execution with results |
198
+ | `onError` | Called when an error occurs |
199
+
200
+ ## API Reference
201
+
202
+ ### Plugin Interface
203
+
204
+ ```typescript
205
+ interface Plugin {
206
+ name: string;
207
+ version?: string;
208
+
209
+ beforeParse?(query: string, context: PluginContext): string | void;
210
+ afterParse?(document: DocumentNode, context: PluginContext): DocumentNode | void;
211
+ beforeValidate?(document: DocumentNode, context: PluginContext): void;
212
+ afterValidate?(result: ValidationResult, context: PluginContext): void;
213
+ beforeExecute?(context: PluginContext): void | Promise<void>;
214
+ afterExecute?(result: ExecutionResult, context: PluginContext): ExecutionResult | void;
215
+ onError?(error: Error, context: PluginContext): void;
216
+ }
217
+ ```
218
+
219
+ ### createPlugin
220
+
221
+ ```typescript
222
+ function createPlugin(config: Plugin): Plugin;
223
+ ```
224
+
225
+ ### composePlugins
226
+
227
+ ```typescript
228
+ function composePlugins(plugins: Plugin[]): Plugin;
229
+ ```
230
+
231
+ ### PluginManager
232
+
233
+ ```typescript
234
+ class PluginManager {
235
+ register(plugin: Plugin): void;
236
+ unregister(name: string): void;
237
+ getPluginNames(): string[];
238
+ execute<T>(hookName: string, ...args: unknown[]): T;
239
+ }
240
+ ```
241
+
242
+ ## License
243
+
244
+ Apache 2.0 - Pegasus Heavy Industries LLC
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @leaven-graphql/plugins - Built-in plugins
3
+ *
4
+ * Copyright 2026 Pegasus Heavy Industries LLC
5
+ * Licensed under the Apache License, Version 2.0
6
+ */
7
+ import type { Plugin, PluginHooks, PluginMetadata } from './types';
8
+ /**
9
+ * Create a custom plugin
10
+ */
11
+ export declare function createPlugin(metadata: PluginMetadata, hooks: PluginHooks): Plugin;
12
+ /**
13
+ * Compose multiple plugins into one
14
+ */
15
+ export declare function composePlugins(name: string, ...plugins: Plugin[]): Plugin;
16
+ /**
17
+ * Create a caching plugin
18
+ */
19
+ export declare function createCachingPlugin(options?: {
20
+ /** Maximum cache size */
21
+ maxSize?: number;
22
+ /** Cache TTL in milliseconds */
23
+ ttl?: number;
24
+ }): Plugin;
25
+ /**
26
+ * Create a logging plugin
27
+ */
28
+ export declare function createLoggingPlugin(options?: {
29
+ /** Log level */
30
+ level?: 'debug' | 'info' | 'warn' | 'error';
31
+ /** Custom logger */
32
+ logger?: {
33
+ debug: (msg: string, data?: unknown) => void;
34
+ info: (msg: string, data?: unknown) => void;
35
+ warn: (msg: string, data?: unknown) => void;
36
+ error: (msg: string, data?: unknown) => void;
37
+ };
38
+ }): Plugin;
39
+ /**
40
+ * Create a tracing plugin
41
+ */
42
+ export declare function createTracingPlugin(): Plugin;
43
+ /**
44
+ * Create a depth limit plugin
45
+ */
46
+ export declare function createDepthLimitPlugin(maxDepth: number): Plugin;
47
+ /**
48
+ * Create a complexity plugin
49
+ */
50
+ export declare function createComplexityPlugin(options: {
51
+ /** Maximum allowed complexity */
52
+ maxComplexity: number;
53
+ /** Default field complexity */
54
+ defaultComplexity?: number;
55
+ /** Custom complexity calculator */
56
+ calculator?: (node: unknown, childComplexity: number) => number;
57
+ }): Plugin;
58
+ //# sourceMappingURL=builtin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":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,QAAQ,EAAE,MAAM,GAAG,MAAM,CAuD/D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,iCAAiC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mCAAmC;IACnC,UAAU,CAAC,EAAE,CACX,IAAI,EAAE,OAAO,EACb,eAAe,EAAE,MAAM,KACpB,MAAM,CAAC;CACb,GAAG,MAAM,CA0ET"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @leaven-graphql/plugins - Plugin system for Leaven
3
+ *
4
+ * Copyright 2026 Pegasus Heavy Industries LLC
5
+ * Licensed under the Apache License, Version 2.0
6
+ */
7
+ export { PluginManager, createPluginManager } from './manager';
8
+ export type { PluginManagerConfig } from './manager';
9
+ export type { Plugin, PluginContext, PluginHooks, PluginMetadata, BeforeParseHook, AfterParseHook, BeforeValidateHook, AfterValidateHook, BeforeExecuteHook, AfterExecuteHook, OnErrorHook, } from './types';
10
+ export { createPlugin, composePlugins, createCachingPlugin, createLoggingPlugin, createTracingPlugin, createDepthLimitPlugin, createComplexityPlugin, } from './builtin';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAC/D,YAAY,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAErD,YAAY,EACV,MAAM,EACN,aAAa,EACb,WAAW,EACX,cAAc,EACd,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,GACZ,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,531 @@
1
+ // @bun
2
+ // src/manager.ts
3
+ class PluginManager {
4
+ schema;
5
+ plugins;
6
+ pluginOrder;
7
+ constructor(config) {
8
+ this.schema = config.schema;
9
+ this.plugins = new Map;
10
+ this.pluginOrder = [];
11
+ if (config.plugins) {
12
+ for (const plugin of config.plugins) {
13
+ this.register(plugin);
14
+ }
15
+ }
16
+ }
17
+ async register(plugin) {
18
+ const { name } = plugin.metadata;
19
+ if (this.plugins.has(name)) {
20
+ throw new Error(`Plugin "${name}" is already registered`);
21
+ }
22
+ if (plugin.metadata.dependencies) {
23
+ for (const dep of plugin.metadata.dependencies) {
24
+ if (!this.plugins.has(dep)) {
25
+ throw new Error(`Plugin "${name}" depends on "${dep}" which is not registered`);
26
+ }
27
+ }
28
+ }
29
+ this.plugins.set(name, plugin);
30
+ this.pluginOrder.push(name);
31
+ await plugin.onRegister?.(this.schema);
32
+ }
33
+ async unregister(name) {
34
+ const plugin = this.plugins.get(name);
35
+ if (!plugin) {
36
+ return false;
37
+ }
38
+ for (const [otherName, otherPlugin] of this.plugins) {
39
+ if (otherPlugin.metadata.dependencies?.includes(name) && otherName !== name) {
40
+ throw new Error(`Cannot unregister "${name}": "${otherName}" depends on it`);
41
+ }
42
+ }
43
+ await plugin.onUnregister?.();
44
+ this.plugins.delete(name);
45
+ const index = this.pluginOrder.indexOf(name);
46
+ if (index !== -1) {
47
+ this.pluginOrder.splice(index, 1);
48
+ }
49
+ return true;
50
+ }
51
+ get(name) {
52
+ return this.plugins.get(name);
53
+ }
54
+ has(name) {
55
+ return this.plugins.has(name);
56
+ }
57
+ getPluginNames() {
58
+ return [...this.pluginOrder];
59
+ }
60
+ createContext(request, userContext) {
61
+ return {
62
+ schema: this.schema,
63
+ request,
64
+ context: userContext,
65
+ state: new Map
66
+ };
67
+ }
68
+ async beforeParse(query, context) {
69
+ let result = query;
70
+ for (const name of this.pluginOrder) {
71
+ const plugin = this.plugins.get(name);
72
+ if (plugin.beforeParse) {
73
+ const modified = await plugin.beforeParse(result, context);
74
+ if (typeof modified === "string") {
75
+ result = modified;
76
+ }
77
+ }
78
+ }
79
+ return result;
80
+ }
81
+ async afterParse(document, context) {
82
+ let result = document;
83
+ for (const name of this.pluginOrder) {
84
+ const plugin = this.plugins.get(name);
85
+ if (plugin.afterParse) {
86
+ const modified = await plugin.afterParse(result, context);
87
+ if (modified) {
88
+ result = modified;
89
+ }
90
+ }
91
+ }
92
+ return result;
93
+ }
94
+ async beforeValidate(document, context) {
95
+ for (const name of this.pluginOrder) {
96
+ const plugin = this.plugins.get(name);
97
+ if (plugin.beforeValidate) {
98
+ await plugin.beforeValidate(document, context);
99
+ }
100
+ }
101
+ }
102
+ async afterValidate(result, context) {
103
+ for (const name of this.pluginOrder) {
104
+ const plugin = this.plugins.get(name);
105
+ if (plugin.afterValidate) {
106
+ await plugin.afterValidate(result, context);
107
+ }
108
+ }
109
+ }
110
+ async beforeExecute(document, context) {
111
+ for (const name of this.pluginOrder) {
112
+ const plugin = this.plugins.get(name);
113
+ if (plugin.beforeExecute) {
114
+ await plugin.beforeExecute(document, context);
115
+ }
116
+ }
117
+ }
118
+ async afterExecute(response, context) {
119
+ let result = response;
120
+ for (let i = this.pluginOrder.length - 1;i >= 0; i--) {
121
+ const name = this.pluginOrder[i];
122
+ const plugin = this.plugins.get(name);
123
+ if (plugin.afterExecute) {
124
+ const modified = await plugin.afterExecute(result, context);
125
+ if (modified) {
126
+ result = modified;
127
+ }
128
+ }
129
+ }
130
+ return result;
131
+ }
132
+ async onError(error, context) {
133
+ let result = error;
134
+ for (const name of this.pluginOrder) {
135
+ const plugin = this.plugins.get(name);
136
+ if (plugin.onError) {
137
+ const modified = await plugin.onError(result, context);
138
+ if (modified instanceof Error) {
139
+ result = modified;
140
+ }
141
+ }
142
+ }
143
+ return result;
144
+ }
145
+ get size() {
146
+ return this.plugins.size;
147
+ }
148
+ async clear() {
149
+ for (let i = this.pluginOrder.length - 1;i >= 0; i--) {
150
+ await this.unregister(this.pluginOrder[i]);
151
+ }
152
+ }
153
+ }
154
+ function createPluginManager(config) {
155
+ return new PluginManager(config);
156
+ }
157
+ // ../../node_modules/.pnpm/graphql@16.12.0/node_modules/graphql/language/kinds.mjs
158
+ var Kind;
159
+ (function(Kind2) {
160
+ Kind2["NAME"] = "Name";
161
+ Kind2["DOCUMENT"] = "Document";
162
+ Kind2["OPERATION_DEFINITION"] = "OperationDefinition";
163
+ Kind2["VARIABLE_DEFINITION"] = "VariableDefinition";
164
+ Kind2["SELECTION_SET"] = "SelectionSet";
165
+ Kind2["FIELD"] = "Field";
166
+ Kind2["ARGUMENT"] = "Argument";
167
+ Kind2["FRAGMENT_SPREAD"] = "FragmentSpread";
168
+ Kind2["INLINE_FRAGMENT"] = "InlineFragment";
169
+ Kind2["FRAGMENT_DEFINITION"] = "FragmentDefinition";
170
+ Kind2["VARIABLE"] = "Variable";
171
+ Kind2["INT"] = "IntValue";
172
+ Kind2["FLOAT"] = "FloatValue";
173
+ Kind2["STRING"] = "StringValue";
174
+ Kind2["BOOLEAN"] = "BooleanValue";
175
+ Kind2["NULL"] = "NullValue";
176
+ Kind2["ENUM"] = "EnumValue";
177
+ Kind2["LIST"] = "ListValue";
178
+ Kind2["OBJECT"] = "ObjectValue";
179
+ Kind2["OBJECT_FIELD"] = "ObjectField";
180
+ Kind2["DIRECTIVE"] = "Directive";
181
+ Kind2["NAMED_TYPE"] = "NamedType";
182
+ Kind2["LIST_TYPE"] = "ListType";
183
+ Kind2["NON_NULL_TYPE"] = "NonNullType";
184
+ Kind2["SCHEMA_DEFINITION"] = "SchemaDefinition";
185
+ Kind2["OPERATION_TYPE_DEFINITION"] = "OperationTypeDefinition";
186
+ Kind2["SCALAR_TYPE_DEFINITION"] = "ScalarTypeDefinition";
187
+ Kind2["OBJECT_TYPE_DEFINITION"] = "ObjectTypeDefinition";
188
+ Kind2["FIELD_DEFINITION"] = "FieldDefinition";
189
+ Kind2["INPUT_VALUE_DEFINITION"] = "InputValueDefinition";
190
+ Kind2["INTERFACE_TYPE_DEFINITION"] = "InterfaceTypeDefinition";
191
+ Kind2["UNION_TYPE_DEFINITION"] = "UnionTypeDefinition";
192
+ Kind2["ENUM_TYPE_DEFINITION"] = "EnumTypeDefinition";
193
+ Kind2["ENUM_VALUE_DEFINITION"] = "EnumValueDefinition";
194
+ Kind2["INPUT_OBJECT_TYPE_DEFINITION"] = "InputObjectTypeDefinition";
195
+ Kind2["DIRECTIVE_DEFINITION"] = "DirectiveDefinition";
196
+ Kind2["SCHEMA_EXTENSION"] = "SchemaExtension";
197
+ Kind2["SCALAR_TYPE_EXTENSION"] = "ScalarTypeExtension";
198
+ Kind2["OBJECT_TYPE_EXTENSION"] = "ObjectTypeExtension";
199
+ Kind2["INTERFACE_TYPE_EXTENSION"] = "InterfaceTypeExtension";
200
+ Kind2["UNION_TYPE_EXTENSION"] = "UnionTypeExtension";
201
+ Kind2["ENUM_TYPE_EXTENSION"] = "EnumTypeExtension";
202
+ Kind2["INPUT_OBJECT_TYPE_EXTENSION"] = "InputObjectTypeExtension";
203
+ Kind2["TYPE_COORDINATE"] = "TypeCoordinate";
204
+ Kind2["MEMBER_COORDINATE"] = "MemberCoordinate";
205
+ Kind2["ARGUMENT_COORDINATE"] = "ArgumentCoordinate";
206
+ Kind2["DIRECTIVE_COORDINATE"] = "DirectiveCoordinate";
207
+ Kind2["DIRECTIVE_ARGUMENT_COORDINATE"] = "DirectiveArgumentCoordinate";
208
+ })(Kind || (Kind = {}));
209
+ // src/builtin.ts
210
+ function createPlugin(metadata, hooks) {
211
+ return {
212
+ metadata,
213
+ ...hooks
214
+ };
215
+ }
216
+ function composePlugins(name, ...plugins) {
217
+ return {
218
+ metadata: {
219
+ name,
220
+ description: `Composed plugin from: ${plugins.map((p) => p.metadata.name).join(", ")}`
221
+ },
222
+ async onRegister(schema) {
223
+ for (const plugin of plugins) {
224
+ await plugin.onRegister?.(schema);
225
+ }
226
+ },
227
+ async onUnregister() {
228
+ for (const plugin of plugins) {
229
+ await plugin.onUnregister?.();
230
+ }
231
+ },
232
+ async beforeParse(query, context) {
233
+ let result = query;
234
+ for (const plugin of plugins) {
235
+ if (plugin.beforeParse) {
236
+ const modified = await plugin.beforeParse(result, context);
237
+ if (typeof modified === "string") {
238
+ result = modified;
239
+ }
240
+ }
241
+ }
242
+ return result;
243
+ },
244
+ async afterParse(document, context) {
245
+ let result = document;
246
+ for (const plugin of plugins) {
247
+ if (plugin.afterParse) {
248
+ const modified = await plugin.afterParse(result, context);
249
+ if (modified) {
250
+ result = modified;
251
+ }
252
+ }
253
+ }
254
+ return result;
255
+ },
256
+ async beforeExecute(document, context) {
257
+ for (const plugin of plugins) {
258
+ await plugin.beforeExecute?.(document, context);
259
+ }
260
+ },
261
+ async afterExecute(response, context) {
262
+ let result = response;
263
+ for (const plugin of plugins.slice().reverse()) {
264
+ if (plugin.afterExecute) {
265
+ const modified = await plugin.afterExecute(result, context);
266
+ if (modified) {
267
+ result = modified;
268
+ }
269
+ }
270
+ }
271
+ return result;
272
+ },
273
+ async onError(error, context) {
274
+ let result = error;
275
+ for (const plugin of plugins) {
276
+ if (plugin.onError) {
277
+ const modified = await plugin.onError(result, context);
278
+ if (modified instanceof Error) {
279
+ result = modified;
280
+ }
281
+ }
282
+ }
283
+ return result;
284
+ }
285
+ };
286
+ }
287
+ function createCachingPlugin(options) {
288
+ const cache = new Map;
289
+ const maxSize = options?.maxSize ?? 100;
290
+ const ttl = options?.ttl ?? 60000;
291
+ return {
292
+ metadata: {
293
+ name: "caching",
294
+ version: "1.0.0",
295
+ description: "Caches query results"
296
+ },
297
+ async beforeExecute(document, context) {
298
+ const key = JSON.stringify({
299
+ query: context.request.query,
300
+ variables: context.request.variables
301
+ });
302
+ const cached = cache.get(key);
303
+ if (cached && cached.expires > Date.now()) {
304
+ context.state.set("cacheHit", true);
305
+ context.state.set("cachedResponse", cached.data);
306
+ }
307
+ },
308
+ async afterExecute(response, context) {
309
+ if (context.state.get("cacheHit")) {
310
+ return context.state.get("cachedResponse");
311
+ }
312
+ if (response.errors && response.errors.length > 0) {
313
+ return response;
314
+ }
315
+ const key = JSON.stringify({
316
+ query: context.request.query,
317
+ variables: context.request.variables
318
+ });
319
+ if (cache.size >= maxSize) {
320
+ const firstKey = cache.keys().next().value;
321
+ if (firstKey)
322
+ cache.delete(firstKey);
323
+ }
324
+ cache.set(key, {
325
+ data: response,
326
+ expires: Date.now() + ttl
327
+ });
328
+ return response;
329
+ }
330
+ };
331
+ }
332
+ function createLoggingPlugin(options) {
333
+ const logger = options?.logger ?? console;
334
+ const level = options?.level ?? "info";
335
+ const shouldLog = (msgLevel) => {
336
+ const levels = ["debug", "info", "warn", "error"];
337
+ return levels.indexOf(msgLevel) >= levels.indexOf(level);
338
+ };
339
+ return {
340
+ metadata: {
341
+ name: "logging",
342
+ version: "1.0.0",
343
+ description: "Logs GraphQL operations"
344
+ },
345
+ async beforeExecute(document, context) {
346
+ context.state.set("startTime", performance.now());
347
+ if (shouldLog("debug")) {
348
+ logger.debug("Executing GraphQL operation", {
349
+ operationName: context.request.operationName,
350
+ query: context.request.query
351
+ });
352
+ }
353
+ },
354
+ async afterExecute(response, context) {
355
+ const startTime = context.state.get("startTime");
356
+ const duration = performance.now() - startTime;
357
+ if (response.errors && response.errors.length > 0) {
358
+ if (shouldLog("error")) {
359
+ logger.error("GraphQL operation completed with errors", {
360
+ operationName: context.request.operationName,
361
+ duration: `${duration.toFixed(2)}ms`,
362
+ errors: response.errors
363
+ });
364
+ }
365
+ } else {
366
+ if (shouldLog("info")) {
367
+ logger.info("GraphQL operation completed", {
368
+ operationName: context.request.operationName,
369
+ duration: `${duration.toFixed(2)}ms`
370
+ });
371
+ }
372
+ }
373
+ return response;
374
+ },
375
+ async onError(error, context) {
376
+ if (shouldLog("error")) {
377
+ logger.error("GraphQL operation failed", {
378
+ operationName: context.request.operationName,
379
+ error: error.message
380
+ });
381
+ }
382
+ return error;
383
+ }
384
+ };
385
+ }
386
+ function createTracingPlugin() {
387
+ return {
388
+ metadata: {
389
+ name: "tracing",
390
+ version: "1.0.0",
391
+ description: "Adds tracing information to responses"
392
+ },
393
+ async beforeExecute(document, context) {
394
+ context.state.set("tracing", {
395
+ version: 1,
396
+ startTime: new Date().toISOString(),
397
+ startHrTime: process.hrtime.bigint(),
398
+ parsing: { startOffset: 0, duration: 0 },
399
+ validation: { startOffset: 0, duration: 0 },
400
+ execution: { startOffset: 0, duration: 0 }
401
+ });
402
+ },
403
+ async afterExecute(response, context) {
404
+ const tracing = context.state.get("tracing");
405
+ if (!tracing)
406
+ return response;
407
+ const endHrTime = process.hrtime.bigint();
408
+ const duration = Number(endHrTime - tracing.startHrTime);
409
+ return {
410
+ ...response,
411
+ extensions: {
412
+ ...response.extensions,
413
+ tracing: {
414
+ version: tracing.version,
415
+ startTime: tracing.startTime,
416
+ endTime: new Date().toISOString(),
417
+ duration,
418
+ parsing: tracing.parsing,
419
+ validation: tracing.validation,
420
+ execution: {
421
+ ...tracing.execution,
422
+ duration
423
+ }
424
+ }
425
+ }
426
+ };
427
+ }
428
+ };
429
+ }
430
+ function createDepthLimitPlugin(maxDepth) {
431
+ function calculateDepth(node, currentDepth = 0) {
432
+ if (!node || typeof node !== "object")
433
+ return currentDepth;
434
+ const typedNode = node;
435
+ let maxFoundDepth = currentDepth;
436
+ if (typedNode.kind === Kind.FIELD) {
437
+ maxFoundDepth = currentDepth + 1;
438
+ }
439
+ if (typedNode.selectionSet) {
440
+ for (const selection of typedNode.selectionSet.selections) {
441
+ const depth = calculateDepth(selection, maxFoundDepth);
442
+ if (depth > maxFoundDepth) {
443
+ maxFoundDepth = depth;
444
+ }
445
+ }
446
+ }
447
+ return maxFoundDepth;
448
+ }
449
+ return {
450
+ metadata: {
451
+ name: "depth-limit",
452
+ version: "1.0.0",
453
+ description: `Limits query depth to ${maxDepth}`
454
+ },
455
+ async afterParse(document, _context) {
456
+ let depth = 0;
457
+ for (const definition of document.definitions) {
458
+ if (definition.kind === Kind.OPERATION_DEFINITION) {
459
+ const opDepth = calculateDepth(definition, 0);
460
+ if (opDepth > depth) {
461
+ depth = opDepth;
462
+ }
463
+ }
464
+ }
465
+ if (depth > maxDepth) {
466
+ throw new Error(`Query depth of ${depth} exceeds maximum allowed depth of ${maxDepth}`);
467
+ }
468
+ return document;
469
+ }
470
+ };
471
+ }
472
+ function createComplexityPlugin(options) {
473
+ const { maxComplexity, defaultComplexity = 1 } = options;
474
+ function calculateComplexity(node, depth = 0) {
475
+ if (!node || typeof node !== "object")
476
+ return 0;
477
+ const typedNode = node;
478
+ let complexity = 0;
479
+ if (typedNode.kind === Kind.FIELD) {
480
+ let multiplier = 1;
481
+ if (typedNode.arguments) {
482
+ for (const arg of typedNode.arguments) {
483
+ if (arg.name.value === "first" || arg.name.value === "last" || arg.name.value === "limit") {
484
+ const value = parseInt(arg.value.value ?? "10", 10);
485
+ if (!isNaN(value)) {
486
+ multiplier = value;
487
+ }
488
+ }
489
+ }
490
+ }
491
+ complexity = defaultComplexity * multiplier;
492
+ }
493
+ if (typedNode.selectionSet) {
494
+ for (const selection of typedNode.selectionSet.selections) {
495
+ complexity += calculateComplexity(selection, depth + 1);
496
+ }
497
+ }
498
+ return complexity;
499
+ }
500
+ return {
501
+ metadata: {
502
+ name: "complexity",
503
+ version: "1.0.0",
504
+ description: `Limits query complexity to ${maxComplexity}`
505
+ },
506
+ async afterParse(document, context) {
507
+ let totalComplexity = 0;
508
+ for (const definition of document.definitions) {
509
+ if (definition.kind === Kind.OPERATION_DEFINITION) {
510
+ totalComplexity += calculateComplexity(definition, 0);
511
+ }
512
+ }
513
+ context.state.set("complexity", totalComplexity);
514
+ if (totalComplexity > maxComplexity) {
515
+ throw new Error(`Query complexity of ${totalComplexity} exceeds maximum allowed complexity of ${maxComplexity}`);
516
+ }
517
+ return document;
518
+ }
519
+ };
520
+ }
521
+ export {
522
+ createTracingPlugin,
523
+ createPluginManager,
524
+ createPlugin,
525
+ createLoggingPlugin,
526
+ createDepthLimitPlugin,
527
+ createComplexityPlugin,
528
+ createCachingPlugin,
529
+ composePlugins,
530
+ PluginManager
531
+ };
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @leaven-graphql/plugins - Plugin manager
3
+ *
4
+ * Copyright 2026 Pegasus Heavy Industries LLC
5
+ * Licensed under the Apache License, Version 2.0
6
+ */
7
+ import type { DocumentNode, GraphQLSchema, GraphQLError } from 'graphql';
8
+ import type { GraphQLRequest, GraphQLResponse } from '@leaven-graphql/core';
9
+ import type { Plugin, PluginContext } from './types';
10
+ /**
11
+ * Plugin manager configuration
12
+ */
13
+ export interface PluginManagerConfig {
14
+ /** GraphQL schema */
15
+ schema: GraphQLSchema;
16
+ /** Initial plugins to register */
17
+ plugins?: Plugin[];
18
+ }
19
+ /**
20
+ * Manages plugins and executes hooks
21
+ */
22
+ export declare class PluginManager {
23
+ private readonly schema;
24
+ private readonly plugins;
25
+ private readonly pluginOrder;
26
+ constructor(config: PluginManagerConfig);
27
+ /**
28
+ * Register a plugin
29
+ */
30
+ register(plugin: Plugin): Promise<void>;
31
+ /**
32
+ * Unregister a plugin
33
+ */
34
+ unregister(name: string): Promise<boolean>;
35
+ /**
36
+ * Get a plugin by name
37
+ */
38
+ get(name: string): Plugin | undefined;
39
+ /**
40
+ * Check if a plugin is registered
41
+ */
42
+ has(name: string): boolean;
43
+ /**
44
+ * Get all registered plugin names
45
+ */
46
+ getPluginNames(): string[];
47
+ /**
48
+ * Create a plugin context
49
+ */
50
+ createContext<TContext>(request: GraphQLRequest, userContext: TContext): PluginContext<TContext>;
51
+ /**
52
+ * Execute beforeParse hooks
53
+ */
54
+ beforeParse(query: string, context: PluginContext): Promise<string>;
55
+ /**
56
+ * Execute afterParse hooks
57
+ */
58
+ afterParse(document: DocumentNode, context: PluginContext): Promise<DocumentNode>;
59
+ /**
60
+ * Execute beforeValidate hooks
61
+ */
62
+ beforeValidate(document: DocumentNode, context: PluginContext): Promise<void>;
63
+ /**
64
+ * Execute afterValidate hooks
65
+ */
66
+ afterValidate(result: {
67
+ valid: boolean;
68
+ errors: readonly GraphQLError[];
69
+ }, context: PluginContext): Promise<void>;
70
+ /**
71
+ * Execute beforeExecute hooks
72
+ */
73
+ beforeExecute(document: DocumentNode, context: PluginContext): Promise<void>;
74
+ /**
75
+ * Execute afterExecute hooks
76
+ */
77
+ afterExecute(response: GraphQLResponse, context: PluginContext): Promise<GraphQLResponse>;
78
+ /**
79
+ * Execute onError hooks
80
+ */
81
+ onError(error: Error, context: PluginContext): Promise<Error>;
82
+ /**
83
+ * Get the number of registered plugins
84
+ */
85
+ get size(): number;
86
+ /**
87
+ * Clear all plugins
88
+ */
89
+ clear(): Promise<void>;
90
+ }
91
+ /**
92
+ * Create a new plugin manager
93
+ */
94
+ export declare function createPluginManager(config: PluginManagerConfig): PluginManager;
95
+ //# sourceMappingURL=manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,qBAAqB;IACrB,MAAM,EAAE,aAAa,CAAC;IACtB,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;gBAE3B,MAAM,EAAE,mBAAmB;IAavC;;OAE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CAAC,KAAK,CAAC;IAgB1E;;OAEG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAMpC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,GAAG,aAAa,CAE9E"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @leaven-graphql/plugins - Plugin types
3
+ *
4
+ * Copyright 2026 Pegasus Heavy Industries LLC
5
+ * Licensed under the Apache License, Version 2.0
6
+ */
7
+ import type { DocumentNode, GraphQLSchema, GraphQLError } from 'graphql';
8
+ import type { GraphQLRequest, GraphQLResponse } from '@leaven-graphql/core';
9
+ /**
10
+ * Plugin metadata
11
+ */
12
+ export interface PluginMetadata {
13
+ /** Unique plugin name */
14
+ name: string;
15
+ /** Plugin version */
16
+ version?: string;
17
+ /** Plugin description */
18
+ description?: string;
19
+ /** Plugin dependencies */
20
+ dependencies?: string[];
21
+ }
22
+ /**
23
+ * Plugin context available to hooks
24
+ */
25
+ export interface PluginContext<TContext = unknown> {
26
+ /** The GraphQL schema */
27
+ schema: GraphQLSchema;
28
+ /** The original request */
29
+ request: GraphQLRequest;
30
+ /** User context */
31
+ context: TContext;
32
+ /** Additional data shared between hooks */
33
+ state: Map<string, unknown>;
34
+ }
35
+ /**
36
+ * Hook called before parsing
37
+ */
38
+ export type BeforeParseHook = (query: string, context: PluginContext) => string | void | Promise<string | void>;
39
+ /**
40
+ * Hook called after parsing
41
+ */
42
+ export type AfterParseHook = (document: DocumentNode, context: PluginContext) => DocumentNode | void | Promise<DocumentNode | void>;
43
+ /**
44
+ * Hook called before validation
45
+ */
46
+ export type BeforeValidateHook = (document: DocumentNode, context: PluginContext) => void | Promise<void>;
47
+ /**
48
+ * Hook called after validation
49
+ */
50
+ export type AfterValidateHook = (result: {
51
+ valid: boolean;
52
+ errors: readonly GraphQLError[];
53
+ }, context: PluginContext) => void | Promise<void>;
54
+ /**
55
+ * Hook called before execution
56
+ */
57
+ export type BeforeExecuteHook = (document: DocumentNode, context: PluginContext) => void | Promise<void>;
58
+ /**
59
+ * Hook called after execution
60
+ */
61
+ export type AfterExecuteHook = (response: GraphQLResponse, context: PluginContext) => GraphQLResponse | void | Promise<GraphQLResponse | void>;
62
+ /**
63
+ * Hook called on error
64
+ */
65
+ export type OnErrorHook = (error: Error, context: PluginContext) => Error | void | Promise<Error | void>;
66
+ /**
67
+ * Plugin hooks
68
+ */
69
+ export interface PluginHooks {
70
+ /** Called before parsing the query */
71
+ beforeParse?: BeforeParseHook;
72
+ /** Called after parsing the query */
73
+ afterParse?: AfterParseHook;
74
+ /** Called before validating the document */
75
+ beforeValidate?: BeforeValidateHook;
76
+ /** Called after validating the document */
77
+ afterValidate?: AfterValidateHook;
78
+ /** Called before executing the operation */
79
+ beforeExecute?: BeforeExecuteHook;
80
+ /** Called after executing the operation */
81
+ afterExecute?: AfterExecuteHook;
82
+ /** Called when an error occurs */
83
+ onError?: OnErrorHook;
84
+ }
85
+ /**
86
+ * Plugin interface
87
+ */
88
+ export interface Plugin extends PluginHooks {
89
+ /** Plugin metadata */
90
+ metadata: PluginMetadata;
91
+ /** Called when plugin is registered */
92
+ onRegister?: (schema: GraphQLSchema) => void | Promise<void>;
93
+ /** Called when plugin is unregistered */
94
+ onUnregister?: () => void | Promise<void>;
95
+ }
96
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,OAAO,CAAC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,CAAC,CAAC;AAE1B;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,aAAa,KACnB,eAAe,GAAG,IAAI,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CACxB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,aAAa,KACnB,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,sCAAsC;IACtC,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,qCAAqC;IACrC,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,4CAA4C;IAC5C,cAAc,CAAC,EAAE,kBAAkB,CAAC;IACpC,2CAA2C;IAC3C,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,4CAA4C;IAC5C,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,2CAA2C;IAC3C,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC,kCAAkC;IAClC,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,MAAO,SAAQ,WAAW;IACzC,sBAAsB;IACtB,QAAQ,EAAE,cAAc,CAAC;IACzB,uCAAuC;IACvC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D,yCAAyC;IACzC,YAAY,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@leaven-graphql/plugins",
3
+ "version": "0.1.0",
4
+ "description": "Plugin system for Leaven GraphQL",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "keywords": [
19
+ "graphql",
20
+ "bun",
21
+ "plugins"
22
+ ],
23
+ "author": "Pegasus Heavy Industries LLC",
24
+ "license": "Apache-2.0",
25
+ "dependencies": {
26
+ "graphql": "^16.8.0",
27
+ "@leaven-graphql/core": "0.1.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/bun": "^1.1.0",
31
+ "typescript": "^5.3.0"
32
+ },
33
+ "peerDependencies": {
34
+ "graphql": "^16.0.0"
35
+ },
36
+ "scripts": {
37
+ "build": "bun build ./src/index.ts --outdir ./dist --target bun && tsc -p tsconfig.build.json",
38
+ "clean": "rm -rf dist",
39
+ "test": "bun test",
40
+ "typecheck": "tsc --noEmit"
41
+ }
42
+ }