sofa-api 0.10.2 → 0.11.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/README.md +9 -7
- package/express.d.ts +2 -2
- package/index.d.ts +3 -3
- package/{index.cjs.js → index.js} +40 -35
- package/{index.esm.js → index.mjs} +40 -35
- package/open-api/index.d.ts +3 -1
- package/package.json +19 -9
- package/sofa.d.ts +15 -5
- package/types.d.ts +0 -1
- package/index.cjs.js.map +0 -1
- package/index.esm.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://sofa-api.com)
|
|
1
|
+
[](https://www.sofa-api.com)
|
|
2
2
|
|
|
3
3
|
[](https://npmjs.com/package/sofa-api)
|
|
4
4
|
[](https://discord.gg/xud7bH9)
|
|
@@ -29,12 +29,12 @@ const invokeSofa = createSofaRouter({
|
|
|
29
29
|
|
|
30
30
|
const server = http.createServer(async (req, res) => {
|
|
31
31
|
try {
|
|
32
|
-
|
|
32
|
+
const response = await invokeSofa({
|
|
33
33
|
method: req.method,
|
|
34
34
|
url: req.url,
|
|
35
35
|
body: JSON.parse(await getStream(req)),
|
|
36
36
|
contextValue: {
|
|
37
|
-
req
|
|
37
|
+
req,
|
|
38
38
|
},
|
|
39
39
|
});
|
|
40
40
|
if (response) {
|
|
@@ -176,17 +176,17 @@ Whenever Sofa tries to resolve an author of a message, instead of exposing an ID
|
|
|
176
176
|
|
|
177
177
|
> Pattern is easy: `Type.field` or `Type`
|
|
178
178
|
|
|
179
|
-
### Customize endpoint's HTTP Method
|
|
179
|
+
### Customize endpoint's HTTP Method, path and response status code
|
|
180
180
|
|
|
181
|
-
Sofa allows you to cutomize the http method. For example, in case you need `POST` instead of `GET` method in one of your query, you do the following:
|
|
181
|
+
Sofa allows you to cutomize the http method, path and response status. For example, in case you need `POST` instead of `GET` method in one of your query, you do the following:
|
|
182
182
|
|
|
183
183
|
```typescript
|
|
184
184
|
api.use(
|
|
185
185
|
'/api',
|
|
186
186
|
sofa({
|
|
187
187
|
schema,
|
|
188
|
-
|
|
189
|
-
'Query.feed': 'POST',
|
|
188
|
+
routes: {
|
|
189
|
+
'Query.feed': { method: 'POST' },
|
|
190
190
|
},
|
|
191
191
|
})
|
|
192
192
|
);
|
|
@@ -196,6 +196,8 @@ When Sofa tries to define a route for `feed` of `Query`, instead of exposing it
|
|
|
196
196
|
|
|
197
197
|
> Pattern is easy: `Type.field` where `Type` is your query or mutation type.
|
|
198
198
|
|
|
199
|
+
You can also specify `path` with dynamic params support (for example `/feed/:offset/:limit`) and `responseStatus`.
|
|
200
|
+
|
|
199
201
|
### Custom depth limit
|
|
200
202
|
|
|
201
203
|
Sofa prevents circular references by default, but only one level deep. In order to change it, set the `depthLimit` option to any number:
|
package/express.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Sofa } from './sofa';
|
|
2
|
-
import { ContextValue } from './types';
|
|
1
|
+
import type { Sofa } from './sofa';
|
|
2
|
+
import type { ContextValue } from './types';
|
|
3
3
|
export declare type ErrorHandler = (errors: ReadonlyArray<any>) => RouterError;
|
|
4
4
|
declare type RouterRequest = {
|
|
5
5
|
method: string;
|
package/index.d.ts
CHANGED
|
@@ -24,8 +24,8 @@ export declare function createSofaRouter(config: SofaConfig): (request: {
|
|
|
24
24
|
method: string;
|
|
25
25
|
url: string;
|
|
26
26
|
body: any;
|
|
27
|
-
contextValue:
|
|
28
|
-
}) => Promise<{
|
|
27
|
+
contextValue: ContextValue;
|
|
28
|
+
}) => Promise<({
|
|
29
29
|
type: "result";
|
|
30
30
|
status: number;
|
|
31
31
|
statusMessage?: string | undefined;
|
|
@@ -35,4 +35,4 @@ export declare function createSofaRouter(config: SofaConfig): (request: {
|
|
|
35
35
|
status: number;
|
|
36
36
|
statusMessage?: string | undefined;
|
|
37
37
|
error: any;
|
|
38
|
-
} | null>;
|
|
38
|
+
}) | null>;
|
|
@@ -6,11 +6,11 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
6
6
|
|
|
7
7
|
const tslib = require('tslib');
|
|
8
8
|
const graphql = require('graphql');
|
|
9
|
-
const Trouter = require('trouter');
|
|
9
|
+
const Trouter = _interopDefault(require('trouter'));
|
|
10
10
|
const utils = require('@graphql-tools/utils');
|
|
11
11
|
const paramCase = require('param-case');
|
|
12
12
|
const uuid = require('uuid');
|
|
13
|
-
const
|
|
13
|
+
const crossUndiciFetch = require('cross-undici-fetch');
|
|
14
14
|
const colors = require('ansi-colors');
|
|
15
15
|
const jsYaml = require('js-yaml');
|
|
16
16
|
const fs = require('fs');
|
|
@@ -62,7 +62,7 @@ function resolveVariable({ value, type, schema, }) {
|
|
|
62
62
|
return value;
|
|
63
63
|
}
|
|
64
64
|
if (type.kind === graphql.Kind.LIST_TYPE) {
|
|
65
|
-
return value.map(val => resolveVariable({
|
|
65
|
+
return (Array.isArray(value) ? value : [value]).map(val => resolveVariable({
|
|
66
66
|
value: val,
|
|
67
67
|
type: type.type,
|
|
68
68
|
schema,
|
|
@@ -236,7 +236,14 @@ class SubscriptionManager {
|
|
|
236
236
|
}
|
|
237
237
|
const { url } = this.clients.get(id);
|
|
238
238
|
logger.info(`[Subscription] Trigger ${id}`);
|
|
239
|
-
yield
|
|
239
|
+
const response = yield crossUndiciFetch.fetch(url, {
|
|
240
|
+
method: 'POST',
|
|
241
|
+
body: JSON.stringify(result),
|
|
242
|
+
headers: {
|
|
243
|
+
'Content-Type': 'application/json',
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
yield response.text();
|
|
240
247
|
});
|
|
241
248
|
}
|
|
242
249
|
buildOperations() {
|
|
@@ -378,6 +385,7 @@ function createRouter(sofa) {
|
|
|
378
385
|
});
|
|
379
386
|
}
|
|
380
387
|
function createQueryRoute({ sofa, router, fieldName, }) {
|
|
388
|
+
var _a, _b, _c, _d;
|
|
381
389
|
logger.debug(`[Router] Creating ${fieldName} query`);
|
|
382
390
|
const queryType = sofa.schema.getQueryType();
|
|
383
391
|
const operationNode = utils.buildOperationNodeForField({
|
|
@@ -398,22 +406,23 @@ function createQueryRoute({ sofa, router, fieldName, }) {
|
|
|
398
406
|
const isSingle = graphql.isObjectType(fieldType) ||
|
|
399
407
|
(graphql.isNonNullType(fieldType) && graphql.isObjectType(fieldType.ofType));
|
|
400
408
|
const hasIdArgument = field.args.some((arg) => arg.name === 'id');
|
|
401
|
-
const
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
router[method.toLocaleLowerCase()](path, useHandler({ info, fieldName, sofa, operation }));
|
|
409
|
-
logger.debug(`[Router] ${fieldName} query available at ${method} ${path}`);
|
|
409
|
+
const graphqlPath = `${queryType.name}.${fieldName}`;
|
|
410
|
+
const routeConfig = (_a = sofa.routes) === null || _a === void 0 ? void 0 : _a[graphqlPath];
|
|
411
|
+
const route = {
|
|
412
|
+
method: (_b = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.method) !== null && _b !== void 0 ? _b : 'GET',
|
|
413
|
+
path: (_c = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path) !== null && _c !== void 0 ? _c : getPath(fieldName, isSingle && hasIdArgument),
|
|
414
|
+
responseStatus: (_d = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.responseStatus) !== null && _d !== void 0 ? _d : 200,
|
|
415
|
+
};
|
|
416
|
+
router[route.method.toLocaleLowerCase()](route.path, useHandler({ info, route, fieldName, sofa, operation }));
|
|
417
|
+
logger.debug(`[Router] ${fieldName} query available at ${route.method} ${route.path}`);
|
|
410
418
|
return {
|
|
411
419
|
document: operation,
|
|
412
|
-
path,
|
|
413
|
-
method: method.toUpperCase(),
|
|
420
|
+
path: route.path,
|
|
421
|
+
method: route.method.toUpperCase(),
|
|
414
422
|
};
|
|
415
423
|
}
|
|
416
424
|
function createMutationRoute({ sofa, router, fieldName, }) {
|
|
425
|
+
var _a, _b, _c, _d;
|
|
417
426
|
logger.debug(`[Router] Creating ${fieldName} mutation`);
|
|
418
427
|
const mutationType = sofa.schema.getMutationType();
|
|
419
428
|
const operationNode = utils.buildOperationNodeForField({
|
|
@@ -429,19 +438,20 @@ function createMutationRoute({ sofa, router, fieldName, }) {
|
|
|
429
438
|
definitions: [operationNode],
|
|
430
439
|
};
|
|
431
440
|
const info = getOperationInfo(operation);
|
|
432
|
-
const
|
|
433
|
-
const
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
|
|
441
|
+
const graphqlPath = `${mutationType.name}.${fieldName}`;
|
|
442
|
+
const routeConfig = (_a = sofa.routes) === null || _a === void 0 ? void 0 : _a[graphqlPath];
|
|
443
|
+
const route = {
|
|
444
|
+
method: (_b = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.method) !== null && _b !== void 0 ? _b : 'POST',
|
|
445
|
+
path: (_c = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path) !== null && _c !== void 0 ? _c : getPath(fieldName),
|
|
446
|
+
responseStatus: (_d = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.responseStatus) !== null && _d !== void 0 ? _d : 200,
|
|
447
|
+
};
|
|
448
|
+
const { method, path } = route;
|
|
449
|
+
router[method.toLowerCase()](path, useHandler({ info, route, fieldName, sofa, operation }));
|
|
440
450
|
logger.debug(`[Router] ${fieldName} mutation available at ${method} ${path}`);
|
|
441
451
|
return {
|
|
442
452
|
document: operation,
|
|
443
453
|
path,
|
|
444
|
-
method
|
|
454
|
+
method,
|
|
445
455
|
};
|
|
446
456
|
}
|
|
447
457
|
function useHandler(config) {
|
|
@@ -480,7 +490,7 @@ function useHandler(config) {
|
|
|
480
490
|
}
|
|
481
491
|
return {
|
|
482
492
|
type: 'result',
|
|
483
|
-
status:
|
|
493
|
+
status: config.route.responseStatus,
|
|
484
494
|
body: result.data && result.data[fieldName],
|
|
485
495
|
};
|
|
486
496
|
});
|
|
@@ -494,18 +504,12 @@ function pickParam({ name, url, params, body, }) {
|
|
|
494
504
|
}
|
|
495
505
|
const searchParams = new URLSearchParams(url.split('?')[1]);
|
|
496
506
|
if (searchParams.has(name)) {
|
|
497
|
-
|
|
507
|
+
const values = searchParams.getAll(name);
|
|
508
|
+
return values.length === 1 ? values[0] : values;
|
|
498
509
|
}
|
|
499
510
|
if (body && body.hasOwnProperty(name)) {
|
|
500
511
|
return body[name];
|
|
501
512
|
}
|
|
502
|
-
}
|
|
503
|
-
function produceMethod({ typeName, fieldName, methodMap, defaultValue, }) {
|
|
504
|
-
const path = `${typeName}.${fieldName}`;
|
|
505
|
-
if (methodMap && methodMap[path]) {
|
|
506
|
-
return methodMap[path];
|
|
507
|
-
}
|
|
508
|
-
return defaultValue;
|
|
509
513
|
}
|
|
510
514
|
|
|
511
515
|
function createSofa(config) {
|
|
@@ -784,11 +788,13 @@ function isObjectTypeDefinitionNode(node) {
|
|
|
784
788
|
return node.kind === graphql.Kind.OBJECT_TYPE_DEFINITION;
|
|
785
789
|
}
|
|
786
790
|
|
|
787
|
-
function OpenAPI({ schema, info, components, security, }) {
|
|
791
|
+
function OpenAPI({ schema, info, servers, components, security, tags, }) {
|
|
788
792
|
const types = schema.getTypeMap();
|
|
789
793
|
const swagger = {
|
|
790
794
|
openapi: '3.0.0',
|
|
791
795
|
info,
|
|
796
|
+
servers,
|
|
797
|
+
tags,
|
|
792
798
|
paths: {},
|
|
793
799
|
components: {
|
|
794
800
|
schemas: {},
|
|
@@ -906,4 +912,3 @@ exports.OpenAPI = OpenAPI;
|
|
|
906
912
|
exports.createSofaRouter = createSofaRouter;
|
|
907
913
|
exports.isContextFn = isContextFn;
|
|
908
914
|
exports.useSofa = useSofa;
|
|
909
|
-
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __awaiter, __asyncValues, __rest } from 'tslib';
|
|
2
2
|
import { getOperationAST, Kind, isScalarType, isEqualType, GraphQLBoolean, isInputObjectType, subscribe, isObjectType, isNonNullType, print, graphql, getNamedType, isListType, isEnumType, parse, printType, isIntrospectionType } from 'graphql';
|
|
3
|
-
import
|
|
3
|
+
import Trouter from 'trouter';
|
|
4
4
|
import { buildOperationNodeForField } from '@graphql-tools/utils';
|
|
5
5
|
import { paramCase } from 'param-case';
|
|
6
6
|
import { v4 } from 'uuid';
|
|
7
|
-
import
|
|
7
|
+
import { fetch } from 'cross-undici-fetch';
|
|
8
8
|
import { red, yellow, green, blue } from 'ansi-colors';
|
|
9
9
|
import { dump } from 'js-yaml';
|
|
10
10
|
import { writeFileSync } from 'fs';
|
|
@@ -56,7 +56,7 @@ function resolveVariable({ value, type, schema, }) {
|
|
|
56
56
|
return value;
|
|
57
57
|
}
|
|
58
58
|
if (type.kind === Kind.LIST_TYPE) {
|
|
59
|
-
return value.map(val => resolveVariable({
|
|
59
|
+
return (Array.isArray(value) ? value : [value]).map(val => resolveVariable({
|
|
60
60
|
value: val,
|
|
61
61
|
type: type.type,
|
|
62
62
|
schema,
|
|
@@ -230,7 +230,14 @@ class SubscriptionManager {
|
|
|
230
230
|
}
|
|
231
231
|
const { url } = this.clients.get(id);
|
|
232
232
|
logger.info(`[Subscription] Trigger ${id}`);
|
|
233
|
-
yield
|
|
233
|
+
const response = yield fetch(url, {
|
|
234
|
+
method: 'POST',
|
|
235
|
+
body: JSON.stringify(result),
|
|
236
|
+
headers: {
|
|
237
|
+
'Content-Type': 'application/json',
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
yield response.text();
|
|
234
241
|
});
|
|
235
242
|
}
|
|
236
243
|
buildOperations() {
|
|
@@ -372,6 +379,7 @@ function createRouter(sofa) {
|
|
|
372
379
|
});
|
|
373
380
|
}
|
|
374
381
|
function createQueryRoute({ sofa, router, fieldName, }) {
|
|
382
|
+
var _a, _b, _c, _d;
|
|
375
383
|
logger.debug(`[Router] Creating ${fieldName} query`);
|
|
376
384
|
const queryType = sofa.schema.getQueryType();
|
|
377
385
|
const operationNode = buildOperationNodeForField({
|
|
@@ -392,22 +400,23 @@ function createQueryRoute({ sofa, router, fieldName, }) {
|
|
|
392
400
|
const isSingle = isObjectType(fieldType) ||
|
|
393
401
|
(isNonNullType(fieldType) && isObjectType(fieldType.ofType));
|
|
394
402
|
const hasIdArgument = field.args.some((arg) => arg.name === 'id');
|
|
395
|
-
const
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
router[method.toLocaleLowerCase()](path, useHandler({ info, fieldName, sofa, operation }));
|
|
403
|
-
logger.debug(`[Router] ${fieldName} query available at ${method} ${path}`);
|
|
403
|
+
const graphqlPath = `${queryType.name}.${fieldName}`;
|
|
404
|
+
const routeConfig = (_a = sofa.routes) === null || _a === void 0 ? void 0 : _a[graphqlPath];
|
|
405
|
+
const route = {
|
|
406
|
+
method: (_b = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.method) !== null && _b !== void 0 ? _b : 'GET',
|
|
407
|
+
path: (_c = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path) !== null && _c !== void 0 ? _c : getPath(fieldName, isSingle && hasIdArgument),
|
|
408
|
+
responseStatus: (_d = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.responseStatus) !== null && _d !== void 0 ? _d : 200,
|
|
409
|
+
};
|
|
410
|
+
router[route.method.toLocaleLowerCase()](route.path, useHandler({ info, route, fieldName, sofa, operation }));
|
|
411
|
+
logger.debug(`[Router] ${fieldName} query available at ${route.method} ${route.path}`);
|
|
404
412
|
return {
|
|
405
413
|
document: operation,
|
|
406
|
-
path,
|
|
407
|
-
method: method.toUpperCase(),
|
|
414
|
+
path: route.path,
|
|
415
|
+
method: route.method.toUpperCase(),
|
|
408
416
|
};
|
|
409
417
|
}
|
|
410
418
|
function createMutationRoute({ sofa, router, fieldName, }) {
|
|
419
|
+
var _a, _b, _c, _d;
|
|
411
420
|
logger.debug(`[Router] Creating ${fieldName} mutation`);
|
|
412
421
|
const mutationType = sofa.schema.getMutationType();
|
|
413
422
|
const operationNode = buildOperationNodeForField({
|
|
@@ -423,19 +432,20 @@ function createMutationRoute({ sofa, router, fieldName, }) {
|
|
|
423
432
|
definitions: [operationNode],
|
|
424
433
|
};
|
|
425
434
|
const info = getOperationInfo(operation);
|
|
426
|
-
const
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
|
|
435
|
+
const graphqlPath = `${mutationType.name}.${fieldName}`;
|
|
436
|
+
const routeConfig = (_a = sofa.routes) === null || _a === void 0 ? void 0 : _a[graphqlPath];
|
|
437
|
+
const route = {
|
|
438
|
+
method: (_b = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.method) !== null && _b !== void 0 ? _b : 'POST',
|
|
439
|
+
path: (_c = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path) !== null && _c !== void 0 ? _c : getPath(fieldName),
|
|
440
|
+
responseStatus: (_d = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.responseStatus) !== null && _d !== void 0 ? _d : 200,
|
|
441
|
+
};
|
|
442
|
+
const { method, path } = route;
|
|
443
|
+
router[method.toLowerCase()](path, useHandler({ info, route, fieldName, sofa, operation }));
|
|
434
444
|
logger.debug(`[Router] ${fieldName} mutation available at ${method} ${path}`);
|
|
435
445
|
return {
|
|
436
446
|
document: operation,
|
|
437
447
|
path,
|
|
438
|
-
method
|
|
448
|
+
method,
|
|
439
449
|
};
|
|
440
450
|
}
|
|
441
451
|
function useHandler(config) {
|
|
@@ -474,7 +484,7 @@ function useHandler(config) {
|
|
|
474
484
|
}
|
|
475
485
|
return {
|
|
476
486
|
type: 'result',
|
|
477
|
-
status:
|
|
487
|
+
status: config.route.responseStatus,
|
|
478
488
|
body: result.data && result.data[fieldName],
|
|
479
489
|
};
|
|
480
490
|
});
|
|
@@ -488,18 +498,12 @@ function pickParam({ name, url, params, body, }) {
|
|
|
488
498
|
}
|
|
489
499
|
const searchParams = new URLSearchParams(url.split('?')[1]);
|
|
490
500
|
if (searchParams.has(name)) {
|
|
491
|
-
|
|
501
|
+
const values = searchParams.getAll(name);
|
|
502
|
+
return values.length === 1 ? values[0] : values;
|
|
492
503
|
}
|
|
493
504
|
if (body && body.hasOwnProperty(name)) {
|
|
494
505
|
return body[name];
|
|
495
506
|
}
|
|
496
|
-
}
|
|
497
|
-
function produceMethod({ typeName, fieldName, methodMap, defaultValue, }) {
|
|
498
|
-
const path = `${typeName}.${fieldName}`;
|
|
499
|
-
if (methodMap && methodMap[path]) {
|
|
500
|
-
return methodMap[path];
|
|
501
|
-
}
|
|
502
|
-
return defaultValue;
|
|
503
507
|
}
|
|
504
508
|
|
|
505
509
|
function createSofa(config) {
|
|
@@ -778,11 +782,13 @@ function isObjectTypeDefinitionNode(node) {
|
|
|
778
782
|
return node.kind === Kind.OBJECT_TYPE_DEFINITION;
|
|
779
783
|
}
|
|
780
784
|
|
|
781
|
-
function OpenAPI({ schema, info, components, security, }) {
|
|
785
|
+
function OpenAPI({ schema, info, servers, components, security, tags, }) {
|
|
782
786
|
const types = schema.getTypeMap();
|
|
783
787
|
const swagger = {
|
|
784
788
|
openapi: '3.0.0',
|
|
785
789
|
info,
|
|
790
|
+
servers,
|
|
791
|
+
tags,
|
|
786
792
|
paths: {},
|
|
787
793
|
components: {
|
|
788
794
|
schemas: {},
|
|
@@ -897,4 +903,3 @@ function createSofaRouter(config) {
|
|
|
897
903
|
}
|
|
898
904
|
|
|
899
905
|
export { OpenAPI, createSofaRouter, isContextFn, useSofa };
|
|
900
|
-
//# sourceMappingURL=index.esm.js.map
|
package/open-api/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
2
|
import { RouteInfo } from '../types';
|
|
3
|
-
export declare function OpenAPI({ schema, info, components, security, }: {
|
|
3
|
+
export declare function OpenAPI({ schema, info, servers, components, security, tags, }: {
|
|
4
4
|
schema: GraphQLSchema;
|
|
5
5
|
info: Record<string, any>;
|
|
6
|
+
servers?: Record<string, any>[];
|
|
6
7
|
components?: Record<string, any>;
|
|
7
8
|
security?: Record<string, any>[];
|
|
9
|
+
tags?: Record<string, any>[];
|
|
8
10
|
}): {
|
|
9
11
|
addRoute(info: RouteInfo, config?: {
|
|
10
12
|
basePath?: string | undefined;
|
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sofa-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Create REST APIs with GraphQL",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^0.13.2 || ^14.0.0 || ^15.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/utils": "
|
|
11
|
-
"@types/js-yaml": "4.0.
|
|
10
|
+
"@graphql-tools/utils": "8.1.1",
|
|
11
|
+
"@types/js-yaml": "4.0.2",
|
|
12
12
|
"ansi-colors": "4.1.1",
|
|
13
|
-
"
|
|
14
|
-
"js-yaml": "4.
|
|
13
|
+
"cross-undici-fetch": "0.1.28",
|
|
14
|
+
"js-yaml": "4.1.0",
|
|
15
15
|
"param-case": "3.0.4",
|
|
16
16
|
"title-case": "3.0.3",
|
|
17
|
-
"trouter": "3.
|
|
18
|
-
"tslib": "2.1
|
|
17
|
+
"trouter": "3.2.0",
|
|
18
|
+
"tslib": "2.3.1",
|
|
19
19
|
"uuid": "8.3.2"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
@@ -34,10 +34,20 @@
|
|
|
34
34
|
"url": "https://github.com/Urigo"
|
|
35
35
|
},
|
|
36
36
|
"license": "MIT",
|
|
37
|
-
"main": "index.
|
|
38
|
-
"module": "index.
|
|
37
|
+
"main": "index.js",
|
|
38
|
+
"module": "index.mjs",
|
|
39
39
|
"typings": "index.d.ts",
|
|
40
40
|
"typescript": {
|
|
41
41
|
"definition": "index.d.ts"
|
|
42
|
+
},
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"require": "./index.js",
|
|
46
|
+
"import": "./index.mjs"
|
|
47
|
+
},
|
|
48
|
+
"./*": {
|
|
49
|
+
"require": "./*.js",
|
|
50
|
+
"import": "./*.mjs"
|
|
51
|
+
}
|
|
42
52
|
}
|
|
43
53
|
}
|
package/sofa.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import { Ignore, ExecuteFn, OnRoute,
|
|
2
|
+
import { Ignore, ExecuteFn, OnRoute, Method } from './types';
|
|
3
3
|
import { ErrorHandler } from './express';
|
|
4
|
+
interface RouteConfig {
|
|
5
|
+
method?: Method;
|
|
6
|
+
path?: string;
|
|
7
|
+
responseStatus?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface Route {
|
|
10
|
+
method: Method;
|
|
11
|
+
path: string;
|
|
12
|
+
responseStatus: number;
|
|
13
|
+
}
|
|
4
14
|
export interface SofaConfig {
|
|
5
15
|
basePath: string;
|
|
6
16
|
schema: GraphQLSchema;
|
|
@@ -14,10 +24,9 @@ export interface SofaConfig {
|
|
|
14
24
|
depthLimit?: number;
|
|
15
25
|
errorHandler?: ErrorHandler;
|
|
16
26
|
/**
|
|
17
|
-
* Overwrites the default HTTP
|
|
18
|
-
* @example {"Query.field": "GET", "Mutation.field": "POST"}
|
|
27
|
+
* Overwrites the default HTTP route.
|
|
19
28
|
*/
|
|
20
|
-
|
|
29
|
+
routes?: Record<string, RouteConfig>;
|
|
21
30
|
}
|
|
22
31
|
export interface Sofa {
|
|
23
32
|
basePath: string;
|
|
@@ -25,9 +34,10 @@ export interface Sofa {
|
|
|
25
34
|
models: string[];
|
|
26
35
|
ignore: Ignore;
|
|
27
36
|
depthLimit: number;
|
|
28
|
-
|
|
37
|
+
routes?: Record<string, RouteConfig>;
|
|
29
38
|
execute: ExecuteFn;
|
|
30
39
|
onRoute?: OnRoute;
|
|
31
40
|
errorHandler?: ErrorHandler;
|
|
32
41
|
}
|
|
33
42
|
export declare function createSofa(config: SofaConfig): Sofa;
|
|
43
|
+
export {};
|
package/types.d.ts
CHANGED
package/index.cjs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/ast.ts","../src/common.ts","../src/parse.ts","../src/logger.ts","../src/subscriptions.ts","../src/express.ts","../src/sofa.ts","../src/open-api/utils.ts","../src/open-api/types.ts","../src/open-api/operations.ts","../src/open-api/index.ts","../src/index.ts"],"sourcesContent":["import {\n getOperationAST,\n DocumentNode,\n OperationDefinitionNode,\n VariableDefinitionNode,\n} from 'graphql';\n\nexport type OperationInfo =\n | {\n operation: OperationDefinitionNode;\n variables: ReadonlyArray<VariableDefinitionNode>;\n name: string;\n }\n | undefined;\n\nexport function getOperationInfo(doc: DocumentNode): OperationInfo {\n const op = getOperationAST(doc, null);\n\n if (!op) {\n return;\n }\n\n return {\n operation: op,\n name: op.name!.value,\n variables: op.variableDefinitions || [],\n };\n}\n","import { paramCase } from 'param-case';\n\nexport function convertName(name: string) {\n return paramCase(name);\n}\n\nexport function isNil<T>(val: T) {\n return val == null;\n}\n","import {\n VariableDefinitionNode,\n GraphQLSchema,\n TypeNode,\n isScalarType,\n isEqualType,\n GraphQLBoolean,\n isInputObjectType,\n Kind,\n} from 'graphql';\nimport { isNil } from './common';\n\nexport function parseVariable({\n value,\n variable,\n schema,\n}: {\n value: any;\n variable: VariableDefinitionNode;\n schema: GraphQLSchema;\n}) {\n if (isNil(value)) {\n return;\n }\n\n return resolveVariable({\n value,\n type: variable.type,\n schema,\n });\n}\n\nfunction resolveVariable({\n value,\n type,\n schema,\n}: {\n value: any;\n type: TypeNode;\n schema: GraphQLSchema;\n}): any | any[] {\n if (type.kind === Kind.NAMED_TYPE) {\n const namedType = schema.getType(type.name.value);\n\n if (isScalarType(namedType)) {\n // GraphQLBoolean.serialize expects a boolean or a number only\n if (isEqualType(GraphQLBoolean, namedType)) {\n // we don't support TRUE\n value = value === 'true';\n }\n\n return namedType.serialize(value);\n }\n\n if (isInputObjectType(namedType)) {\n return value && typeof value === 'object' ? value : JSON.parse(value);\n }\n\n return value;\n }\n\n if (type.kind === Kind.LIST_TYPE) {\n return (value as any[]).map(val =>\n resolveVariable({\n value: val,\n type: type.type,\n schema,\n })\n );\n }\n\n if (type.kind === Kind.NON_NULL_TYPE) {\n return resolveVariable({\n value: value,\n type: type.type,\n schema,\n });\n }\n}\n","import * as colors from 'ansi-colors';\n\ntype Level = 'error' | 'warn' | 'info' | 'debug';\n\nconst levels: Level[] = ['error', 'warn', 'info', 'debug'];\n\nconst toLevel = (string: void | string) =>\n levels.includes(string as Level) ? (string as Level) : null;\n\nconst currentLevel: Level = process.env.SOFA_DEBUG\n ? 'debug'\n : toLevel(process.env.SOFA_LOGGER_LEVEL) ?? 'info';\n\nconst log = (level: Level, color: any, args: any[]) => {\n if (levels.indexOf(level) <= levels.indexOf(currentLevel)) {\n console.log(`${color(level)}:`, ...args);\n }\n};\n\nexport const logger = {\n error: (...args: any[]) => {\n log('error', colors.red, args);\n },\n warn: (...args: any[]) => {\n log('warn', colors.yellow, args);\n },\n info: (...args: any[]) => {\n log('info', colors.green, args);\n },\n debug: (...args: any[]) => {\n log('debug', colors.blue, args);\n },\n};\n","import {\n subscribe,\n DocumentNode,\n VariableDefinitionNode,\n ExecutionResult,\n Kind,\n} from 'graphql';\nimport { v4 as uuid } from 'uuid';\nimport axios from 'axios';\nimport { buildOperationNodeForField } from '@graphql-tools/utils';\nimport type { ContextValue } from './types';\nimport type { Sofa } from './sofa';\nimport { getOperationInfo } from './ast';\nimport { parseVariable } from './parse';\nimport { logger } from './logger';\n\nfunction isAsyncIterable(obj: any): obj is AsyncIterable<any> {\n return typeof obj[Symbol.asyncIterator] === 'function';\n}\n\n// To start subscription:\n// - an url that Sofa should trigger\n// - name of a subscription\n// - variables if needed\n// - some sort of an auth token\n// - Sofa should return a unique id of that subscription\n// - respond with OK 200\n\n// To stop subscription\n// - an id is required\n// - respond with OK 200\n\n// To update subscription\n// - an id is required\n// - new set of variables\n\nexport type ID = string;\nexport type SubscriptionFieldName = string;\n\nexport interface StartSubscriptionEvent {\n subscription: SubscriptionFieldName;\n variables: any;\n url: string;\n}\n\nexport interface UpdateSubscriptionEvent {\n id: ID;\n variables: any;\n}\n\nexport interface StopSubscriptionResponse {\n id: ID;\n}\n\ninterface BuiltOperation {\n operationName: string;\n document: DocumentNode;\n variables: ReadonlyArray<VariableDefinitionNode>;\n}\n\ninterface StoredClient {\n name: SubscriptionFieldName;\n url: string;\n iterator: AsyncIterator<any>;\n}\n\nexport class SubscriptionManager {\n private operations = new Map<SubscriptionFieldName, BuiltOperation>();\n private clients = new Map<ID, StoredClient>();\n\n constructor(private sofa: Sofa) {\n this.buildOperations();\n }\n\n public async start(\n event: StartSubscriptionEvent,\n contextValue: ContextValue\n ) {\n const id = uuid();\n const name = event.subscription;\n\n if (!this.operations.has(name)) {\n throw new Error(`Subscription '${name}' is not available`);\n }\n\n const { document, operationName, variables } = this.operations.get(name)!;\n\n logger.info(`[Subscription] Start ${id}`, event);\n\n const result = await this.execute({\n id,\n name,\n url: event.url,\n document,\n operationName,\n variables,\n contextValue,\n });\n\n if (typeof result !== 'undefined') {\n return result;\n }\n\n return { id };\n }\n\n public async stop(id: ID): Promise<StopSubscriptionResponse> {\n logger.info(`[Subscription] Stop ${id}`);\n\n if (!this.clients.has(id)) {\n throw new Error(`Subscription with ID '${id}' does not exist`);\n }\n\n const execution = this.clients.get(id)!;\n\n if (execution.iterator.return) {\n execution.iterator.return();\n }\n\n this.clients.delete(id);\n\n return { id };\n }\n\n public async update(\n event: UpdateSubscriptionEvent,\n contextValue: ContextValue\n ) {\n const { variables, id } = event;\n\n logger.info(`[Subscription] Update ${id}`, event);\n\n if (!this.clients.has(id)) {\n throw new Error(`Subscription with ID '${id}' does not exist`);\n }\n\n const { name: subscription, url } = this.clients.get(id)!;\n\n this.stop(id);\n\n return this.start(\n {\n url,\n subscription,\n variables,\n },\n contextValue\n );\n }\n\n private async execute({\n id,\n document,\n name,\n url,\n operationName,\n variables,\n contextValue,\n }: {\n id: ID;\n name: SubscriptionFieldName;\n url: string;\n document: DocumentNode;\n operationName: string;\n variables: Record<string, any>;\n contextValue: ContextValue;\n }) {\n const variableNodes = this.operations.get(name)!.variables;\n const variableValues = variableNodes.reduce((values, variable) => {\n const value = parseVariable({\n value: variables[variable.variable.name.value],\n variable,\n schema: this.sofa.schema,\n });\n\n if (typeof value === 'undefined') {\n return values;\n }\n\n return {\n ...values,\n [name]: value,\n };\n }, {});\n\n const execution = await subscribe({\n schema: this.sofa.schema,\n document,\n operationName,\n variableValues,\n contextValue,\n });\n\n if (isAsyncIterable(execution)) {\n // successful\n\n // add execution to clients\n this.clients.set(id, {\n name,\n url,\n iterator: execution as any,\n });\n\n // success\n (async () => {\n for await (const result of execution) {\n await this.sendData({\n id,\n result,\n });\n }\n })().then(\n () => {\n // completes\n this.clients.delete(id);\n },\n (e) => {\n logger.info(`Subscription #${id} closed`);\n logger.error(e);\n this.clients.delete(id);\n }\n );\n } else {\n return execution as ExecutionResult;\n }\n }\n\n private async sendData({ id, result }: { id: ID; result: any }) {\n if (!this.clients.has(id)) {\n throw new Error(`Subscription with ID '${id}' does not exist`);\n }\n\n const { url } = this.clients.get(id)!;\n\n logger.info(`[Subscription] Trigger ${id}`);\n\n await axios.post(url, result);\n }\n\n private buildOperations() {\n const subscription = this.sofa.schema.getSubscriptionType();\n\n if (!subscription) {\n return;\n }\n\n const fieldMap = subscription.getFields();\n\n for (const field in fieldMap) {\n const operationNode = buildOperationNodeForField({\n kind: 'subscription',\n field,\n schema: this.sofa.schema,\n models: this.sofa.models,\n ignore: this.sofa.ignore,\n circularReferenceDepth: this.sofa.depthLimit,\n });\n const document: DocumentNode = {\n kind: Kind.DOCUMENT,\n definitions: [operationNode],\n };\n\n const { variables, name: operationName } = getOperationInfo(document)!;\n\n this.operations.set(field, {\n operationName,\n document,\n variables,\n });\n }\n }\n}\n","import {\n DocumentNode,\n print,\n isObjectType,\n isNonNullType,\n Kind,\n} from 'graphql';\nimport * as Trouter from 'trouter';\nimport { buildOperationNodeForField } from '@graphql-tools/utils';\nimport { getOperationInfo, OperationInfo } from './ast';\nimport { Sofa } from './sofa';\nimport { RouteInfo, Method, MethodMap, ContextValue } from './types';\nimport { convertName } from './common';\nimport { parseVariable } from './parse';\nimport { StartSubscriptionEvent, SubscriptionManager } from './subscriptions';\nimport { logger } from './logger';\n\nexport type ErrorHandler = (errors: ReadonlyArray<any>) => RouterError;\n\ntype Params = { [key: string]: string };\n\ntype TrouterMethod = 'get' | 'post' | 'put' | 'delete' | 'patch';\n\ntype RouterRequest = {\n method: string;\n url: string;\n body: any;\n contextValue: ContextValue;\n};\ntype RouterResult = {\n type: 'result';\n status: number;\n statusMessage?: string;\n body: any;\n};\ntype RouterError = {\n type: 'error';\n status: number;\n statusMessage?: string;\n error: any;\n};\ntype RouterResponse = RouterResult | RouterError;\ntype Router = (request: RouterRequest) => Promise<null | RouterResponse>;\n\ntype RouteRequest = {\n url: string;\n body: any;\n params: Params;\n contextValue: ContextValue;\n};\ntype RouteMiddleware = (request: RouteRequest) => Promise<RouterResponse>;\n\nexport function createRouter(sofa: Sofa): Router {\n logger.debug('[Sofa] Creating router');\n\n const router = new Trouter<RouteMiddleware>();\n\n const queryType = sofa.schema.getQueryType();\n const mutationType = sofa.schema.getMutationType();\n const subscriptionManager = new SubscriptionManager(sofa);\n\n if (queryType) {\n Object.keys(queryType.getFields()).forEach((fieldName) => {\n const route = createQueryRoute({ sofa, router, fieldName });\n\n if (sofa.onRoute) {\n sofa.onRoute(route);\n }\n });\n }\n\n if (mutationType) {\n Object.keys(mutationType.getFields()).forEach((fieldName) => {\n const route = createMutationRoute({ sofa, router, fieldName });\n\n if (sofa.onRoute) {\n sofa.onRoute(route);\n }\n });\n }\n\n router.post('/webhook', async ({ body, contextValue }) => {\n const { subscription, variables, url }: StartSubscriptionEvent = body;\n try {\n const result = await subscriptionManager.start(\n {\n subscription,\n variables,\n url,\n },\n contextValue\n );\n return {\n type: 'result',\n status: 200,\n statusMessage: 'OK',\n body: result,\n };\n } catch (error) {\n return {\n type: 'error',\n status: 500,\n statusMessage: 'Subscription failed',\n error,\n };\n }\n });\n\n router.post('/webhook/:id', async ({ body, params, contextValue }) => {\n const id: string = params.id;\n const variables: any = body.variables;\n try {\n const result = await subscriptionManager.update(\n {\n id,\n variables,\n },\n contextValue\n );\n return {\n type: 'result',\n status: 200,\n statusMessage: 'OK',\n body: result,\n };\n } catch (error) {\n return {\n type: 'error',\n status: 500,\n statusMessage: 'Subscription failed to update',\n error,\n };\n }\n });\n\n router.delete('/webhook/:id', async ({ params }) => {\n const id: string = params.id;\n try {\n const result = await subscriptionManager.stop(id);\n return {\n type: 'result',\n status: 200,\n statusMessage: 'OK',\n body: result,\n };\n } catch (error) {\n return {\n type: 'error',\n status: 500,\n statusMessage: 'Subscription failed to stop',\n error,\n };\n }\n });\n\n return async ({ method, url, body, contextValue }) => {\n if (!url.startsWith(sofa.basePath)) {\n return null;\n }\n // trim base path and search\n const [slicedUrl] = url.slice(sofa.basePath.length).split('?');\n const trouterMethod = method.toUpperCase() as Trouter.HTTPMethod;\n const obj = router.find(trouterMethod, slicedUrl);\n for (const handler of obj.handlers) {\n return await handler({\n url,\n body,\n params: obj.params,\n contextValue,\n });\n }\n return null;\n };\n}\n\nfunction createQueryRoute({\n sofa,\n router,\n fieldName,\n}: {\n sofa: Sofa;\n router: Trouter;\n fieldName: string;\n}): RouteInfo {\n logger.debug(`[Router] Creating ${fieldName} query`);\n\n const queryType = sofa.schema.getQueryType()!;\n const operationNode = buildOperationNodeForField({\n kind: 'query',\n schema: sofa.schema,\n field: fieldName,\n models: sofa.models,\n ignore: sofa.ignore,\n circularReferenceDepth: sofa.depthLimit,\n });\n const operation: DocumentNode = {\n kind: Kind.DOCUMENT,\n definitions: [operationNode],\n };\n const info = getOperationInfo(operation)!;\n const field = queryType.getFields()[fieldName];\n const fieldType = field.type;\n const isSingle =\n isObjectType(fieldType) ||\n (isNonNullType(fieldType) && isObjectType(fieldType.ofType));\n const hasIdArgument = field.args.some((arg) => arg.name === 'id');\n const path = getPath(fieldName, isSingle && hasIdArgument);\n\n const method = produceMethod({\n typeName: queryType.name,\n fieldName,\n methodMap: sofa.method,\n defaultValue: 'GET',\n });\n\n router[method.toLocaleLowerCase() as TrouterMethod](\n path,\n useHandler({ info, fieldName, sofa, operation })\n );\n\n logger.debug(`[Router] ${fieldName} query available at ${method} ${path}`);\n\n return {\n document: operation,\n path,\n method: method.toUpperCase() as Method,\n };\n}\n\nfunction createMutationRoute({\n sofa,\n router,\n fieldName,\n}: {\n sofa: Sofa;\n router: Trouter;\n fieldName: string;\n}): RouteInfo {\n logger.debug(`[Router] Creating ${fieldName} mutation`);\n\n const mutationType = sofa.schema.getMutationType()!;\n const operationNode = buildOperationNodeForField({\n kind: 'mutation',\n schema: sofa.schema,\n field: fieldName,\n models: sofa.models,\n ignore: sofa.ignore,\n circularReferenceDepth: sofa.depthLimit,\n });\n const operation: DocumentNode = {\n kind: Kind.DOCUMENT,\n definitions: [operationNode],\n };\n const info = getOperationInfo(operation)!;\n const path = getPath(fieldName);\n\n const method = produceMethod({\n typeName: mutationType.name,\n fieldName,\n methodMap: sofa.method,\n defaultValue: 'POST',\n });\n\n router[method.toLowerCase() as TrouterMethod](\n path,\n useHandler({ info, fieldName, sofa, operation })\n );\n\n logger.debug(`[Router] ${fieldName} mutation available at ${method} ${path}`);\n\n return {\n document: operation,\n path,\n method: method.toUpperCase() as Method,\n };\n}\n\nfunction useHandler(config: {\n sofa: Sofa;\n info: OperationInfo;\n operation: DocumentNode;\n fieldName: string;\n}): RouteMiddleware {\n const { sofa, operation, fieldName } = config;\n const info = config.info!;\n\n return async ({ url, body, params, contextValue }) => {\n const variableValues = info.variables.reduce((variables, variable) => {\n const name = variable.variable.name.value;\n const value = parseVariable({\n value: pickParam({ url, body, params, name }),\n variable,\n schema: sofa.schema,\n });\n\n if (typeof value === 'undefined') {\n return variables;\n }\n\n return {\n ...variables,\n [name]: value,\n };\n }, {});\n\n const result = await sofa.execute({\n schema: sofa.schema,\n source: print(operation),\n contextValue,\n variableValues,\n operationName: info.operation.name && info.operation.name.value,\n });\n\n if (result.errors) {\n const defaultErrorHandler: ErrorHandler = (errors) => {\n return {\n type: 'error',\n status: 500,\n error: errors[0],\n };\n };\n const errorHandler: ErrorHandler =\n sofa.errorHandler || defaultErrorHandler;\n return errorHandler(result.errors);\n }\n\n return {\n type: 'result',\n status: 200,\n body: result.data && result.data[fieldName],\n };\n };\n}\n\nfunction getPath(fieldName: string, hasId = false) {\n return `/${convertName(fieldName)}${hasId ? '/:id' : ''}`;\n}\n\nfunction pickParam({\n name,\n url,\n params,\n body,\n}: {\n name: string;\n url: string;\n params: Params;\n body: any;\n}) {\n if (params && params.hasOwnProperty(name)) {\n return params[name];\n }\n const searchParams = new URLSearchParams(url.split('?')[1]);\n if (searchParams.has(name)) {\n return searchParams.get(name);\n }\n if (body && body.hasOwnProperty(name)) {\n return body[name];\n }\n}\n\nfunction produceMethod({\n typeName,\n fieldName,\n methodMap,\n defaultValue,\n}: {\n typeName: string;\n fieldName: string;\n methodMap?: MethodMap;\n defaultValue: Method;\n}): Method {\n const path = `${typeName}.${fieldName}`;\n\n if (methodMap && methodMap[path]) {\n return methodMap[path];\n }\n\n return defaultValue;\n}\n","import {\n GraphQLSchema,\n graphql,\n isObjectType,\n GraphQLObjectType,\n getNamedType,\n GraphQLNamedType,\n isListType,\n isNonNullType,\n GraphQLOutputType,\n} from 'graphql';\n\nimport { Ignore, ExecuteFn, OnRoute, MethodMap } from './types';\nimport { convertName } from './common';\nimport { logger } from './logger';\nimport { ErrorHandler } from './express';\n\n// user passes:\n// - schema\n// - error handler\n// - execute function\n// - context\n\nexport interface SofaConfig {\n basePath: string;\n schema: GraphQLSchema;\n execute?: ExecuteFn;\n /**\n * Treats an Object with an ID as not a model.\n * @example [\"User\", \"Message.author\"]\n */\n ignore?: Ignore;\n onRoute?: OnRoute;\n depthLimit?: number;\n errorHandler?: ErrorHandler;\n /**\n * Overwrites the default HTTP method.\n * @example {\"Query.field\": \"GET\", \"Mutation.field\": \"POST\"}\n */\n method?: MethodMap;\n}\n\nexport interface Sofa {\n basePath: string;\n schema: GraphQLSchema;\n models: string[];\n ignore: Ignore;\n depthLimit: number;\n method?: MethodMap;\n execute: ExecuteFn;\n onRoute?: OnRoute;\n errorHandler?: ErrorHandler;\n}\n\nexport function createSofa(config: SofaConfig): Sofa {\n logger.debug('[Sofa] Created');\n\n const models = extractsModels(config.schema);\n const ignore = config.ignore || [];\n const depthLimit = config.depthLimit || 1;\n\n logger.debug(`[Sofa] models: ${models.join(', ')}`);\n logger.debug(`[Sofa] ignore: ${ignore.join(', ')}`);\n\n return {\n execute: graphql,\n models,\n ignore,\n depthLimit,\n ...config,\n };\n}\n\n// Objects and Unions are the only things that are used to define return types\n// and both might contain an ID\n// We don't treat Unions as models because\n// they might represent an Object that is not a model\n// We check it later, when an operation is being built\nfunction extractsModels(schema: GraphQLSchema): string[] {\n const modelMap: {\n [name: string]: {\n list?: boolean;\n single?: boolean;\n };\n } = {};\n const query = schema.getQueryType()!;\n const fields = query.getFields();\n\n // if Query[type] (no args) and Query[type](just id as an argument)\n\n // loop through every field\n for (const fieldName in fields) {\n const field = fields[fieldName];\n const namedType = getNamedType(field.type);\n\n if (hasID(namedType)) {\n if (!modelMap[namedType.name]) {\n modelMap[namedType.name] = {};\n }\n\n if (isArrayOf(field.type, namedType)) {\n // check if type is a list\n // check if name of a field matches a name of a named type (in plural)\n // check if has no non-optional arguments\n // add to registry with `list: true`\n const sameName = isNameEqual(field.name, namedType.name + 's');\n const allOptionalArguments = !field.args.some((arg) =>\n isNonNullType(arg.type)\n );\n\n modelMap[namedType.name].list = sameName && allOptionalArguments;\n } else if (\n isObjectType(field.type) ||\n (isNonNullType(field.type) && isObjectType(field.type.ofType))\n ) {\n // check if type is a graphql object type\n // check if name of a field matches with name of an object type\n // check if has only one argument named `id`\n // add to registry with `single: true`\n const sameName = isNameEqual(field.name, namedType.name);\n const hasIdArgument =\n field.args.length === 1 && field.args[0].name === 'id';\n\n modelMap[namedType.name].single = sameName && hasIdArgument;\n }\n }\n }\n\n return Object.keys(modelMap).filter(\n (name) => modelMap[name].list && modelMap[name].single\n );\n}\n\n// it's dumb but let's leave it for now\nfunction isArrayOf(\n type: GraphQLOutputType,\n expected: GraphQLObjectType\n): boolean {\n if (isOptionalList(type)) {\n return true;\n }\n\n if (isNonNullType(type) && isOptionalList(type.ofType)) {\n return true;\n }\n\n function isOptionalList(list: GraphQLOutputType) {\n if (isListType(list)) {\n if (list.ofType.name === expected.name) {\n return true;\n }\n\n if (\n isNonNullType(list.ofType) &&\n list.ofType.ofType.name === expected.name\n ) {\n return true;\n }\n }\n }\n\n return false;\n}\n\nfunction hasID(type: GraphQLNamedType): type is GraphQLObjectType {\n return isObjectType(type) && !!type.getFields().id;\n}\n\nfunction isNameEqual(a: string, b: string): boolean {\n return convertName(a) === convertName(b);\n}\n","export function mapToPrimitive(type: string) {\n const formatMap: Record<string, any> = {\n Int: {\n type: 'integer',\n format: 'int32',\n },\n Float: {\n type: 'number',\n format: 'float',\n },\n String: {\n type: 'string',\n },\n Boolean: {\n type: 'boolean',\n },\n ID: {\n type: 'string',\n },\n };\n\n if (formatMap[type]) {\n return formatMap[type];\n }\n}\n\nexport function mapToRef(type: string) {\n return `#/components/schemas/${type}`;\n}\n","import {\n GraphQLObjectType,\n GraphQLInputObjectType,\n GraphQLField,\n GraphQLInputField,\n isNonNullType,\n GraphQLOutputType,\n isListType,\n isObjectType,\n isScalarType,\n GraphQLNamedType,\n isEnumType,\n} from 'graphql';\nimport { mapToPrimitive, mapToRef } from './utils';\n\nexport function buildSchemaObjectFromType(\n type: GraphQLObjectType | GraphQLInputObjectType\n): any {\n const required: string[] = [];\n const properties: Record<string, any> = {};\n\n const fields = type.getFields();\n\n for (const fieldName in fields) {\n const field = fields[fieldName];\n\n if (isNonNullType(field.type)) {\n required.push(field.name);\n }\n\n properties[fieldName] = resolveField(field);\n if (field.description) {\n properties[fieldName].description = field.description;\n }\n }\n\n return {\n type: 'object',\n ...(required.length ? { required } : {}),\n properties,\n ...(type.description ? { description: type.description } : {}),\n };\n}\n\nfunction resolveField(field: GraphQLField<any, any> | GraphQLInputField) {\n return resolveFieldType(field.type);\n}\n\n// array -> [type]\n// type -> $ref\n// scalar -> swagger primitive\nexport function resolveFieldType(\n type: GraphQLOutputType | GraphQLNamedType\n): any {\n if (isNonNullType(type)) {\n return resolveFieldType(type.ofType);\n }\n\n if (isListType(type)) {\n return {\n type: 'array',\n items: resolveFieldType(type.ofType),\n };\n }\n\n if (isObjectType(type)) {\n return {\n $ref: mapToRef(type.name),\n };\n }\n\n if (isScalarType(type)) {\n return (\n mapToPrimitive(type.name) || {\n type: 'object',\n }\n );\n }\n\n if (isEnumType(type)) {\n return {\n type: 'string',\n enum: type.astNode?.values?.map((value) => value.name.value),\n };\n }\n\n return {\n type: 'object',\n };\n}\n","import {\n DocumentNode,\n GraphQLSchema,\n VariableDefinitionNode,\n TypeNode,\n OperationDefinitionNode,\n ObjectTypeDefinitionNode,\n FieldNode,\n parse,\n printType,\n Kind,\n} from 'graphql';\n\nimport { getOperationInfo } from '../ast';\nimport { mapToPrimitive, mapToRef } from './utils';\nimport { resolveFieldType } from './types';\nimport { titleCase } from 'title-case';\n\nexport function buildPathFromOperation({\n url,\n schema,\n operation,\n useRequestBody,\n}: {\n url: string;\n schema: GraphQLSchema;\n operation: DocumentNode;\n useRequestBody: boolean;\n}): any {\n const info = getOperationInfo(operation)!;\n\n const description = resolveDescription(schema, info.operation);\n\n return {\n operationId: info.name,\n ...(useRequestBody\n ? {\n requestBody: {\n content: {\n 'application/json': {\n schema: resolveRequestBody(info.operation.variableDefinitions),\n },\n },\n },\n }\n : {\n parameters: resolveParameters(\n url,\n info.operation.variableDefinitions\n ),\n }),\n responses: {\n 200: {\n description,\n content: {\n 'application/json': {\n schema: resolveResponse({\n schema,\n operation: info.operation,\n }),\n },\n },\n },\n },\n };\n}\n\nfunction resolveParameters(\n url: string,\n variables: ReadonlyArray<VariableDefinitionNode> | undefined\n) {\n if (!variables) {\n return [];\n }\n\n return variables.map((variable: any) => {\n return {\n in: isInPath(url, variable.variable.name.value) ? 'path' : 'query',\n name: variable.variable.name.value,\n required: variable.type.kind === Kind.NON_NULL_TYPE,\n schema: resolveParamSchema(variable.type),\n };\n });\n}\n\nfunction resolveRequestBody(\n variables: ReadonlyArray<VariableDefinitionNode> | undefined\n) {\n if (!variables) {\n return {};\n }\n\n const properties: Record<string, any> = {};\n const required: string[] = [];\n\n variables.forEach(variable => {\n if (variable.type.kind === Kind.NON_NULL_TYPE) {\n required.push(variable.variable.name.value);\n }\n\n properties[variable.variable.name.value] = resolveParamSchema(\n variable.type\n );\n });\n\n return {\n type: 'object',\n properties,\n ...(required.length ? { required } : {}),\n };\n}\n\n// array -> [type]\n// type -> $ref\n// scalar -> swagger primitive\nfunction resolveParamSchema(type: TypeNode): any {\n if (type.kind === Kind.NON_NULL_TYPE) {\n return resolveParamSchema(type.type);\n }\n\n if (type.kind === Kind.LIST_TYPE) {\n return {\n type: 'array',\n items: resolveParamSchema(type.type),\n };\n }\n\n const primitive = mapToPrimitive(type.name.value);\n\n return (\n primitive || {\n $ref: mapToRef(type.name.value),\n }\n );\n}\n\nfunction resolveResponse({\n schema,\n operation,\n}: {\n schema: GraphQLSchema;\n operation: OperationDefinitionNode;\n}) {\n const operationType = operation.operation;\n const rootField = operation.selectionSet.selections[0];\n\n if (rootField.kind === Kind.FIELD) {\n if (operationType === 'query') {\n const queryType = schema.getQueryType()!;\n const field = queryType.getFields()[rootField.name.value];\n\n return resolveFieldType(field.type);\n }\n\n if (operationType === 'mutation') {\n const mutationType = schema.getMutationType()!;\n const field = mutationType.getFields()[rootField.name.value];\n\n return resolveFieldType(field.type);\n }\n }\n}\n\nfunction isInPath(url: string, param: string): boolean {\n return url.indexOf(`{${param}}`) !== -1;\n}\n\nfunction resolveDescription(\n schema: GraphQLSchema,\n operation: OperationDefinitionNode\n) {\n const selection = operation.selectionSet.selections[0] as FieldNode;\n const fieldName = selection.name.value;\n const typeDefinition = schema.getType(titleCase(operation.operation));\n\n if (!typeDefinition) {\n return '';\n }\n\n const definitionNode =\n typeDefinition.astNode || parse(printType(typeDefinition)).definitions[0];\n\n if (!isObjectTypeDefinitionNode(definitionNode)) {\n return '';\n }\n\n const fieldNode = definitionNode.fields!.find(\n field => field.name.value === fieldName\n );\n const descriptionDefinition = fieldNode && fieldNode.description;\n return descriptionDefinition && descriptionDefinition.value\n ? descriptionDefinition.value\n : '';\n}\n\nfunction isObjectTypeDefinitionNode(\n node: any\n): node is ObjectTypeDefinitionNode {\n return node.kind === Kind.OBJECT_TYPE_DEFINITION;\n}\n","import {\n GraphQLSchema,\n isObjectType,\n isInputObjectType,\n isIntrospectionType,\n} from 'graphql';\nimport { dump as YAMLstringify } from 'js-yaml';\nimport { writeFileSync } from 'fs';\n\nimport { buildSchemaObjectFromType } from './types';\nimport { buildPathFromOperation } from './operations';\nimport { RouteInfo } from '../types';\nimport { OpenAPI } from './interfaces';\n\nexport function OpenAPI({\n schema,\n info,\n components,\n security,\n}: {\n schema: GraphQLSchema;\n info: Record<string, any>;\n components?: Record<string, any>;\n security?: Record<string, any>[];\n}) {\n const types = schema.getTypeMap();\n const swagger: any = {\n openapi: '3.0.0',\n info,\n paths: {},\n components: {\n schemas: {},\n },\n };\n\n for (const typeName in types) {\n const type = types[typeName];\n\n if (\n (isObjectType(type) || isInputObjectType(type)) &&\n !isIntrospectionType(type)\n ) {\n swagger.components!.schemas![typeName] = buildSchemaObjectFromType(type);\n }\n }\n\n if (components) {\n swagger.components = { ...components, ...swagger.components };\n }\n\n if (security) {\n swagger.security = security;\n }\n\n return {\n addRoute(\n info: RouteInfo,\n config?: {\n basePath?: string;\n }\n ) {\n const basePath = config?.basePath || '';\n const path =\n basePath +\n info.path.replace(\n /\\:[a-z0-9]+\\w/i,\n (param) => `{${param.replace(':', '')}}`\n );\n\n if (!swagger.paths[path]) {\n swagger.paths[path] = {};\n }\n\n swagger.paths[path][info.method.toLowerCase()] = buildPathFromOperation({\n url: path,\n operation: info.document,\n schema,\n useRequestBody: ['POST', 'PUT', 'PATCH'].includes(info.method),\n });\n },\n get() {\n return swagger;\n },\n save(filepath: string) {\n const isJSON = /\\.json$/i;\n const isYAML = /.ya?ml$/i;\n\n if (isJSON.test(filepath)) {\n writeOutput(filepath, JSON.stringify(swagger, null, 2));\n } else if (isYAML.test(filepath)) {\n writeOutput(filepath, YAMLstringify(swagger));\n } else {\n throw new Error('We only support JSON and YAML files');\n }\n },\n };\n}\n\nfunction writeOutput(filepath: string, contents: string) {\n writeFileSync(filepath, contents, {\n encoding: 'utf-8',\n });\n}\n","import * as http from 'http';\nimport { createRouter } from './express';\nimport type { ContextValue } from './types';\nimport type { SofaConfig } from './sofa';\nimport { createSofa } from './sofa';\n\nexport { OpenAPI } from './open-api';\n\ntype Request = http.IncomingMessage & {\n method: string;\n url: string;\n originalUrl?: string;\n body?: any;\n};\n\ntype NextFunction = (err?: any) => void;\n\ntype Middleware = (\n req: Request,\n res: http.ServerResponse,\n next: NextFunction\n) => unknown;\n\nexport type ContextFn = (init: { req: any; res: any }) => ContextValue;\n\nexport function isContextFn(context: any): context is ContextFn {\n return typeof context === 'function';\n}\n\ninterface SofaMiddlewareConfig extends SofaConfig {\n context?: ContextValue | ContextFn;\n}\n\nexport function useSofa({\n context,\n ...config\n}: SofaMiddlewareConfig): Middleware {\n const invokeSofa = createSofaRouter(config);\n return async (req, res, next) => {\n try {\n let contextValue: ContextValue = { req };\n if (context) {\n if (typeof context === 'function') {\n contextValue = await context({ req, res });\n } else {\n contextValue = context;\n }\n }\n const response = await invokeSofa({\n method: req.method,\n url: req.originalUrl ?? req.url,\n body: req.body,\n contextValue,\n });\n if (response == null) {\n next();\n } else {\n const headers = {\n 'Content-Type': 'application/json',\n };\n if (response.statusMessage) {\n res.writeHead(response.status, response.statusMessage, headers);\n } else {\n res.writeHead(response.status, headers);\n }\n if (response.type === 'result') {\n res.end(JSON.stringify(response.body));\n }\n if (response.type === 'error') {\n res.end(JSON.stringify(response.error));\n }\n }\n } catch (error) {\n next(error);\n }\n };\n}\n\nexport function createSofaRouter(config: SofaConfig) {\n const sofa = createSofa(config);\n const router = createRouter(sofa);\n return router;\n}\n"],"names":["getOperationAST","paramCase","Kind","isScalarType","isEqualType","GraphQLBoolean","isInputObjectType","colors.red","colors.yellow","colors.green","colors.blue","uuid","subscribe","__asyncValues","buildOperationNodeForField","isObjectType","isNonNullType","print","graphql","getNamedType","isListType","isEnumType","titleCase","parse","printType","isIntrospectionType","YAMLstringify","writeFileSync"],"mappings":";;;;;;;;;;;;;;;;;;SAegB,gBAAgB,CAAC,GAAiB;IAChD,MAAM,EAAE,GAAGA,uBAAe,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAEtC,IAAI,CAAC,EAAE,EAAE;QACP,OAAO;KACR;IAED,OAAO;QACL,SAAS,EAAE,EAAE;QACb,IAAI,EAAE,EAAE,CAAC,IAAK,CAAC,KAAK;QACpB,SAAS,EAAE,EAAE,CAAC,mBAAmB,IAAI,EAAE;KACxC,CAAC;AACJ;;SCzBgB,WAAW,CAAC,IAAY;IACtC,OAAOC,mBAAS,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;SAEe,KAAK,CAAI,GAAM;IAC7B,OAAO,GAAG,IAAI,IAAI,CAAC;AACrB;;SCIgB,aAAa,CAAC,EAC5B,KAAK,EACL,QAAQ,EACR,MAAM,GAKP;IACC,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;QAChB,OAAO;KACR;IAED,OAAO,eAAe,CAAC;QACrB,KAAK;QACL,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,M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AAG;oBACd,cAAc,EAAE,kBAAkB;iBACnC,CAAC;gBACF,IAAI,QAAQ,CAAC,aAAa,EAAE;oBAC1B,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;iBACjE;qBAAM;oBACL,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;iBACzC;gBACD,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE;oBAC9B,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;iBACxC;gBACD,IAAI,QAAQ,CAAC,IAAI,KAAK,OAAO,EAAE;oBAC7B,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;iBACzC;aACF;SACF;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,KAAK,CAAC,CAAC;SACb;KACF,CAAA,CAAC;AACJ,CAAC;SAEe,gBAAgB,CAAC,MAAkB;IACjD,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAClC,OAAO,MAAM,CAAC;AAChB;;;;;;;"}
|
package/index.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/ast.ts","../src/common.ts","../src/parse.ts","../src/logger.ts","../src/subscriptions.ts","../src/express.ts","../src/sofa.ts","../src/open-api/utils.ts","../src/open-api/types.ts","../src/open-api/operations.ts","../src/open-api/index.ts","../src/index.ts"],"sourcesContent":["import {\n getOperationAST,\n DocumentNode,\n OperationDefinitionNode,\n VariableDefinitionNode,\n} from 'graphql';\n\nexport type OperationInfo =\n | {\n operation: OperationDefinitionNode;\n variables: ReadonlyArray<VariableDefinitionNode>;\n name: string;\n }\n | undefined;\n\nexport function getOperationInfo(doc: DocumentNode): OperationInfo {\n const op = getOperationAST(doc, null);\n\n if (!op) {\n return;\n }\n\n return {\n operation: op,\n name: op.name!.value,\n variables: op.variableDefinitions || [],\n };\n}\n","import { paramCase } from 'param-case';\n\nexport function convertName(name: string) {\n return paramCase(name);\n}\n\nexport function isNil<T>(val: T) {\n return val == null;\n}\n","import {\n VariableDefinitionNode,\n GraphQLSchema,\n TypeNode,\n isScalarType,\n isEqualType,\n GraphQLBoolean,\n isInputObjectType,\n Kind,\n} from 'graphql';\nimport { isNil } from './common';\n\nexport function parseVariable({\n value,\n variable,\n schema,\n}: {\n value: any;\n variable: VariableDefinitionNode;\n schema: GraphQLSchema;\n}) {\n if (isNil(value)) {\n return;\n }\n\n return resolveVariable({\n value,\n type: variable.type,\n schema,\n });\n}\n\nfunction resolveVariable({\n value,\n type,\n schema,\n}: {\n value: any;\n type: TypeNode;\n schema: GraphQLSchema;\n}): any | any[] {\n if (type.kind === Kind.NAMED_TYPE) {\n const namedType = schema.getType(type.name.value);\n\n if (isScalarType(namedType)) {\n // GraphQLBoolean.serialize expects a boolean or a number only\n if (isEqualType(GraphQLBoolean, namedType)) {\n // we don't support TRUE\n value = value === 'true';\n }\n\n return namedType.serialize(value);\n }\n\n if (isInputObjectType(namedType)) {\n return value && typeof value === 'object' ? value : JSON.parse(value);\n }\n\n return value;\n }\n\n if (type.kind === Kind.LIST_TYPE) {\n return (value as any[]).map(val =>\n resolveVariable({\n value: val,\n type: type.type,\n schema,\n })\n );\n }\n\n if (type.kind === Kind.NON_NULL_TYPE) {\n return resolveVariable({\n value: value,\n type: type.type,\n schema,\n });\n }\n}\n","import * as colors from 'ansi-colors';\n\ntype Level = 'error' | 'warn' | 'info' | 'debug';\n\nconst levels: Level[] = ['error', 'warn', 'info', 'debug'];\n\nconst toLevel = (string: void | string) =>\n levels.includes(string as Level) ? (string as Level) : null;\n\nconst currentLevel: Level = process.env.SOFA_DEBUG\n ? 'debug'\n : toLevel(process.env.SOFA_LOGGER_LEVEL) ?? 'info';\n\nconst log = (level: Level, color: any, args: any[]) => {\n if (levels.indexOf(level) <= levels.indexOf(currentLevel)) {\n console.log(`${color(level)}:`, ...args);\n }\n};\n\nexport const logger = {\n error: (...args: any[]) => {\n log('error', colors.red, args);\n },\n warn: (...args: any[]) => {\n log('warn', colors.yellow, args);\n },\n info: (...args: any[]) => {\n log('info', colors.green, args);\n },\n debug: (...args: any[]) => {\n log('debug', colors.blue, args);\n },\n};\n","import {\n subscribe,\n DocumentNode,\n VariableDefinitionNode,\n ExecutionResult,\n Kind,\n} from 'graphql';\nimport { v4 as uuid } from 'uuid';\nimport axios from 'axios';\nimport { buildOperationNodeForField } from '@graphql-tools/utils';\nimport type { ContextValue } from './types';\nimport type { Sofa } from './sofa';\nimport { getOperationInfo } from './ast';\nimport { parseVariable } from './parse';\nimport { logger } from './logger';\n\nfunction isAsyncIterable(obj: any): obj is AsyncIterable<any> {\n return typeof obj[Symbol.asyncIterator] === 'function';\n}\n\n// To start subscription:\n// - an url that Sofa should trigger\n// - name of a subscription\n// - variables if needed\n// - some sort of an auth token\n// - Sofa should return a unique id of that subscription\n// - respond with OK 200\n\n// To stop subscription\n// - an id is required\n// - respond with OK 200\n\n// To update subscription\n// - an id is required\n// - new set of variables\n\nexport type ID = string;\nexport type SubscriptionFieldName = string;\n\nexport interface StartSubscriptionEvent {\n subscription: SubscriptionFieldName;\n variables: any;\n url: string;\n}\n\nexport interface UpdateSubscriptionEvent {\n id: ID;\n variables: any;\n}\n\nexport interface StopSubscriptionResponse {\n id: ID;\n}\n\ninterface BuiltOperation {\n operationName: string;\n document: DocumentNode;\n variables: ReadonlyArray<VariableDefinitionNode>;\n}\n\ninterface StoredClient {\n name: SubscriptionFieldName;\n url: string;\n iterator: AsyncIterator<any>;\n}\n\nexport class SubscriptionManager {\n private operations = new Map<SubscriptionFieldName, BuiltOperation>();\n private clients = new Map<ID, StoredClient>();\n\n constructor(private sofa: Sofa) {\n this.buildOperations();\n }\n\n public async start(\n event: StartSubscriptionEvent,\n contextValue: ContextValue\n ) {\n const id = uuid();\n const name = event.subscription;\n\n if (!this.operations.has(name)) {\n throw new Error(`Subscription '${name}' is not available`);\n }\n\n const { document, operationName, variables } = this.operations.get(name)!;\n\n logger.info(`[Subscription] Start ${id}`, event);\n\n const result = await this.execute({\n id,\n name,\n url: event.url,\n document,\n operationName,\n variables,\n contextValue,\n });\n\n if (typeof result !== 'undefined') {\n return result;\n }\n\n return { id };\n }\n\n public async stop(id: ID): Promise<StopSubscriptionResponse> {\n logger.info(`[Subscription] Stop ${id}`);\n\n if (!this.clients.has(id)) {\n throw new Error(`Subscription with ID '${id}' does not exist`);\n }\n\n const execution = this.clients.get(id)!;\n\n if (execution.iterator.return) {\n execution.iterator.return();\n }\n\n this.clients.delete(id);\n\n return { id };\n }\n\n public async update(\n event: UpdateSubscriptionEvent,\n contextValue: ContextValue\n ) {\n const { variables, id } = event;\n\n logger.info(`[Subscription] Update ${id}`, event);\n\n if (!this.clients.has(id)) {\n throw new Error(`Subscription with ID '${id}' does not exist`);\n }\n\n const { name: subscription, url } = this.clients.get(id)!;\n\n this.stop(id);\n\n return this.start(\n {\n url,\n subscription,\n variables,\n },\n contextValue\n );\n }\n\n private async execute({\n id,\n document,\n name,\n url,\n operationName,\n variables,\n contextValue,\n }: {\n id: ID;\n name: SubscriptionFieldName;\n url: string;\n document: DocumentNode;\n operationName: string;\n variables: Record<string, any>;\n contextValue: ContextValue;\n }) {\n const variableNodes = this.operations.get(name)!.variables;\n const variableValues = variableNodes.reduce((values, variable) => {\n const value = parseVariable({\n value: variables[variable.variable.name.value],\n variable,\n schema: this.sofa.schema,\n });\n\n if (typeof value === 'undefined') {\n return values;\n }\n\n return {\n ...values,\n [name]: value,\n };\n }, {});\n\n const execution = await subscribe({\n schema: this.sofa.schema,\n document,\n operationName,\n variableValues,\n contextValue,\n });\n\n if (isAsyncIterable(execution)) {\n // successful\n\n // add execution to clients\n this.clients.set(id, {\n name,\n url,\n iterator: execution as any,\n });\n\n // success\n (async () => {\n for await (const result of execution) {\n await this.sendData({\n id,\n result,\n });\n }\n })().then(\n () => {\n // completes\n this.clients.delete(id);\n },\n (e) => {\n logger.info(`Subscription #${id} closed`);\n logger.error(e);\n this.clients.delete(id);\n }\n );\n } else {\n return execution as ExecutionResult;\n }\n }\n\n private async sendData({ id, result }: { id: ID; result: any }) {\n if (!this.clients.has(id)) {\n throw new Error(`Subscription with ID '${id}' does not exist`);\n }\n\n const { url } = this.clients.get(id)!;\n\n logger.info(`[Subscription] Trigger ${id}`);\n\n await axios.post(url, result);\n }\n\n private buildOperations() {\n const subscription = this.sofa.schema.getSubscriptionType();\n\n if (!subscription) {\n return;\n }\n\n const fieldMap = subscription.getFields();\n\n for (const field in fieldMap) {\n const operationNode = buildOperationNodeForField({\n kind: 'subscription',\n field,\n schema: this.sofa.schema,\n models: this.sofa.models,\n ignore: this.sofa.ignore,\n circularReferenceDepth: this.sofa.depthLimit,\n });\n const document: DocumentNode = {\n kind: Kind.DOCUMENT,\n definitions: [operationNode],\n };\n\n const { variables, name: operationName } = getOperationInfo(document)!;\n\n this.operations.set(field, {\n operationName,\n document,\n variables,\n });\n }\n }\n}\n","import {\n DocumentNode,\n print,\n isObjectType,\n isNonNullType,\n Kind,\n} from 'graphql';\nimport * as Trouter from 'trouter';\nimport { buildOperationNodeForField } from '@graphql-tools/utils';\nimport { getOperationInfo, OperationInfo } from './ast';\nimport { Sofa } from './sofa';\nimport { RouteInfo, Method, MethodMap, ContextValue } from './types';\nimport { convertName } from './common';\nimport { parseVariable } from './parse';\nimport { StartSubscriptionEvent, SubscriptionManager } from './subscriptions';\nimport { logger } from './logger';\n\nexport type ErrorHandler = (errors: ReadonlyArray<any>) => RouterError;\n\ntype Params = { [key: string]: string };\n\ntype TrouterMethod = 'get' | 'post' | 'put' | 'delete' | 'patch';\n\ntype RouterRequest = {\n method: string;\n url: string;\n body: any;\n contextValue: ContextValue;\n};\ntype RouterResult = {\n type: 'result';\n status: number;\n statusMessage?: string;\n body: any;\n};\ntype RouterError = {\n type: 'error';\n status: number;\n statusMessage?: string;\n error: any;\n};\ntype RouterResponse = RouterResult | RouterError;\ntype Router = (request: RouterRequest) => Promise<null | RouterResponse>;\n\ntype RouteRequest = {\n url: string;\n body: any;\n params: Params;\n contextValue: ContextValue;\n};\ntype RouteMiddleware = (request: RouteRequest) => Promise<RouterResponse>;\n\nexport function createRouter(sofa: Sofa): Router {\n logger.debug('[Sofa] Creating router');\n\n const router = new Trouter<RouteMiddleware>();\n\n const queryType = sofa.schema.getQueryType();\n const mutationType = sofa.schema.getMutationType();\n const subscriptionManager = new SubscriptionManager(sofa);\n\n if (queryType) {\n Object.keys(queryType.getFields()).forEach((fieldName) => {\n const route = createQueryRoute({ sofa, router, fieldName });\n\n if (sofa.onRoute) {\n sofa.onRoute(route);\n }\n });\n }\n\n if (mutationType) {\n Object.keys(mutationType.getFields()).forEach((fieldName) => {\n const route = createMutationRoute({ sofa, router, fieldName });\n\n if (sofa.onRoute) {\n sofa.onRoute(route);\n }\n });\n }\n\n router.post('/webhook', async ({ body, contextValue }) => {\n const { subscription, variables, url }: StartSubscriptionEvent = body;\n try {\n const result = await subscriptionManager.start(\n {\n subscription,\n variables,\n url,\n },\n contextValue\n );\n return {\n type: 'result',\n status: 200,\n statusMessage: 'OK',\n body: result,\n };\n } catch (error) {\n return {\n type: 'error',\n status: 500,\n statusMessage: 'Subscription failed',\n error,\n };\n }\n });\n\n router.post('/webhook/:id', async ({ body, params, contextValue }) => {\n const id: string = params.id;\n const variables: any = body.variables;\n try {\n const result = await subscriptionManager.update(\n {\n id,\n variables,\n },\n contextValue\n );\n return {\n type: 'result',\n status: 200,\n statusMessage: 'OK',\n body: result,\n };\n } catch (error) {\n return {\n type: 'error',\n status: 500,\n statusMessage: 'Subscription failed to update',\n error,\n };\n }\n });\n\n router.delete('/webhook/:id', async ({ params }) => {\n const id: string = params.id;\n try {\n const result = await subscriptionManager.stop(id);\n return {\n type: 'result',\n status: 200,\n statusMessage: 'OK',\n body: result,\n };\n } catch (error) {\n return {\n type: 'error',\n status: 500,\n statusMessage: 'Subscription failed to stop',\n error,\n };\n }\n });\n\n return async ({ method, url, body, contextValue }) => {\n if (!url.startsWith(sofa.basePath)) {\n return null;\n }\n // trim base path and search\n const [slicedUrl] = url.slice(sofa.basePath.length).split('?');\n const trouterMethod = method.toUpperCase() as Trouter.HTTPMethod;\n const obj = router.find(trouterMethod, slicedUrl);\n for (const handler of obj.handlers) {\n return await handler({\n url,\n body,\n params: obj.params,\n contextValue,\n });\n }\n return null;\n };\n}\n\nfunction createQueryRoute({\n sofa,\n router,\n fieldName,\n}: {\n sofa: Sofa;\n router: Trouter;\n fieldName: string;\n}): RouteInfo {\n logger.debug(`[Router] Creating ${fieldName} query`);\n\n const queryType = sofa.schema.getQueryType()!;\n const operationNode = buildOperationNodeForField({\n kind: 'query',\n schema: sofa.schema,\n field: fieldName,\n models: sofa.models,\n ignore: sofa.ignore,\n circularReferenceDepth: sofa.depthLimit,\n });\n const operation: DocumentNode = {\n kind: Kind.DOCUMENT,\n definitions: [operationNode],\n };\n const info = getOperationInfo(operation)!;\n const field = queryType.getFields()[fieldName];\n const fieldType = field.type;\n const isSingle =\n isObjectType(fieldType) ||\n (isNonNullType(fieldType) && isObjectType(fieldType.ofType));\n const hasIdArgument = field.args.some((arg) => arg.name === 'id');\n const path = getPath(fieldName, isSingle && hasIdArgument);\n\n const method = produceMethod({\n typeName: queryType.name,\n fieldName,\n methodMap: sofa.method,\n defaultValue: 'GET',\n });\n\n router[method.toLocaleLowerCase() as TrouterMethod](\n path,\n useHandler({ info, fieldName, sofa, operation })\n );\n\n logger.debug(`[Router] ${fieldName} query available at ${method} ${path}`);\n\n return {\n document: operation,\n path,\n method: method.toUpperCase() as Method,\n };\n}\n\nfunction createMutationRoute({\n sofa,\n router,\n fieldName,\n}: {\n sofa: Sofa;\n router: Trouter;\n fieldName: string;\n}): RouteInfo {\n logger.debug(`[Router] Creating ${fieldName} mutation`);\n\n const mutationType = sofa.schema.getMutationType()!;\n const operationNode = buildOperationNodeForField({\n kind: 'mutation',\n schema: sofa.schema,\n field: fieldName,\n models: sofa.models,\n ignore: sofa.ignore,\n circularReferenceDepth: sofa.depthLimit,\n });\n const operation: DocumentNode = {\n kind: Kind.DOCUMENT,\n definitions: [operationNode],\n };\n const info = getOperationInfo(operation)!;\n const path = getPath(fieldName);\n\n const method = produceMethod({\n typeName: mutationType.name,\n fieldName,\n methodMap: sofa.method,\n defaultValue: 'POST',\n });\n\n router[method.toLowerCase() as TrouterMethod](\n path,\n useHandler({ info, fieldName, sofa, operation })\n );\n\n logger.debug(`[Router] ${fieldName} mutation available at ${method} ${path}`);\n\n return {\n document: operation,\n path,\n method: method.toUpperCase() as Method,\n };\n}\n\nfunction useHandler(config: {\n sofa: Sofa;\n info: OperationInfo;\n operation: DocumentNode;\n fieldName: string;\n}): RouteMiddleware {\n const { sofa, operation, fieldName } = config;\n const info = config.info!;\n\n return async ({ url, body, params, contextValue }) => {\n const variableValues = info.variables.reduce((variables, variable) => {\n const name = variable.variable.name.value;\n const value = parseVariable({\n value: pickParam({ url, body, params, name }),\n variable,\n schema: sofa.schema,\n });\n\n if (typeof value === 'undefined') {\n return variables;\n }\n\n return {\n ...variables,\n [name]: value,\n };\n }, {});\n\n const result = await sofa.execute({\n schema: sofa.schema,\n source: print(operation),\n contextValue,\n variableValues,\n operationName: info.operation.name && info.operation.name.value,\n });\n\n if (result.errors) {\n const defaultErrorHandler: ErrorHandler = (errors) => {\n return {\n type: 'error',\n status: 500,\n error: errors[0],\n };\n };\n const errorHandler: ErrorHandler =\n sofa.errorHandler || defaultErrorHandler;\n return errorHandler(result.errors);\n }\n\n return {\n type: 'result',\n status: 200,\n body: result.data && result.data[fieldName],\n };\n };\n}\n\nfunction getPath(fieldName: string, hasId = false) {\n return `/${convertName(fieldName)}${hasId ? '/:id' : ''}`;\n}\n\nfunction pickParam({\n name,\n url,\n params,\n body,\n}: {\n name: string;\n url: string;\n params: Params;\n body: any;\n}) {\n if (params && params.hasOwnProperty(name)) {\n return params[name];\n }\n const searchParams = new URLSearchParams(url.split('?')[1]);\n if (searchParams.has(name)) {\n return searchParams.get(name);\n }\n if (body && body.hasOwnProperty(name)) {\n return body[name];\n }\n}\n\nfunction produceMethod({\n typeName,\n fieldName,\n methodMap,\n defaultValue,\n}: {\n typeName: string;\n fieldName: string;\n methodMap?: MethodMap;\n defaultValue: Method;\n}): Method {\n const path = `${typeName}.${fieldName}`;\n\n if (methodMap && methodMap[path]) {\n return methodMap[path];\n }\n\n return defaultValue;\n}\n","import {\n GraphQLSchema,\n graphql,\n isObjectType,\n GraphQLObjectType,\n getNamedType,\n GraphQLNamedType,\n isListType,\n isNonNullType,\n GraphQLOutputType,\n} from 'graphql';\n\nimport { Ignore, ExecuteFn, OnRoute, MethodMap } from './types';\nimport { convertName } from './common';\nimport { logger } from './logger';\nimport { ErrorHandler } from './express';\n\n// user passes:\n// - schema\n// - error handler\n// - execute function\n// - context\n\nexport interface SofaConfig {\n basePath: string;\n schema: GraphQLSchema;\n execute?: ExecuteFn;\n /**\n * Treats an Object with an ID as not a model.\n * @example [\"User\", \"Message.author\"]\n */\n ignore?: Ignore;\n onRoute?: OnRoute;\n depthLimit?: number;\n errorHandler?: ErrorHandler;\n /**\n * Overwrites the default HTTP method.\n * @example {\"Query.field\": \"GET\", \"Mutation.field\": \"POST\"}\n */\n method?: MethodMap;\n}\n\nexport interface Sofa {\n basePath: string;\n schema: GraphQLSchema;\n models: string[];\n ignore: Ignore;\n depthLimit: number;\n method?: MethodMap;\n execute: ExecuteFn;\n onRoute?: OnRoute;\n errorHandler?: ErrorHandler;\n}\n\nexport function createSofa(config: SofaConfig): Sofa {\n logger.debug('[Sofa] Created');\n\n const models = extractsModels(config.schema);\n const ignore = config.ignore || [];\n const depthLimit = config.depthLimit || 1;\n\n logger.debug(`[Sofa] models: ${models.join(', ')}`);\n logger.debug(`[Sofa] ignore: ${ignore.join(', ')}`);\n\n return {\n execute: graphql,\n models,\n ignore,\n depthLimit,\n ...config,\n };\n}\n\n// Objects and Unions are the only things that are used to define return types\n// and both might contain an ID\n// We don't treat Unions as models because\n// they might represent an Object that is not a model\n// We check it later, when an operation is being built\nfunction extractsModels(schema: GraphQLSchema): string[] {\n const modelMap: {\n [name: string]: {\n list?: boolean;\n single?: boolean;\n };\n } = {};\n const query = schema.getQueryType()!;\n const fields = query.getFields();\n\n // if Query[type] (no args) and Query[type](just id as an argument)\n\n // loop through every field\n for (const fieldName in fields) {\n const field = fields[fieldName];\n const namedType = getNamedType(field.type);\n\n if (hasID(namedType)) {\n if (!modelMap[namedType.name]) {\n modelMap[namedType.name] = {};\n }\n\n if (isArrayOf(field.type, namedType)) {\n // check if type is a list\n // check if name of a field matches a name of a named type (in plural)\n // check if has no non-optional arguments\n // add to registry with `list: true`\n const sameName = isNameEqual(field.name, namedType.name + 's');\n const allOptionalArguments = !field.args.some((arg) =>\n isNonNullType(arg.type)\n );\n\n modelMap[namedType.name].list = sameName && allOptionalArguments;\n } else if (\n isObjectType(field.type) ||\n (isNonNullType(field.type) && isObjectType(field.type.ofType))\n ) {\n // check if type is a graphql object type\n // check if name of a field matches with name of an object type\n // check if has only one argument named `id`\n // add to registry with `single: true`\n const sameName = isNameEqual(field.name, namedType.name);\n const hasIdArgument =\n field.args.length === 1 && field.args[0].name === 'id';\n\n modelMap[namedType.name].single = sameName && hasIdArgument;\n }\n }\n }\n\n return Object.keys(modelMap).filter(\n (name) => modelMap[name].list && modelMap[name].single\n );\n}\n\n// it's dumb but let's leave it for now\nfunction isArrayOf(\n type: GraphQLOutputType,\n expected: GraphQLObjectType\n): boolean {\n if (isOptionalList(type)) {\n return true;\n }\n\n if (isNonNullType(type) && isOptionalList(type.ofType)) {\n return true;\n }\n\n function isOptionalList(list: GraphQLOutputType) {\n if (isListType(list)) {\n if (list.ofType.name === expected.name) {\n return true;\n }\n\n if (\n isNonNullType(list.ofType) &&\n list.ofType.ofType.name === expected.name\n ) {\n return true;\n }\n }\n }\n\n return false;\n}\n\nfunction hasID(type: GraphQLNamedType): type is GraphQLObjectType {\n return isObjectType(type) && !!type.getFields().id;\n}\n\nfunction isNameEqual(a: string, b: string): boolean {\n return convertName(a) === convertName(b);\n}\n","export function mapToPrimitive(type: string) {\n const formatMap: Record<string, any> = {\n Int: {\n type: 'integer',\n format: 'int32',\n },\n Float: {\n type: 'number',\n format: 'float',\n },\n String: {\n type: 'string',\n },\n Boolean: {\n type: 'boolean',\n },\n ID: {\n type: 'string',\n },\n };\n\n if (formatMap[type]) {\n return formatMap[type];\n }\n}\n\nexport function mapToRef(type: string) {\n return `#/components/schemas/${type}`;\n}\n","import {\n GraphQLObjectType,\n GraphQLInputObjectType,\n GraphQLField,\n GraphQLInputField,\n isNonNullType,\n GraphQLOutputType,\n isListType,\n isObjectType,\n isScalarType,\n GraphQLNamedType,\n isEnumType,\n} from 'graphql';\nimport { mapToPrimitive, mapToRef } from './utils';\n\nexport function buildSchemaObjectFromType(\n type: GraphQLObjectType | GraphQLInputObjectType\n): any {\n const required: string[] = [];\n const properties: Record<string, any> = {};\n\n const fields = type.getFields();\n\n for (const fieldName in fields) {\n const field = fields[fieldName];\n\n if (isNonNullType(field.type)) {\n required.push(field.name);\n }\n\n properties[fieldName] = resolveField(field);\n if (field.description) {\n properties[fieldName].description = field.description;\n }\n }\n\n return {\n type: 'object',\n ...(required.length ? { required } : {}),\n properties,\n ...(type.description ? { description: type.description } : {}),\n };\n}\n\nfunction resolveField(field: GraphQLField<any, any> | GraphQLInputField) {\n return resolveFieldType(field.type);\n}\n\n// array -> [type]\n// type -> $ref\n// scalar -> swagger primitive\nexport function resolveFieldType(\n type: GraphQLOutputType | GraphQLNamedType\n): any {\n if (isNonNullType(type)) {\n return resolveFieldType(type.ofType);\n }\n\n if (isListType(type)) {\n return {\n type: 'array',\n items: resolveFieldType(type.ofType),\n };\n }\n\n if (isObjectType(type)) {\n return {\n $ref: mapToRef(type.name),\n };\n }\n\n if (isScalarType(type)) {\n return (\n mapToPrimitive(type.name) || {\n type: 'object',\n }\n );\n }\n\n if (isEnumType(type)) {\n return {\n type: 'string',\n enum: type.astNode?.values?.map((value) => value.name.value),\n };\n }\n\n return {\n type: 'object',\n };\n}\n","import {\n DocumentNode,\n GraphQLSchema,\n VariableDefinitionNode,\n TypeNode,\n OperationDefinitionNode,\n ObjectTypeDefinitionNode,\n FieldNode,\n parse,\n printType,\n Kind,\n} from 'graphql';\n\nimport { getOperationInfo } from '../ast';\nimport { mapToPrimitive, mapToRef } from './utils';\nimport { resolveFieldType } from './types';\nimport { titleCase } from 'title-case';\n\nexport function buildPathFromOperation({\n url,\n schema,\n operation,\n useRequestBody,\n}: {\n url: string;\n schema: GraphQLSchema;\n operation: DocumentNode;\n useRequestBody: boolean;\n}): any {\n const info = getOperationInfo(operation)!;\n\n const description = resolveDescription(schema, info.operation);\n\n return {\n operationId: info.name,\n ...(useRequestBody\n ? {\n requestBody: {\n content: {\n 'application/json': {\n schema: resolveRequestBody(info.operation.variableDefinitions),\n },\n },\n },\n }\n : {\n parameters: resolveParameters(\n url,\n info.operation.variableDefinitions\n ),\n }),\n responses: {\n 200: {\n description,\n content: {\n 'application/json': {\n schema: resolveResponse({\n schema,\n operation: info.operation,\n }),\n },\n },\n },\n },\n };\n}\n\nfunction resolveParameters(\n url: string,\n variables: ReadonlyArray<VariableDefinitionNode> | undefined\n) {\n if (!variables) {\n return [];\n }\n\n return variables.map((variable: any) => {\n return {\n in: isInPath(url, variable.variable.name.value) ? 'path' : 'query',\n name: variable.variable.name.value,\n required: variable.type.kind === Kind.NON_NULL_TYPE,\n schema: resolveParamSchema(variable.type),\n };\n });\n}\n\nfunction resolveRequestBody(\n variables: ReadonlyArray<VariableDefinitionNode> | undefined\n) {\n if (!variables) {\n return {};\n }\n\n const properties: Record<string, any> = {};\n const required: string[] = [];\n\n variables.forEach(variable => {\n if (variable.type.kind === Kind.NON_NULL_TYPE) {\n required.push(variable.variable.name.value);\n }\n\n properties[variable.variable.name.value] = resolveParamSchema(\n variable.type\n );\n });\n\n return {\n type: 'object',\n properties,\n ...(required.length ? { required } : {}),\n };\n}\n\n// array -> [type]\n// type -> $ref\n// scalar -> swagger primitive\nfunction resolveParamSchema(type: TypeNode): any {\n if (type.kind === Kind.NON_NULL_TYPE) {\n return resolveParamSchema(type.type);\n }\n\n if (type.kind === Kind.LIST_TYPE) {\n return {\n type: 'array',\n items: resolveParamSchema(type.type),\n };\n }\n\n const primitive = mapToPrimitive(type.name.value);\n\n return (\n primitive || {\n $ref: mapToRef(type.name.value),\n }\n );\n}\n\nfunction resolveResponse({\n schema,\n operation,\n}: {\n schema: GraphQLSchema;\n operation: OperationDefinitionNode;\n}) {\n const operationType = operation.operation;\n const rootField = operation.selectionSet.selections[0];\n\n if (rootField.kind === Kind.FIELD) {\n if (operationType === 'query') {\n const queryType = schema.getQueryType()!;\n const field = queryType.getFields()[rootField.name.value];\n\n return resolveFieldType(field.type);\n }\n\n if (operationType === 'mutation') {\n const mutationType = schema.getMutationType()!;\n const field = mutationType.getFields()[rootField.name.value];\n\n return resolveFieldType(field.type);\n }\n }\n}\n\nfunction isInPath(url: string, param: string): boolean {\n return url.indexOf(`{${param}}`) !== -1;\n}\n\nfunction resolveDescription(\n schema: GraphQLSchema,\n operation: OperationDefinitionNode\n) {\n const selection = operation.selectionSet.selections[0] as FieldNode;\n const fieldName = selection.name.value;\n const typeDefinition = schema.getType(titleCase(operation.operation));\n\n if (!typeDefinition) {\n return '';\n }\n\n const definitionNode =\n typeDefinition.astNode || parse(printType(typeDefinition)).definitions[0];\n\n if (!isObjectTypeDefinitionNode(definitionNode)) {\n return '';\n }\n\n const fieldNode = definitionNode.fields!.find(\n field => field.name.value === fieldName\n );\n const descriptionDefinition = fieldNode && fieldNode.description;\n return descriptionDefinition && descriptionDefinition.value\n ? descriptionDefinition.value\n : '';\n}\n\nfunction isObjectTypeDefinitionNode(\n node: any\n): node is ObjectTypeDefinitionNode {\n return node.kind === Kind.OBJECT_TYPE_DEFINITION;\n}\n","import {\n GraphQLSchema,\n isObjectType,\n isInputObjectType,\n isIntrospectionType,\n} from 'graphql';\nimport { dump as YAMLstringify } from 'js-yaml';\nimport { writeFileSync } from 'fs';\n\nimport { buildSchemaObjectFromType } from './types';\nimport { buildPathFromOperation } from './operations';\nimport { RouteInfo } from '../types';\nimport { OpenAPI } from './interfaces';\n\nexport function OpenAPI({\n schema,\n info,\n components,\n security,\n}: {\n schema: GraphQLSchema;\n info: Record<string, any>;\n components?: Record<string, any>;\n security?: Record<string, any>[];\n}) {\n const types = schema.getTypeMap();\n const swagger: any = {\n openapi: '3.0.0',\n info,\n paths: {},\n components: {\n schemas: {},\n },\n };\n\n for (const typeName in types) {\n const type = types[typeName];\n\n if (\n (isObjectType(type) || isInputObjectType(type)) &&\n !isIntrospectionType(type)\n ) {\n swagger.components!.schemas![typeName] = buildSchemaObjectFromType(type);\n }\n }\n\n if (components) {\n swagger.components = { ...components, ...swagger.components };\n }\n\n if (security) {\n swagger.security = security;\n }\n\n return {\n addRoute(\n info: RouteInfo,\n config?: {\n basePath?: string;\n }\n ) {\n const basePath = config?.basePath || '';\n const path =\n basePath +\n info.path.replace(\n /\\:[a-z0-9]+\\w/i,\n (param) => `{${param.replace(':', '')}}`\n );\n\n if (!swagger.paths[path]) {\n swagger.paths[path] = {};\n }\n\n swagger.paths[path][info.method.toLowerCase()] = buildPathFromOperation({\n url: path,\n operation: info.document,\n schema,\n useRequestBody: ['POST', 'PUT', 'PATCH'].includes(info.method),\n });\n },\n get() {\n return swagger;\n },\n save(filepath: string) {\n const isJSON = /\\.json$/i;\n const isYAML = /.ya?ml$/i;\n\n if (isJSON.test(filepath)) {\n writeOutput(filepath, JSON.stringify(swagger, null, 2));\n } else if (isYAML.test(filepath)) {\n writeOutput(filepath, YAMLstringify(swagger));\n } else {\n throw new Error('We only support JSON and YAML files');\n }\n },\n };\n}\n\nfunction writeOutput(filepath: string, contents: string) {\n writeFileSync(filepath, contents, {\n encoding: 'utf-8',\n });\n}\n","import * as http from 'http';\nimport { createRouter } from './express';\nimport type { ContextValue } from './types';\nimport type { SofaConfig } from './sofa';\nimport { createSofa } from './sofa';\n\nexport { OpenAPI } from './open-api';\n\ntype Request = http.IncomingMessage & {\n method: string;\n url: string;\n originalUrl?: string;\n body?: any;\n};\n\ntype NextFunction = (err?: any) => void;\n\ntype Middleware = (\n req: Request,\n res: http.ServerResponse,\n next: NextFunction\n) => unknown;\n\nexport type ContextFn = (init: { req: any; res: any }) => ContextValue;\n\nexport function isContextFn(context: any): context is ContextFn {\n return typeof context === 'function';\n}\n\ninterface SofaMiddlewareConfig extends SofaConfig {\n context?: ContextValue | ContextFn;\n}\n\nexport function useSofa({\n context,\n ...config\n}: SofaMiddlewareConfig): Middleware {\n const invokeSofa = createSofaRouter(config);\n return async (req, res, next) => {\n try {\n let contextValue: ContextValue = { req };\n if (context) {\n if (typeof context === 'function') {\n contextValue = await context({ req, res });\n } else {\n contextValue = context;\n }\n }\n const response = await invokeSofa({\n method: req.method,\n url: req.originalUrl ?? req.url,\n body: req.body,\n contextValue,\n });\n if (response == null) {\n next();\n } else {\n const headers = {\n 'Content-Type': 'application/json',\n };\n if (response.statusMessage) {\n res.writeHead(response.status, response.statusMessage, headers);\n } else {\n res.writeHead(response.status, headers);\n }\n if (response.type === 'result') {\n res.end(JSON.stringify(response.body));\n }\n if (response.type === 'error') {\n res.end(JSON.stringify(response.error));\n }\n }\n } catch (error) {\n next(error);\n }\n };\n}\n\nexport function createSofaRouter(config: SofaConfig) {\n const sofa = createSofa(config);\n const router = createRouter(sofa);\n return router;\n}\n"],"names":["colors.red","colors.yellow","colors.green","colors.blue","uuid","YAMLstringify"],"mappings":";;;;;;;;;;;;SAegB,gBAAgB,CAAC,GAAiB;IAChD,MAAM,EAAE,GAAG,eAAe,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAEtC,IAAI,CAAC,EAAE,EAAE;QAC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