@ttoss/graphql-api-server 0.5.2 → 0.5.4
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 +16 -0
- package/dist/esm/index.js +8 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +8 -1
- package/package.json +3 -1
- package/src/index.ts +9 -0
package/README.md
CHANGED
|
@@ -155,3 +155,19 @@ server.listen(3000, () => {
|
|
|
155
155
|
console.log('Server listening on port 3000');
|
|
156
156
|
});
|
|
157
157
|
```
|
|
158
|
+
|
|
159
|
+
## CORS
|
|
160
|
+
|
|
161
|
+
You can enable CORS by setting the `cors` option. You can check the available options on [@koa/cors package](https://github.com/koajs/cors?tab=readme-ov-file#corsoptions).
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
import { createServer } from '@ttoss/graphql-api-server';
|
|
165
|
+
|
|
166
|
+
const server = createServer({
|
|
167
|
+
schemaComposer,
|
|
168
|
+
cors: {
|
|
169
|
+
origin: '*',
|
|
170
|
+
allowMethods: ['GET', 'POST'],
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
```
|
package/dist/esm/index.js
CHANGED
|
@@ -6,18 +6,25 @@ import { CognitoJwtVerifier } from "@ttoss/auth-core/amazon-cognito";
|
|
|
6
6
|
import { createYoga } from "graphql-yoga";
|
|
7
7
|
import Koa from "koa";
|
|
8
8
|
import Router from "@koa/router";
|
|
9
|
+
import cors from "@koa/cors";
|
|
9
10
|
var createServer = ({
|
|
10
11
|
authenticationType,
|
|
11
12
|
userPoolConfig,
|
|
12
13
|
graphiql,
|
|
14
|
+
cors: corsOptions,
|
|
13
15
|
...buildSchemaInput
|
|
14
16
|
}) => {
|
|
15
17
|
const app = new Koa();
|
|
18
|
+
app.use(cors(corsOptions));
|
|
16
19
|
const yoga = createYoga({
|
|
17
20
|
schema: buildSchema(buildSchemaInput),
|
|
18
21
|
graphiql,
|
|
19
22
|
landingPage: false,
|
|
20
|
-
logging: false
|
|
23
|
+
logging: false,
|
|
24
|
+
/**
|
|
25
|
+
* Disable CORS, as it's handled by Koa middleware
|
|
26
|
+
*/
|
|
27
|
+
cors: false
|
|
21
28
|
});
|
|
22
29
|
const jwtVerifier = (() => {
|
|
23
30
|
if (authenticationType === "AMAZON_COGNITO_USER_POOLS") {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BuildSchemaInput } from '@ttoss/graphql-api';
|
|
2
2
|
import Koa from 'koa';
|
|
3
3
|
export { default as Router } from '@koa/router';
|
|
4
|
+
import cors from '@koa/cors';
|
|
4
5
|
|
|
5
6
|
type AuthenticationType = 'AMAZON_COGNITO_USER_POOLS';
|
|
6
7
|
type CreateServerInput = {
|
|
@@ -11,7 +12,8 @@ type CreateServerInput = {
|
|
|
11
12
|
tokenUse?: 'access' | 'id';
|
|
12
13
|
clientId: string;
|
|
13
14
|
};
|
|
15
|
+
cors?: cors.Options;
|
|
14
16
|
} & BuildSchemaInput;
|
|
15
|
-
declare const createServer: ({ authenticationType, userPoolConfig, graphiql, ...buildSchemaInput }: CreateServerInput) => Koa;
|
|
17
|
+
declare const createServer: ({ authenticationType, userPoolConfig, graphiql, cors: corsOptions, ...buildSchemaInput }: CreateServerInput) => Koa;
|
|
16
18
|
|
|
17
19
|
export { type AuthenticationType, type CreateServerInput, createServer };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BuildSchemaInput } from '@ttoss/graphql-api';
|
|
2
2
|
import Koa from 'koa';
|
|
3
3
|
export { default as Router } from '@koa/router';
|
|
4
|
+
import cors from '@koa/cors';
|
|
4
5
|
|
|
5
6
|
type AuthenticationType = 'AMAZON_COGNITO_USER_POOLS';
|
|
6
7
|
type CreateServerInput = {
|
|
@@ -11,7 +12,8 @@ type CreateServerInput = {
|
|
|
11
12
|
tokenUse?: 'access' | 'id';
|
|
12
13
|
clientId: string;
|
|
13
14
|
};
|
|
15
|
+
cors?: cors.Options;
|
|
14
16
|
} & BuildSchemaInput;
|
|
15
|
-
declare const createServer: ({ authenticationType, userPoolConfig, graphiql, ...buildSchemaInput }: CreateServerInput) => Koa;
|
|
17
|
+
declare const createServer: ({ authenticationType, userPoolConfig, graphiql, cors: corsOptions, ...buildSchemaInput }: CreateServerInput) => Koa;
|
|
16
18
|
|
|
17
19
|
export { type AuthenticationType, type CreateServerInput, createServer };
|
package/dist/index.js
CHANGED
|
@@ -47,18 +47,25 @@ var import_amazon_cognito = require("@ttoss/auth-core/amazon-cognito");
|
|
|
47
47
|
var import_graphql_yoga = require("graphql-yoga");
|
|
48
48
|
var import_koa = __toESM(require("koa"));
|
|
49
49
|
var import_router = __toESM(require("@koa/router"));
|
|
50
|
+
var import_cors = __toESM(require("@koa/cors"));
|
|
50
51
|
var createServer = ({
|
|
51
52
|
authenticationType,
|
|
52
53
|
userPoolConfig,
|
|
53
54
|
graphiql,
|
|
55
|
+
cors: corsOptions,
|
|
54
56
|
...buildSchemaInput
|
|
55
57
|
}) => {
|
|
56
58
|
const app = new import_koa.default();
|
|
59
|
+
app.use((0, import_cors.default)(corsOptions));
|
|
57
60
|
const yoga = (0, import_graphql_yoga.createYoga)({
|
|
58
61
|
schema: (0, import_graphql_api.buildSchema)(buildSchemaInput),
|
|
59
62
|
graphiql,
|
|
60
63
|
landingPage: false,
|
|
61
|
-
logging: false
|
|
64
|
+
logging: false,
|
|
65
|
+
/**
|
|
66
|
+
* Disable CORS, as it's handled by Koa middleware
|
|
67
|
+
*/
|
|
68
|
+
cors: false
|
|
62
69
|
});
|
|
63
70
|
const jwtVerifier = (() => {
|
|
64
71
|
if (authenticationType === "AMAZON_COGNITO_USER_POOLS") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/graphql-api-server",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "GraphQL API Server",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"typings": "dist/index.d.ts",
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"@koa/cors": "^5.0.0",
|
|
23
24
|
"@koa/router": "^12.0.1",
|
|
24
25
|
"graphql-yoga": "^5.1.1",
|
|
25
26
|
"koa": "^2.15.0",
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@types/koa": "^2.14.0",
|
|
35
|
+
"@types/koa__cors": "^5.0.0",
|
|
34
36
|
"@types/koa__router": "^12.0.4",
|
|
35
37
|
"@types/supertest": "^6.0.2",
|
|
36
38
|
"graphql": "^16.8.1",
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { CognitoJwtVerifier } from '@ttoss/auth-core/amazon-cognito';
|
|
|
3
3
|
import { createYoga } from 'graphql-yoga';
|
|
4
4
|
import Koa from 'koa';
|
|
5
5
|
import Router from '@koa/router';
|
|
6
|
+
import cors from '@koa/cors';
|
|
6
7
|
|
|
7
8
|
export { Router };
|
|
8
9
|
|
|
@@ -16,16 +17,20 @@ export type CreateServerInput = {
|
|
|
16
17
|
tokenUse?: 'access' | 'id';
|
|
17
18
|
clientId: string;
|
|
18
19
|
};
|
|
20
|
+
cors?: cors.Options;
|
|
19
21
|
} & BuildSchemaInput;
|
|
20
22
|
|
|
21
23
|
export const createServer = ({
|
|
22
24
|
authenticationType,
|
|
23
25
|
userPoolConfig,
|
|
24
26
|
graphiql,
|
|
27
|
+
cors: corsOptions,
|
|
25
28
|
...buildSchemaInput
|
|
26
29
|
}: CreateServerInput): Koa => {
|
|
27
30
|
const app = new Koa();
|
|
28
31
|
|
|
32
|
+
app.use(cors(corsOptions));
|
|
33
|
+
|
|
29
34
|
/**
|
|
30
35
|
* https://the-guild.dev/graphql/yoga-server/docs/integrations/integration-with-koa
|
|
31
36
|
*/
|
|
@@ -34,6 +39,10 @@ export const createServer = ({
|
|
|
34
39
|
graphiql,
|
|
35
40
|
landingPage: false,
|
|
36
41
|
logging: false,
|
|
42
|
+
/**
|
|
43
|
+
* Disable CORS, as it's handled by Koa middleware
|
|
44
|
+
*/
|
|
45
|
+
cors: false,
|
|
37
46
|
});
|
|
38
47
|
|
|
39
48
|
const jwtVerifier = (() => {
|