@0xobelisk/graphql-server 1.2.0-pre.24

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 (79) hide show
  1. package/Dockerfile +31 -0
  2. package/EXPRESS_MIGRATION.md +176 -0
  3. package/LICENSE +92 -0
  4. package/README.md +908 -0
  5. package/dist/config/subscription-config.d.ts +47 -0
  6. package/dist/config/subscription-config.d.ts.map +1 -0
  7. package/dist/config/subscription-config.js +133 -0
  8. package/dist/config/subscription-config.js.map +1 -0
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +217 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/plugins/all-fields-filter-plugin.d.ts +4 -0
  14. package/dist/plugins/all-fields-filter-plugin.d.ts.map +1 -0
  15. package/dist/plugins/all-fields-filter-plugin.js +132 -0
  16. package/dist/plugins/all-fields-filter-plugin.js.map +1 -0
  17. package/dist/plugins/database-introspector.d.ts +23 -0
  18. package/dist/plugins/database-introspector.d.ts.map +1 -0
  19. package/dist/plugins/database-introspector.js +96 -0
  20. package/dist/plugins/database-introspector.js.map +1 -0
  21. package/dist/plugins/enhanced-playground.d.ts +9 -0
  22. package/dist/plugins/enhanced-playground.d.ts.map +1 -0
  23. package/dist/plugins/enhanced-playground.js +97 -0
  24. package/dist/plugins/enhanced-playground.js.map +1 -0
  25. package/dist/plugins/enhanced-server-manager.d.ts +28 -0
  26. package/dist/plugins/enhanced-server-manager.d.ts.map +1 -0
  27. package/dist/plugins/enhanced-server-manager.js +232 -0
  28. package/dist/plugins/enhanced-server-manager.js.map +1 -0
  29. package/dist/plugins/index.d.ts +9 -0
  30. package/dist/plugins/index.d.ts.map +1 -0
  31. package/dist/plugins/index.js +26 -0
  32. package/dist/plugins/index.js.map +1 -0
  33. package/dist/plugins/postgraphile-config.d.ts +94 -0
  34. package/dist/plugins/postgraphile-config.d.ts.map +1 -0
  35. package/dist/plugins/postgraphile-config.js +183 -0
  36. package/dist/plugins/postgraphile-config.js.map +1 -0
  37. package/dist/plugins/query-filter.d.ts +4 -0
  38. package/dist/plugins/query-filter.d.ts.map +1 -0
  39. package/dist/plugins/query-filter.js +42 -0
  40. package/dist/plugins/query-filter.js.map +1 -0
  41. package/dist/plugins/simple-naming.d.ts +4 -0
  42. package/dist/plugins/simple-naming.d.ts.map +1 -0
  43. package/dist/plugins/simple-naming.js +79 -0
  44. package/dist/plugins/simple-naming.js.map +1 -0
  45. package/dist/plugins/welcome-page.d.ts +11 -0
  46. package/dist/plugins/welcome-page.d.ts.map +1 -0
  47. package/dist/plugins/welcome-page.js +203 -0
  48. package/dist/plugins/welcome-page.js.map +1 -0
  49. package/dist/universal-subscriptions.d.ts +32 -0
  50. package/dist/universal-subscriptions.d.ts.map +1 -0
  51. package/dist/universal-subscriptions.js +318 -0
  52. package/dist/universal-subscriptions.js.map +1 -0
  53. package/dist/utils/logger/index.d.ts +80 -0
  54. package/dist/utils/logger/index.d.ts.map +1 -0
  55. package/dist/utils/logger/index.js +232 -0
  56. package/dist/utils/logger/index.js.map +1 -0
  57. package/docker-compose.yml +87 -0
  58. package/package.json +71 -0
  59. package/server.log +62 -0
  60. package/src/config/subscription-config.ts +186 -0
  61. package/src/index.ts +239 -0
  62. package/src/plugins/README.md +123 -0
  63. package/src/plugins/all-fields-filter-plugin.ts +158 -0
  64. package/src/plugins/database-introspector.ts +126 -0
  65. package/src/plugins/enhanced-playground.ts +105 -0
  66. package/src/plugins/enhanced-server-manager.ts +282 -0
  67. package/src/plugins/index.ts +9 -0
  68. package/src/plugins/postgraphile-config.ts +226 -0
  69. package/src/plugins/query-filter.ts +50 -0
  70. package/src/plugins/simple-naming.ts +105 -0
  71. package/src/plugins/welcome-page.ts +218 -0
  72. package/src/universal-subscriptions.ts +397 -0
  73. package/src/utils/logger/README.md +193 -0
  74. package/src/utils/logger/index.ts +315 -0
  75. package/sui-indexer-schema.graphql +1004 -0
  76. package/test-express.js +124 -0
  77. package/test_listen_subscription.js +121 -0
  78. package/test_notification.js +63 -0
  79. package/tsconfig.json +28 -0
package/Dockerfile ADDED
@@ -0,0 +1,31 @@
1
+ FROM node:18-alpine
2
+
3
+ WORKDIR /app
4
+
5
+ # 安装 pnpm
6
+ RUN npm install -g pnpm
7
+
8
+ # 复制依赖文件
9
+ COPY package.json pnpm-lock.yaml* ./
10
+
11
+ # 安装依赖
12
+ RUN pnpm install --frozen-lockfile
13
+
14
+ # 复制源代码
15
+ COPY . .
16
+
17
+ # 构建项目
18
+ RUN pnpm build
19
+
20
+ # 创建非root用户
21
+ RUN addgroup -g 1001 -S nodejs
22
+ RUN adduser -S nodejs -u 1001
23
+
24
+ # 设置用户
25
+ USER nodejs
26
+
27
+ # 暴露端口
28
+ EXPOSE 4000
29
+
30
+ # 启动应用
31
+ CMD ["pnpm", "start"]
@@ -0,0 +1,176 @@
1
+ # Express架构迁移指南
2
+
3
+ ## 概述
4
+
5
+ 原本的GraphQL服务器使用Node.js原生HTTP模块实现,现已成功迁移至Express框架。这次迁移带来了更好的中间件支持、更清晰的路由管理和更强的扩展性。
6
+
7
+ ## 主要变更
8
+
9
+ ### 1. 架构变更
10
+ - **之前**: Node.js原生HTTP + 手动路由处理
11
+ - **现在**: Express框架 + 中间件和路由系统
12
+
13
+ ### 2. 新增依赖
14
+ ```json
15
+ {
16
+ "express": "^4.18.2",
17
+ "cors": "^2.8.5",
18
+ "@types/express": "^4.17.21",
19
+ "@types/cors": "^2.8.17"
20
+ }
21
+ ```
22
+
23
+ ### 3. 核心文件变更
24
+
25
+ #### `enhanced-server-manager.ts`
26
+ - 从原生HTTP服务器改为Express应用
27
+ - 使用Express中间件系统
28
+ - 更清晰的路由定义
29
+ - 专业的错误处理
30
+
31
+ #### `index.ts`
32
+ - 更新启动日志,标明使用Express架构
33
+ - 错误信息中提到使用`pnpm install`
34
+
35
+ ## 功能对比
36
+
37
+ | 功能 | 原生HTTP | Express |
38
+ |------|----------|---------|
39
+ | 路由管理 | 手动`if/else`判断 | 专业路由系统 |
40
+ | 中间件 | 手动实现 | 内置中间件系统 |
41
+ | CORS | 手动设置头部 | `cors`中间件 |
42
+ | 错误处理 | 手动try/catch | 全局错误中间件 |
43
+ | 请求日志 | 分散在各处 | 统一中间件 |
44
+ | 代码可读性 | 较低 | 大幅提升 |
45
+
46
+ ## API端点
47
+
48
+ 所有原有端点保持不变:
49
+
50
+ - `GET /` - 欢迎页面
51
+ - `GET /playground` - GraphQL Playground
52
+ - `GET /graphiql*` - 重定向到`/playground`
53
+ - `POST /graphql` - GraphQL端点
54
+ - `GET /health` - 健康检查
55
+ - `GET /subscription-config` - 订阅配置
56
+ - `GET /subscription-docs` - 配置文档
57
+
58
+ ## 安装和运行
59
+
60
+ ### 安装依赖
61
+ ```bash
62
+ pnpm install
63
+ ```
64
+
65
+ ### 开发模式
66
+ ```bash
67
+ pnpm dev
68
+ ```
69
+
70
+ ### 生产模式
71
+ ```bash
72
+ pnpm build
73
+ pnpm start
74
+ ```
75
+
76
+ ### 测试服务器
77
+ ```bash
78
+ node test-express.js
79
+ ```
80
+
81
+ ## Express架构优势
82
+
83
+ ### 1. 更好的中间件系统
84
+ ```javascript
85
+ // CORS处理
86
+ app.use(cors({
87
+ origin: '*',
88
+ methods: ['GET', 'POST', 'OPTIONS'],
89
+ allowedHeaders: ['Content-Type', 'Authorization'],
90
+ }));
91
+
92
+ // 请求日志
93
+ app.use((req, res, next) => {
94
+ // 统一的请求日志处理
95
+ next();
96
+ });
97
+ ```
98
+
99
+ ### 2. 清晰的路由定义
100
+ ```javascript
101
+ // 具体路由
102
+ app.get('/', handleHomePage);
103
+ app.get('/health', handleHealthCheck);
104
+ app.use('/graphql', postgraphileMiddleware);
105
+
106
+ // 404处理
107
+ app.use('*', handle404);
108
+
109
+ // 错误处理
110
+ app.use(errorHandler);
111
+ ```
112
+
113
+ ### 3. 专业的错误处理
114
+ ```javascript
115
+ app.use((err, req, res, next) => {
116
+ serverLogger.error('Express错误处理', err, {
117
+ url: req.originalUrl,
118
+ method: req.method,
119
+ userAgent: req.get('user-agent')?.substring(0, 50),
120
+ });
121
+ res.status(500).send('Internal Server Error');
122
+ });
123
+ ```
124
+
125
+ ## 迁移后的好处
126
+
127
+ 1. **可维护性**: 代码结构更清晰,易于维护
128
+ 2. **扩展性**: 可以轻松添加新的中间件和路由
129
+ 3. **标准化**: 使用业界标准的Express框架
130
+ 4. **生态系统**: 可以利用Express丰富的中间件生态
131
+ 5. **调试体验**: 更好的错误堆栈和调试信息
132
+
133
+ ## 潜在影响
134
+
135
+ ### 正面影响
136
+ - 更稳定的HTTP处理
137
+ - 更好的错误恢复机制
138
+ - 更专业的中间件处理
139
+ - 更清晰的代码结构
140
+
141
+ ### 注意事项
142
+ - 轻微的性能开销(但在实际应用中可以忽略)
143
+ - 新增了Express依赖
144
+
145
+ ## 验证迁移
146
+
147
+ 运行测试脚本验证所有端点正常工作:
148
+
149
+ ```bash
150
+ node test-express.js
151
+ ```
152
+
153
+ 预期输出:
154
+ ```
155
+ 🧪 开始测试Express服务器 (localhost:4000)
156
+ ============================================================
157
+ 🔍 测试 / (主页)
158
+ ✅ / - 状态码: 200
159
+
160
+ 🔍 测试 /health (健康检查)
161
+ ✅ /health - 状态码: 200
162
+
163
+ 🔍 测试 /playground (GraphQL Playground)
164
+ ✅ /playground - 状态码: 200
165
+
166
+ 🔍 测试 /subscription-config (订阅配置)
167
+ ✅ /subscription-config - 状态码: 200
168
+
169
+ ============================================================
170
+ 📊 测试结果: 4/4 通过
171
+ 🎉 所有测试通过!Express服务器运行正常
172
+ ```
173
+
174
+ ## 总结
175
+
176
+ Express架构迁移成功完成,服务器现在使用更专业的Web框架,提供了更好的开发体验和更强的扩展性。所有原有功能保持不变,同时代码质量得到显著提升。
package/LICENSE ADDED
@@ -0,0 +1,92 @@
1
+ Business Source License 1.1
2
+
3
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
4
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
5
+
6
+ -----------------------------------------------------------------------------
7
+
8
+ Parameters
9
+
10
+ Licensor: Obelisk Labs
11
+
12
+ Licensed Work: Dubhe
13
+ The Licensed Work is (c) 2023 Obelisk Labs
14
+
15
+ -----------------------------------------------------------------------------
16
+
17
+ Terms
18
+
19
+ The Licensor hereby grants you the right to copy, modify, create derivative
20
+ works, redistribute, and make non-production use of the Licensed Work. The
21
+ Licensor may make an Additional Use Grant, above, permitting limited
22
+ production use.
23
+
24
+ Effective on the Change Date, or the fourth anniversary of the first publicly
25
+ available distribution of a specific version of the Licensed Work under this
26
+ License, whichever comes first, the Licensor hereby grants you rights under
27
+ the terms of the Change License, and the rights granted in the paragraph
28
+ above terminate.
29
+
30
+ If your use of the Licensed Work does not comply with the requirements
31
+ currently in effect as described in this License, you must purchase a
32
+ commercial license from the Licensor, its affiliated entities, or authorized
33
+ resellers, or you must refrain from using the Licensed Work.
34
+
35
+ All copies of the original and modified Licensed Work, and derivative works
36
+ of the Licensed Work, are subject to this License. This License applies
37
+ separately for each version of the Licensed Work and the Change Date may vary
38
+ for each version of the Licensed Work released by Licensor.
39
+
40
+ You must conspicuously display this License on each original or modified copy
41
+ of the Licensed Work. If you receive the Licensed Work in original or
42
+ modified form from a third party, the terms and conditions set forth in this
43
+ License apply to your use of that work.
44
+
45
+ Any use of the Licensed Work in violation of this License will automatically
46
+ terminate your rights under this License for the current and all other
47
+ versions of the Licensed Work.
48
+
49
+ This License does not grant you any right in any trademark or logo of
50
+ Licensor or its affiliates (provided that you may use a trademark or logo of
51
+ Licensor as expressly required by this License).
52
+
53
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
54
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
55
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
57
+ TITLE.
58
+
59
+ MariaDB hereby grants you permission to use this License’s text to license
60
+ your works, and to refer to it using the trademark "Business Source License",
61
+ as long as you comply with the Covenants of Licensor below.
62
+
63
+ -----------------------------------------------------------------------------
64
+
65
+ Covenants of Licensor
66
+
67
+ In consideration of the right to use this License’s text and the "Business
68
+ Source License" name and trademark, Licensor covenants to MariaDB, and to all
69
+ other recipients of the licensed work to be provided by Licensor:
70
+
71
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
72
+ or a license that is compatible with GPL Version 2.0 or a later version,
73
+ where "compatible" means that software provided under the Change License can
74
+ be included in a program with software provided under GPL Version 2.0 or a
75
+ later version. Licensor may specify additional Change Licenses without
76
+ limitation.
77
+
78
+ 2. To either: (a) specify an additional grant of rights to use that does not
79
+ impose any additional restriction on the right granted in this License, as
80
+ the Additional Use Grant; or (b) insert the text "None".
81
+
82
+ 3. To specify a Change Date.
83
+
84
+ 4. Not to modify this License in any other way.
85
+
86
+ -----------------------------------------------------------------------------
87
+
88
+ Notice
89
+
90
+ The Business Source License (this document, or the "License") is not an Open
91
+ Source license. However, the Licensed Work will eventually be made available
92
+ under an Open Source License, as stated in this License.