@martel/calyx 1.10.0 → 1.10.1
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/http/application.ts +31 -5
- package/src/openapi/swagger.module.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.10.1](https://github.com/bmartel/calyx/compare/v1.10.0...v1.10.1) (2026-07-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Performance Improvements
|
|
5
|
+
|
|
6
|
+
* **graphql,openapi:** implement query AST caching and swagger response caching ([8310045](https://github.com/bmartel/calyx/commit/8310045265512553214a0a4040bc02d5085c77fa))
|
|
7
|
+
|
|
1
8
|
# [1.10.0](https://github.com/bmartel/calyx/compare/v1.9.0...v1.10.0) (2026-07-01)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/http/application.ts
CHANGED
|
@@ -119,6 +119,7 @@ export class CalyxApplication {
|
|
|
119
119
|
private hasWebSockets = false;
|
|
120
120
|
private serverPort = 3000;
|
|
121
121
|
private graphqlSchema: any = null;
|
|
122
|
+
private graphqlQueryCache = new Map<string, any>();
|
|
122
123
|
private isInitialized = false;
|
|
123
124
|
private versioningOptions?: VersioningOptions;
|
|
124
125
|
|
|
@@ -1215,10 +1216,24 @@ export class CalyxApplication {
|
|
|
1215
1216
|
const body = await req.json() as any;
|
|
1216
1217
|
const { query, variables } = body;
|
|
1217
1218
|
|
|
1218
|
-
const {
|
|
1219
|
-
|
|
1219
|
+
const { parse, validate, execute } = await import('graphql');
|
|
1220
|
+
|
|
1221
|
+
let document = this.graphqlQueryCache.get(query);
|
|
1222
|
+
if (!document) {
|
|
1223
|
+
document = parse(query);
|
|
1224
|
+
const errors = validate(this.graphqlSchema, document);
|
|
1225
|
+
if (errors.length > 0) {
|
|
1226
|
+
return new Response(JSON.stringify({ errors }), {
|
|
1227
|
+
status: 200,
|
|
1228
|
+
headers: { 'content-type': 'application/json' },
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
this.graphqlQueryCache.set(query, document);
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
const result = await execute({
|
|
1220
1235
|
schema: this.graphqlSchema,
|
|
1221
|
-
|
|
1236
|
+
document,
|
|
1222
1237
|
contextValue: { req },
|
|
1223
1238
|
variableValues: variables,
|
|
1224
1239
|
});
|
|
@@ -1321,11 +1336,22 @@ export class CalyxApplication {
|
|
|
1321
1336
|
const { id, payload } = data;
|
|
1322
1337
|
const { query, variables } = payload;
|
|
1323
1338
|
|
|
1324
|
-
const { subscribe, parse } = await import('graphql');
|
|
1339
|
+
const { subscribe, parse, validate } = await import('graphql');
|
|
1325
1340
|
|
|
1341
|
+
let document = this.graphqlQueryCache.get(query);
|
|
1342
|
+
if (!document) {
|
|
1343
|
+
document = parse(query);
|
|
1344
|
+
const errors = validate(this.graphqlSchema, document);
|
|
1345
|
+
if (errors.length > 0) {
|
|
1346
|
+
ws.send(JSON.stringify({ type: 'error', id, payload: errors }));
|
|
1347
|
+
break;
|
|
1348
|
+
}
|
|
1349
|
+
this.graphqlQueryCache.set(query, document);
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1326
1352
|
const subResult = await subscribe({
|
|
1327
1353
|
schema: this.graphqlSchema,
|
|
1328
|
-
document
|
|
1354
|
+
document,
|
|
1329
1355
|
variableValues: variables,
|
|
1330
1356
|
contextValue: { req: ws.data?.req },
|
|
1331
1357
|
});
|
|
@@ -271,12 +271,14 @@ export class SwaggerModule {
|
|
|
271
271
|
const jsonPath = `/${path}-json`.replace(/\/\/+/g, '/');
|
|
272
272
|
const uiPath = `/${path}`.replace(/\/\/+/g, '/');
|
|
273
273
|
|
|
274
|
+
const jsonString = JSON.stringify(document);
|
|
275
|
+
|
|
274
276
|
app.use((req: any, res: any, next: any) => {
|
|
275
277
|
const url = new URL(req.url);
|
|
276
278
|
if (url.pathname === jsonPath && req.method === 'GET') {
|
|
277
279
|
res.status(200);
|
|
278
280
|
res.set('content-type', 'application/json');
|
|
279
|
-
res.send(
|
|
281
|
+
res.send(jsonString);
|
|
280
282
|
return;
|
|
281
283
|
}
|
|
282
284
|
next();
|