@ttoss/graphql-api-server 0.4.0 → 0.5.0
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/dist/esm/index.js +14 -10
- package/dist/index.js +14 -10
- package/package.json +2 -1
- package/src/index.ts +19 -13
package/dist/esm/index.js
CHANGED
|
@@ -30,16 +30,18 @@ var createServer = ({
|
|
|
30
30
|
method: ctx.method,
|
|
31
31
|
query: ctx.request.query
|
|
32
32
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
if (request.method !== "GET" && request.headers.referer !== "http://localhost:4000/graphql") {
|
|
34
|
+
try {
|
|
35
|
+
if (authenticationType === "AMAZON_COGNITO_USER_POOLS" && jwtVerifier) {
|
|
36
|
+
const token = request.headers.authorization?.replace("Bearer ", "");
|
|
37
|
+
const identity = await jwtVerifier.verify(token || "");
|
|
38
|
+
ctx.identity = identity;
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
ctx.status = 401;
|
|
42
|
+
ctx.body = "Unauthorized";
|
|
43
|
+
return;
|
|
38
44
|
}
|
|
39
|
-
} catch {
|
|
40
|
-
ctx.status = 401;
|
|
41
|
-
ctx.body = "Unauthorized";
|
|
42
|
-
return;
|
|
43
45
|
}
|
|
44
46
|
const operationName = request.body;
|
|
45
47
|
const query = request.headers;
|
|
@@ -51,7 +53,9 @@ var createServer = ({
|
|
|
51
53
|
const response = await yoga.handleNodeRequest(ctx.req, ctx);
|
|
52
54
|
ctx.status = response.status;
|
|
53
55
|
for (const [key, value] of response.headers.entries()) {
|
|
54
|
-
ctx.
|
|
56
|
+
if (ctx.status != 401) {
|
|
57
|
+
ctx.append(key, value);
|
|
58
|
+
}
|
|
55
59
|
}
|
|
56
60
|
ctx.body = response.body;
|
|
57
61
|
});
|
package/dist/index.js
CHANGED
|
@@ -70,16 +70,18 @@ var createServer = ({
|
|
|
70
70
|
method: ctx.method,
|
|
71
71
|
query: ctx.request.query
|
|
72
72
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
if (request.method !== "GET" && request.headers.referer !== "http://localhost:4000/graphql") {
|
|
74
|
+
try {
|
|
75
|
+
if (authenticationType === "AMAZON_COGNITO_USER_POOLS" && jwtVerifier) {
|
|
76
|
+
const token = request.headers.authorization?.replace("Bearer ", "");
|
|
77
|
+
const identity = await jwtVerifier.verify(token || "");
|
|
78
|
+
ctx.identity = identity;
|
|
79
|
+
}
|
|
80
|
+
} catch {
|
|
81
|
+
ctx.status = 401;
|
|
82
|
+
ctx.body = "Unauthorized";
|
|
83
|
+
return;
|
|
78
84
|
}
|
|
79
|
-
} catch {
|
|
80
|
-
ctx.status = 401;
|
|
81
|
-
ctx.body = "Unauthorized";
|
|
82
|
-
return;
|
|
83
85
|
}
|
|
84
86
|
const operationName = request.body;
|
|
85
87
|
const query = request.headers;
|
|
@@ -91,7 +93,9 @@ var createServer = ({
|
|
|
91
93
|
const response = await yoga.handleNodeRequest(ctx.req, ctx);
|
|
92
94
|
ctx.status = response.status;
|
|
93
95
|
for (const [key, value] of response.headers.entries()) {
|
|
94
|
-
ctx.
|
|
96
|
+
if (ctx.status != 401) {
|
|
97
|
+
ctx.append(key, value);
|
|
98
|
+
}
|
|
95
99
|
}
|
|
96
100
|
ctx.body = response.body;
|
|
97
101
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/graphql-api-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "GraphQL API Server",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@koa/cors": "^4.0.0",
|
|
24
24
|
"@koa/router": "^12.0.1",
|
|
25
|
+
"@types/supertest": "^6.0.2",
|
|
25
26
|
"aws-jwt-verify": "^4.0.0",
|
|
26
27
|
"graphql-helix": "^1.13.0",
|
|
27
28
|
"graphql-yoga": "^5.0.2",
|
package/src/index.ts
CHANGED
|
@@ -29,7 +29,6 @@ export const createServer = ({
|
|
|
29
29
|
'userPoolConfig is required when using AMAZON_COGNITO_USER_POOLS authenticationType'
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
|
-
|
|
33
32
|
return CognitoJwtVerifier.create({
|
|
34
33
|
tokenUse: 'access',
|
|
35
34
|
...userPoolConfig,
|
|
@@ -47,20 +46,25 @@ export const createServer = ({
|
|
|
47
46
|
query: ctx.request.query,
|
|
48
47
|
};
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
if (
|
|
50
|
+
request.method !== 'GET' &&
|
|
51
|
+
request.headers.referer !== 'http://localhost:4000/graphql'
|
|
52
|
+
) {
|
|
53
|
+
try {
|
|
54
|
+
if (authenticationType === 'AMAZON_COGNITO_USER_POOLS' && jwtVerifier) {
|
|
55
|
+
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
56
|
+
const identity = await jwtVerifier.verify(token || '');
|
|
57
|
+
|
|
58
|
+
ctx.identity = identity;
|
|
59
|
+
}
|
|
60
|
+
} catch {
|
|
61
|
+
ctx.status = 401;
|
|
62
|
+
ctx.body = 'Unauthorized';
|
|
63
|
+
return;
|
|
57
64
|
}
|
|
58
|
-
} catch {
|
|
59
|
-
ctx.status = 401;
|
|
60
|
-
ctx.body = 'Unauthorized';
|
|
61
|
-
return;
|
|
62
65
|
}
|
|
63
66
|
|
|
67
|
+
//console.log(ctx.identity);
|
|
64
68
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
65
69
|
const operationName = request.body;
|
|
66
70
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -80,7 +84,9 @@ export const createServer = ({
|
|
|
80
84
|
|
|
81
85
|
// Set headers
|
|
82
86
|
for (const [key, value] of response.headers.entries()) {
|
|
83
|
-
ctx.
|
|
87
|
+
if (ctx.status != 401) {
|
|
88
|
+
ctx.append(key, value);
|
|
89
|
+
}
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
ctx.body = response.body;
|