@0xobelisk/graphql-server 1.2.0-pre.100
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/.turbo/turbo-build.log +8 -0
- package/DUAL_POOL_CONFIG.md +188 -0
- package/Dockerfile +35 -0
- package/LICENSE +92 -0
- package/README.md +487 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +206 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/subscription-config.d.ts +80 -0
- package/dist/config/subscription-config.d.ts.map +1 -0
- package/dist/config/subscription-config.js +158 -0
- package/dist/config/subscription-config.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/all-fields-filter-plugin.d.ts +4 -0
- package/dist/plugins/all-fields-filter-plugin.d.ts.map +1 -0
- package/dist/plugins/all-fields-filter-plugin.js +132 -0
- package/dist/plugins/all-fields-filter-plugin.js.map +1 -0
- package/dist/plugins/database-introspector.d.ts +23 -0
- package/dist/plugins/database-introspector.d.ts.map +1 -0
- package/dist/plugins/database-introspector.js +96 -0
- package/dist/plugins/database-introspector.js.map +1 -0
- package/dist/plugins/enhanced-playground.d.ts +9 -0
- package/dist/plugins/enhanced-playground.d.ts.map +1 -0
- package/dist/plugins/enhanced-playground.js +113 -0
- package/dist/plugins/enhanced-playground.js.map +1 -0
- package/dist/plugins/enhanced-server-manager.d.ts +29 -0
- package/dist/plugins/enhanced-server-manager.d.ts.map +1 -0
- package/dist/plugins/enhanced-server-manager.js +262 -0
- package/dist/plugins/enhanced-server-manager.js.map +1 -0
- package/dist/plugins/index.d.ts +9 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +26 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/postgraphile-config.d.ts +94 -0
- package/dist/plugins/postgraphile-config.d.ts.map +1 -0
- package/dist/plugins/postgraphile-config.js +138 -0
- package/dist/plugins/postgraphile-config.js.map +1 -0
- package/dist/plugins/query-filter.d.ts +4 -0
- package/dist/plugins/query-filter.d.ts.map +1 -0
- package/dist/plugins/query-filter.js +42 -0
- package/dist/plugins/query-filter.js.map +1 -0
- package/dist/plugins/simple-naming.d.ts +4 -0
- package/dist/plugins/simple-naming.d.ts.map +1 -0
- package/dist/plugins/simple-naming.js +79 -0
- package/dist/plugins/simple-naming.js.map +1 -0
- package/dist/plugins/welcome-page.d.ts +11 -0
- package/dist/plugins/welcome-page.d.ts.map +1 -0
- package/dist/plugins/welcome-page.js +203 -0
- package/dist/plugins/welcome-page.js.map +1 -0
- package/dist/server.d.ts +21 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +265 -0
- package/dist/server.js.map +1 -0
- package/dist/universal-subscriptions.d.ts +32 -0
- package/dist/universal-subscriptions.d.ts.map +1 -0
- package/dist/universal-subscriptions.js +318 -0
- package/dist/universal-subscriptions.js.map +1 -0
- package/dist/utils/logger/index.d.ts +80 -0
- package/dist/utils/logger/index.d.ts.map +1 -0
- package/dist/utils/logger/index.js +230 -0
- package/dist/utils/logger/index.js.map +1 -0
- package/docker-compose.yml +46 -0
- package/eslint.config.mjs +3 -0
- package/package.json +78 -0
- package/src/cli.ts +232 -0
- package/src/config/subscription-config.ts +243 -0
- package/src/index.ts +11 -0
- package/src/plugins/README.md +138 -0
- package/src/plugins/all-fields-filter-plugin.ts +158 -0
- package/src/plugins/database-introspector.ts +126 -0
- package/src/plugins/enhanced-playground.ts +121 -0
- package/src/plugins/enhanced-server-manager.ts +314 -0
- package/src/plugins/index.ts +9 -0
- package/src/plugins/postgraphile-config.ts +182 -0
- package/src/plugins/query-filter.ts +50 -0
- package/src/plugins/simple-naming.ts +105 -0
- package/src/plugins/welcome-page.ts +218 -0
- package/src/server.ts +324 -0
- package/src/universal-subscriptions.ts +397 -0
- package/src/utils/logger/README.md +209 -0
- package/src/utils/logger/index.ts +275 -0
- package/sui-indexer-schema.graphql +3691 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import pino from 'pino';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
|
|
5
|
+
export interface LoggerConfig {
|
|
6
|
+
level?: string;
|
|
7
|
+
service?: string;
|
|
8
|
+
component?: string;
|
|
9
|
+
enableFileLogging?: boolean;
|
|
10
|
+
logsDir?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ComponentLoggerMethods {
|
|
14
|
+
debug: (message: string, meta?: any) => void;
|
|
15
|
+
info: (message: string, meta?: any) => void;
|
|
16
|
+
warn: (message: string, meta?: any) => void;
|
|
17
|
+
error: (message: string, error?: any, meta?: any) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* High-performance logging system based on Pino
|
|
22
|
+
*/
|
|
23
|
+
export class Logger {
|
|
24
|
+
private pinoInstance: pino.Logger;
|
|
25
|
+
private config: Required<LoggerConfig>;
|
|
26
|
+
|
|
27
|
+
constructor(config: LoggerConfig = {}) {
|
|
28
|
+
this.config = {
|
|
29
|
+
level: config.level || process.env.LOG_LEVEL || 'info',
|
|
30
|
+
service: config.service || 'dubhe-graphql-server',
|
|
31
|
+
component: config.component || 'default',
|
|
32
|
+
enableFileLogging: config.enableFileLogging !== false,
|
|
33
|
+
logsDir: config.logsDir || path.join(process.cwd(), 'logs')
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
this.ensureLogsDirectory();
|
|
37
|
+
this.pinoInstance = this.createPinoInstance();
|
|
38
|
+
this.setupExceptionHandlers();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Ensure logs directory exists
|
|
43
|
+
*/
|
|
44
|
+
private ensureLogsDirectory(): void {
|
|
45
|
+
if (this.config.enableFileLogging && !fs.existsSync(this.config.logsDir)) {
|
|
46
|
+
fs.mkdirSync(this.config.logsDir, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Create Pino instance
|
|
52
|
+
*/
|
|
53
|
+
private createPinoInstance(): pino.Logger {
|
|
54
|
+
const pinoOptions: pino.LoggerOptions = {
|
|
55
|
+
level: this.config.level,
|
|
56
|
+
base: {
|
|
57
|
+
service: this.config.service,
|
|
58
|
+
pid: process.pid
|
|
59
|
+
},
|
|
60
|
+
timestamp: pino.stdTimeFunctions.isoTime,
|
|
61
|
+
formatters: {
|
|
62
|
+
level(label: string) {
|
|
63
|
+
return { level: label };
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
serializers: {
|
|
67
|
+
error: pino.stdSerializers.err
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// If file logging is enabled, use multistream
|
|
72
|
+
if (this.config.enableFileLogging) {
|
|
73
|
+
const streams = [
|
|
74
|
+
// Pretty print to console
|
|
75
|
+
{
|
|
76
|
+
stream: pino.transport({
|
|
77
|
+
target: 'pino-pretty',
|
|
78
|
+
options: {
|
|
79
|
+
colorize: true,
|
|
80
|
+
translateTime: 'yyyy-mm-dd HH:MM:ss.l',
|
|
81
|
+
ignore: 'pid,hostname,service,component',
|
|
82
|
+
messageFormat: '[{component}]: {msg}',
|
|
83
|
+
singleLine: true,
|
|
84
|
+
hideObject: false
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
},
|
|
88
|
+
// JSON format to file
|
|
89
|
+
{
|
|
90
|
+
stream: pino.destination({
|
|
91
|
+
dest: path.join(this.config.logsDir, 'combined.log'),
|
|
92
|
+
sync: false
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
return pino(pinoOptions, pino.multistream(streams));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Only output to console in pretty format
|
|
101
|
+
return pino({
|
|
102
|
+
...pinoOptions,
|
|
103
|
+
transport: {
|
|
104
|
+
target: 'pino-pretty',
|
|
105
|
+
options: {
|
|
106
|
+
colorize: true,
|
|
107
|
+
translateTime: 'yyyy-mm-dd HH:MM:ss.l',
|
|
108
|
+
ignore: 'pid,hostname,service',
|
|
109
|
+
messageFormat: '[{component}]: {msg}',
|
|
110
|
+
singleLine: true,
|
|
111
|
+
hideObject: false
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Setup exception handlers
|
|
119
|
+
*/
|
|
120
|
+
private setupExceptionHandlers(): void {
|
|
121
|
+
process.on('uncaughtException', (error) => {
|
|
122
|
+
this.pinoInstance.fatal({ error }, 'Uncaught Exception');
|
|
123
|
+
process.exit(1);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
127
|
+
this.pinoInstance.fatal({ reason, promise }, 'Unhandled Promise Rejection');
|
|
128
|
+
process.exit(1);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Create component logger with context
|
|
134
|
+
*/
|
|
135
|
+
public createComponentLogger(component: string): ComponentLoggerMethods {
|
|
136
|
+
const componentLogger = this.pinoInstance.child({ component });
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
debug: (message: string, meta?: any) => componentLogger.debug(meta || {}, message),
|
|
140
|
+
info: (message: string, meta?: any) => componentLogger.info(meta || {}, message),
|
|
141
|
+
warn: (message: string, meta?: any) => componentLogger.warn(meta || {}, message),
|
|
142
|
+
error: (message: string, error?: any, meta?: any) => {
|
|
143
|
+
const errorData =
|
|
144
|
+
error instanceof Error
|
|
145
|
+
? {
|
|
146
|
+
error: {
|
|
147
|
+
message: error.message,
|
|
148
|
+
stack: error.stack,
|
|
149
|
+
name: error.name
|
|
150
|
+
},
|
|
151
|
+
...meta
|
|
152
|
+
}
|
|
153
|
+
: { error, ...meta };
|
|
154
|
+
componentLogger.error(errorData, message);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Get raw Pino instance
|
|
161
|
+
*/
|
|
162
|
+
public getPinoInstance(): pino.Logger {
|
|
163
|
+
return this.pinoInstance;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Log performance metrics
|
|
168
|
+
*/
|
|
169
|
+
public logPerformance(operation: string, startTime: number, meta?: any): void {
|
|
170
|
+
const duration = Date.now() - startTime;
|
|
171
|
+
const perfLogger = this.createComponentLogger('performance');
|
|
172
|
+
perfLogger.info(operation, {
|
|
173
|
+
duration: `${duration}ms`,
|
|
174
|
+
...meta
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Log Express HTTP requests
|
|
180
|
+
*/
|
|
181
|
+
public logExpress(
|
|
182
|
+
method: string,
|
|
183
|
+
path: string,
|
|
184
|
+
statusCode: number,
|
|
185
|
+
startTime: number,
|
|
186
|
+
meta?: any
|
|
187
|
+
): void {
|
|
188
|
+
const duration = Date.now() - startTime;
|
|
189
|
+
const httpLogger = this.createComponentLogger('express');
|
|
190
|
+
const message = `${method} ${path} - ${statusCode} (${duration}ms)`;
|
|
191
|
+
|
|
192
|
+
// Choose log level based on status code
|
|
193
|
+
if (statusCode >= 500) {
|
|
194
|
+
httpLogger.error(message, meta);
|
|
195
|
+
} else if (statusCode >= 400) {
|
|
196
|
+
httpLogger.warn(message, meta);
|
|
197
|
+
} else {
|
|
198
|
+
httpLogger.info(message, meta);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Log database operations
|
|
204
|
+
*/
|
|
205
|
+
public logDatabaseOperation(operation: string, table?: string, meta?: any): void {
|
|
206
|
+
const dbLogger = this.createComponentLogger('database');
|
|
207
|
+
dbLogger.info(`Database operation: ${operation}`, {
|
|
208
|
+
table,
|
|
209
|
+
...meta
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Log WebSocket events
|
|
215
|
+
*/
|
|
216
|
+
public logWebSocketEvent(event: string, clientCount?: number, meta?: any): void {
|
|
217
|
+
const wsLogger = this.createComponentLogger('websocket');
|
|
218
|
+
wsLogger.info(`WebSocket event: ${event}`, {
|
|
219
|
+
clientCount,
|
|
220
|
+
...meta
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Log GraphQL queries
|
|
226
|
+
*/
|
|
227
|
+
public logGraphQLQuery(operation: string, query?: string, variables?: any): void {
|
|
228
|
+
const gqlLogger = this.createComponentLogger('graphql');
|
|
229
|
+
gqlLogger.info(`GraphQL ${operation}`, {
|
|
230
|
+
query: query?.substring(0, 200) + (query && query.length > 200 ? '...' : ''),
|
|
231
|
+
variableCount: variables ? Object.keys(variables).length : 0
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Create default logger instance
|
|
237
|
+
const defaultLogger = new Logger();
|
|
238
|
+
|
|
239
|
+
// Export predefined component loggers (maintain backward compatibility)
|
|
240
|
+
export const dbLogger = defaultLogger.createComponentLogger('database');
|
|
241
|
+
export const serverLogger = defaultLogger.createComponentLogger('server');
|
|
242
|
+
export const httpLogger = defaultLogger.createComponentLogger('express');
|
|
243
|
+
export const wsLogger = defaultLogger.createComponentLogger('websocket');
|
|
244
|
+
export const gqlLogger = defaultLogger.createComponentLogger('graphql');
|
|
245
|
+
export const subscriptionLogger = defaultLogger.createComponentLogger('subscription');
|
|
246
|
+
export const systemLogger = defaultLogger.createComponentLogger('system');
|
|
247
|
+
export const authLogger = defaultLogger.createComponentLogger('auth');
|
|
248
|
+
export const perfLogger = defaultLogger.createComponentLogger('performance');
|
|
249
|
+
|
|
250
|
+
// Export utility functions (maintain backward compatibility)
|
|
251
|
+
export const createComponentLogger = (component: string) =>
|
|
252
|
+
defaultLogger.createComponentLogger(component);
|
|
253
|
+
|
|
254
|
+
export const logPerformance = (operation: string, startTime: number, meta?: any) =>
|
|
255
|
+
defaultLogger.logPerformance(operation, startTime, meta);
|
|
256
|
+
|
|
257
|
+
export const logExpress = (
|
|
258
|
+
method: string,
|
|
259
|
+
path: string,
|
|
260
|
+
statusCode: number,
|
|
261
|
+
startTime: number,
|
|
262
|
+
meta?: any
|
|
263
|
+
) => defaultLogger.logExpress(method, path, statusCode, startTime, meta);
|
|
264
|
+
|
|
265
|
+
export const logDatabaseOperation = (operation: string, table?: string, meta?: any) =>
|
|
266
|
+
defaultLogger.logDatabaseOperation(operation, table, meta);
|
|
267
|
+
|
|
268
|
+
export const logWebSocketEvent = (event: string, clientCount?: number, meta?: any) =>
|
|
269
|
+
defaultLogger.logWebSocketEvent(event, clientCount, meta);
|
|
270
|
+
|
|
271
|
+
export const logGraphQLQuery = (operation: string, query?: string, variables?: any) =>
|
|
272
|
+
defaultLogger.logGraphQLQuery(operation, query, variables);
|
|
273
|
+
|
|
274
|
+
// Default export (maintain backward compatibility)
|
|
275
|
+
export default defaultLogger.getPinoInstance();
|