sofa-api 0.16.1 → 0.16.3
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/index.d.ts +1 -1
- package/index.js +15 -8
- package/index.mjs +15 -8
- package/package.json +9 -9
- package/router.d.ts +1 -2
- package/types.d.ts +1 -2
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { SofaConfig } from './sofa';
|
|
2
2
|
export { OpenAPI } from './open-api';
|
|
3
|
-
export declare function useSofa(config: SofaConfig): import("@whatwg-node/router").Router<
|
|
3
|
+
export declare function useSofa(config: SofaConfig): import("@whatwg-node/router").Router<{}>;
|
package/index.js
CHANGED
|
@@ -73,12 +73,12 @@ function resolveVariable({ value, type, schema, }) {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
var _a, _b;
|
|
76
|
+
var _a, _b, _c, _d, _e;
|
|
77
77
|
const levels = ['error', 'warn', 'info', 'debug'];
|
|
78
78
|
const toLevel = (string) => levels.includes(string) ? string : null;
|
|
79
|
-
const currentLevel = ((_a = globalThis.process) === null || _a === void 0 ? void 0 : _a.env.SOFA_DEBUG)
|
|
79
|
+
const currentLevel = ((_b = (_a = globalThis.process) === null || _a === void 0 ? void 0 : _a.env) === null || _b === void 0 ? void 0 : _b.SOFA_DEBUG)
|
|
80
80
|
? 'debug'
|
|
81
|
-
: (
|
|
81
|
+
: (_e = toLevel((_d = (_c = globalThis.process) === null || _c === void 0 ? void 0 : _c.env) === null || _d === void 0 ? void 0 : _d.SOFA_LOGGER_LEVEL)) !== null && _e !== void 0 ? _e : 'info';
|
|
82
82
|
const log = (level, color, args) => {
|
|
83
83
|
if (levels.indexOf(level) <= levels.indexOf(currentLevel)) {
|
|
84
84
|
console.log(`${color(level)}:`, ...args);
|
|
@@ -330,11 +330,14 @@ function createRouter(sofa) {
|
|
|
330
330
|
router$1.post('/webhook', (request, serverContext) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
331
331
|
const { subscription, variables, url } = yield request.json();
|
|
332
332
|
try {
|
|
333
|
+
const sofaContext = Object.assign(serverContext, {
|
|
334
|
+
request,
|
|
335
|
+
});
|
|
333
336
|
const result = yield subscriptionManager.start({
|
|
334
337
|
subscription,
|
|
335
338
|
variables,
|
|
336
339
|
url,
|
|
337
|
-
},
|
|
340
|
+
}, sofaContext);
|
|
338
341
|
return new router.Response(JSON.stringify(result), {
|
|
339
342
|
status: 200,
|
|
340
343
|
statusText: 'OK',
|
|
@@ -356,8 +359,10 @@ function createRouter(sofa) {
|
|
|
356
359
|
const body = yield request.json();
|
|
357
360
|
const variables = body.variables;
|
|
358
361
|
try {
|
|
359
|
-
const
|
|
360
|
-
|
|
362
|
+
const sofaContext = Object.assign(serverContext, {
|
|
363
|
+
request,
|
|
364
|
+
});
|
|
365
|
+
const contextValue = yield sofa.contextFactory(sofaContext);
|
|
361
366
|
const result = yield subscriptionManager.update({
|
|
362
367
|
id,
|
|
363
368
|
variables,
|
|
@@ -530,8 +535,10 @@ function useHandler(config) {
|
|
|
530
535
|
}
|
|
531
536
|
});
|
|
532
537
|
}
|
|
533
|
-
const
|
|
534
|
-
|
|
538
|
+
const sofaContext = Object.assign(serverContext, {
|
|
539
|
+
request,
|
|
540
|
+
});
|
|
541
|
+
const contextValue = yield sofa.contextFactory(sofaContext);
|
|
535
542
|
const result = yield sofa.execute({
|
|
536
543
|
schema: sofa.schema,
|
|
537
544
|
document: operation,
|
package/index.mjs
CHANGED
|
@@ -67,12 +67,12 @@ function resolveVariable({ value, type, schema, }) {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
var _a, _b;
|
|
70
|
+
var _a, _b, _c, _d, _e;
|
|
71
71
|
const levels = ['error', 'warn', 'info', 'debug'];
|
|
72
72
|
const toLevel = (string) => levels.includes(string) ? string : null;
|
|
73
|
-
const currentLevel = ((_a = globalThis.process) === null || _a === void 0 ? void 0 : _a.env.SOFA_DEBUG)
|
|
73
|
+
const currentLevel = ((_b = (_a = globalThis.process) === null || _a === void 0 ? void 0 : _a.env) === null || _b === void 0 ? void 0 : _b.SOFA_DEBUG)
|
|
74
74
|
? 'debug'
|
|
75
|
-
: (
|
|
75
|
+
: (_e = toLevel((_d = (_c = globalThis.process) === null || _c === void 0 ? void 0 : _c.env) === null || _d === void 0 ? void 0 : _d.SOFA_LOGGER_LEVEL)) !== null && _e !== void 0 ? _e : 'info';
|
|
76
76
|
const log = (level, color, args) => {
|
|
77
77
|
if (levels.indexOf(level) <= levels.indexOf(currentLevel)) {
|
|
78
78
|
console.log(`${color(level)}:`, ...args);
|
|
@@ -324,11 +324,14 @@ function createRouter(sofa) {
|
|
|
324
324
|
router.post('/webhook', (request, serverContext) => __awaiter(this, void 0, void 0, function* () {
|
|
325
325
|
const { subscription, variables, url } = yield request.json();
|
|
326
326
|
try {
|
|
327
|
+
const sofaContext = Object.assign(serverContext, {
|
|
328
|
+
request,
|
|
329
|
+
});
|
|
327
330
|
const result = yield subscriptionManager.start({
|
|
328
331
|
subscription,
|
|
329
332
|
variables,
|
|
330
333
|
url,
|
|
331
|
-
},
|
|
334
|
+
}, sofaContext);
|
|
332
335
|
return new Response(JSON.stringify(result), {
|
|
333
336
|
status: 200,
|
|
334
337
|
statusText: 'OK',
|
|
@@ -350,8 +353,10 @@ function createRouter(sofa) {
|
|
|
350
353
|
const body = yield request.json();
|
|
351
354
|
const variables = body.variables;
|
|
352
355
|
try {
|
|
353
|
-
const
|
|
354
|
-
|
|
356
|
+
const sofaContext = Object.assign(serverContext, {
|
|
357
|
+
request,
|
|
358
|
+
});
|
|
359
|
+
const contextValue = yield sofa.contextFactory(sofaContext);
|
|
355
360
|
const result = yield subscriptionManager.update({
|
|
356
361
|
id,
|
|
357
362
|
variables,
|
|
@@ -524,8 +529,10 @@ function useHandler(config) {
|
|
|
524
529
|
}
|
|
525
530
|
});
|
|
526
531
|
}
|
|
527
|
-
const
|
|
528
|
-
|
|
532
|
+
const sofaContext = Object.assign(serverContext, {
|
|
533
|
+
request,
|
|
534
|
+
});
|
|
535
|
+
const contextValue = yield sofa.contextFactory(sofaContext);
|
|
529
536
|
const result = yield sofa.execute({
|
|
530
537
|
schema: sofa.schema,
|
|
531
538
|
document: operation,
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sofa-api",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.3",
|
|
4
4
|
"description": "Create REST APIs with GraphQL",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/utils": "9.
|
|
11
|
-
"@whatwg-node/fetch": "^0.6.
|
|
12
|
-
"@whatwg-node/router": "^0.
|
|
13
|
-
"ansi-colors": "4.1.3",
|
|
14
|
-
"openapi-types": "12.1.0",
|
|
15
|
-
"param-case": "3.0.4",
|
|
16
|
-
"title-case": "3.0.3",
|
|
17
|
-
"tslib": "2.5.0"
|
|
10
|
+
"@graphql-tools/utils": "^9.2.0",
|
|
11
|
+
"@whatwg-node/fetch": "^0.6.6",
|
|
12
|
+
"@whatwg-node/router": "^0.2.0",
|
|
13
|
+
"ansi-colors": "^4.1.3",
|
|
14
|
+
"openapi-types": "^12.1.0",
|
|
15
|
+
"param-case": "^3.0.4",
|
|
16
|
+
"title-case": "^3.0.3",
|
|
17
|
+
"tslib": "^2.5.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
package/router.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Sofa } from './sofa';
|
|
2
|
-
import type { DefaultSofaServerContext } from './types';
|
|
3
2
|
import { Router } from '@whatwg-node/router';
|
|
4
3
|
export type ErrorHandler = (errors: ReadonlyArray<any>) => Response;
|
|
5
4
|
declare module 'graphql' {
|
|
@@ -11,4 +10,4 @@ declare module 'graphql' {
|
|
|
11
10
|
http?: GraphQLHTTPErrorExtensions;
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
|
-
export declare function createRouter(sofa: Sofa): Router<
|
|
13
|
+
export declare function createRouter(sofa: Sofa): Router<{}>;
|
package/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DefaultServerAdapterContext } from '@whatwg-node/router';
|
|
2
1
|
import { DocumentNode } from 'graphql';
|
|
3
2
|
export type ContextValue = Record<string, any>;
|
|
4
3
|
export type Ignore = string[];
|
|
@@ -12,6 +11,6 @@ export interface RouteInfo {
|
|
|
12
11
|
}
|
|
13
12
|
export type OnRoute = (info: RouteInfo) => void;
|
|
14
13
|
export type ContextFn = (serverContext: DefaultSofaServerContext) => Promise<ContextValue> | ContextValue;
|
|
15
|
-
export type DefaultSofaServerContext =
|
|
14
|
+
export type DefaultSofaServerContext = {
|
|
16
15
|
request: Request;
|
|
17
16
|
};
|