@graphql-yoga/plugin-sofa 3.6.1 → 3.6.2-alpha-20240724000308-79fedfd8
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/cjs/index.js +12 -8
- package/esm/index.js +12 -8
- package/package.json +2 -1
package/cjs/index.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSofa = useSofa;
|
|
4
4
|
const sofa_api_1 = require("sofa-api");
|
|
5
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
5
6
|
function useSofa(config) {
|
|
6
7
|
let sofaHandler;
|
|
7
8
|
let getEnveloped;
|
|
8
9
|
const envelopedByContext = new WeakMap();
|
|
9
|
-
const requestByContext = new WeakMap();
|
|
10
10
|
return {
|
|
11
11
|
onYogaInit({ yoga }) {
|
|
12
12
|
getEnveloped = yoga.getEnveloped;
|
|
@@ -15,12 +15,17 @@ function useSofa(config) {
|
|
|
15
15
|
sofaHandler = (0, sofa_api_1.useSofa)({
|
|
16
16
|
...config,
|
|
17
17
|
schema: onSchemaChangeEventPayload.schema,
|
|
18
|
-
|
|
18
|
+
context(serverContext) {
|
|
19
19
|
const enveloped = getEnveloped(serverContext);
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const contextValue$ = enveloped.contextFactory(serverContext);
|
|
21
|
+
if ((0, utils_1.isPromise)(contextValue$)) {
|
|
22
|
+
return contextValue$.then(contextValue => {
|
|
23
|
+
envelopedByContext.set(contextValue, enveloped);
|
|
24
|
+
return contextValue;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
envelopedByContext.set(contextValue$, enveloped);
|
|
28
|
+
return contextValue$;
|
|
24
29
|
},
|
|
25
30
|
execute(...args) {
|
|
26
31
|
const executionArgs = args.length === 1
|
|
@@ -63,8 +68,7 @@ function useSofa(config) {
|
|
|
63
68
|
});
|
|
64
69
|
},
|
|
65
70
|
async onRequest({ request, serverContext, endResponse }) {
|
|
66
|
-
|
|
67
|
-
const response = await sofaHandler.handle(request, serverContext);
|
|
71
|
+
const response = await sofaHandler(request, serverContext);
|
|
68
72
|
if (response != null && response.status !== 404) {
|
|
69
73
|
endResponse(response);
|
|
70
74
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useSofa as createSofaHandler } from 'sofa-api';
|
|
2
|
+
import { isPromise } from '@graphql-tools/utils';
|
|
2
3
|
export function useSofa(config) {
|
|
3
4
|
let sofaHandler;
|
|
4
5
|
let getEnveloped;
|
|
5
6
|
const envelopedByContext = new WeakMap();
|
|
6
|
-
const requestByContext = new WeakMap();
|
|
7
7
|
return {
|
|
8
8
|
onYogaInit({ yoga }) {
|
|
9
9
|
getEnveloped = yoga.getEnveloped;
|
|
@@ -12,12 +12,17 @@ export function useSofa(config) {
|
|
|
12
12
|
sofaHandler = createSofaHandler({
|
|
13
13
|
...config,
|
|
14
14
|
schema: onSchemaChangeEventPayload.schema,
|
|
15
|
-
|
|
15
|
+
context(serverContext) {
|
|
16
16
|
const enveloped = getEnveloped(serverContext);
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const contextValue$ = enveloped.contextFactory(serverContext);
|
|
18
|
+
if (isPromise(contextValue$)) {
|
|
19
|
+
return contextValue$.then(contextValue => {
|
|
20
|
+
envelopedByContext.set(contextValue, enveloped);
|
|
21
|
+
return contextValue;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
envelopedByContext.set(contextValue$, enveloped);
|
|
25
|
+
return contextValue$;
|
|
21
26
|
},
|
|
22
27
|
execute(...args) {
|
|
23
28
|
const executionArgs = args.length === 1
|
|
@@ -60,8 +65,7 @@ export function useSofa(config) {
|
|
|
60
65
|
});
|
|
61
66
|
},
|
|
62
67
|
async onRequest({ request, serverContext, endResponse }) {
|
|
63
|
-
|
|
64
|
-
const response = await sofaHandler.handle(request, serverContext);
|
|
68
|
+
const response = await sofaHandler(request, serverContext);
|
|
65
69
|
if (response != null && response.status !== 404) {
|
|
66
70
|
endResponse(response);
|
|
67
71
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-yoga/plugin-sofa",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.2-alpha-20240724000308-79fedfd8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^15.2.0 || ^16.0.0",
|
|
7
7
|
"graphql-yoga": "^5.6.1"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
+
"@graphql-tools/utils": "^10.3.2",
|
|
10
11
|
"sofa-api": "^0.18.0"
|
|
11
12
|
},
|
|
12
13
|
"repository": {
|