@ttoss/graphql-api-server 0.6.11 → 0.7.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 CHANGED
@@ -1,12 +1,10 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
 
3
3
  // src/index.ts
4
+ import { App, Router, cors } from "@ttoss/http-server";
4
5
  import { buildSchema } from "@ttoss/graphql-api";
5
6
  import { CognitoJwtVerifier } from "@ttoss/auth-core/amazon-cognito";
6
7
  import { createYoga } from "graphql-yoga";
7
- import Koa from "koa";
8
- import Router from "@koa/router";
9
- import cors from "@koa/cors";
10
8
  var createServer = ({
11
9
  authenticationType,
12
10
  userPoolConfig,
@@ -14,7 +12,7 @@ var createServer = ({
14
12
  cors: corsOptions,
15
13
  ...buildSchemaInput
16
14
  }) => {
17
- const app = new Koa();
15
+ const app = new App();
18
16
  app.use(cors(corsOptions));
19
17
  const yoga = createYoga({
20
18
  schema: buildSchema(buildSchemaInput),
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
+ import { cors, App } from '@ttoss/http-server';
2
+ export { Router } from '@ttoss/http-server';
1
3
  import { BuildSchemaInput } from '@ttoss/graphql-api';
2
- import Koa from 'koa';
3
- export { default as Router } from '@koa/router';
4
- import cors from '@koa/cors';
5
4
 
6
5
  type AuthenticationType = 'AMAZON_COGNITO_USER_POOLS';
7
6
  type CreateServerInput = {
@@ -14,6 +13,6 @@ type CreateServerInput = {
14
13
  };
15
14
  cors?: cors.Options;
16
15
  } & BuildSchemaInput;
17
- declare const createServer: ({ authenticationType, userPoolConfig, graphiql, cors: corsOptions, ...buildSchemaInput }: CreateServerInput) => Koa;
16
+ declare const createServer: ({ authenticationType, userPoolConfig, graphiql, cors: corsOptions, ...buildSchemaInput }: CreateServerInput) => App;
18
17
 
19
18
  export { type AuthenticationType, type CreateServerInput, createServer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/graphql-api-server",
3
- "version": "0.6.11",
3
+ "version": "0.7.0",
4
4
  "description": "GraphQL API Server",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -11,10 +11,10 @@
11
11
  "url": "https://github.com/ttoss/ttoss.git",
12
12
  "directory": "packages/graphql-api-server"
13
13
  },
14
+ "type": "module",
14
15
  "exports": {
15
16
  ".": {
16
17
  "import": "./dist/esm/index.js",
17
- "require": "./dist/index.js",
18
18
  "types": "./dist/index.d.ts"
19
19
  }
20
20
  },
@@ -24,27 +24,21 @@
24
24
  ],
25
25
  "sideEffects": false,
26
26
  "dependencies": {
27
- "@koa/cors": "^5.0.0",
28
- "@koa/router": "^12.0.1",
29
27
  "graphql-yoga": "^5.1.1",
30
- "koa": "^2.15.0",
31
- "@ttoss/auth-core": "^0.1.10"
28
+ "@ttoss/auth-core": "^0.1.12",
29
+ "@ttoss/graphql-api": "^0.7.6",
30
+ "@ttoss/http-server": "^0.1.0"
32
31
  },
33
32
  "peerDependencies": {
34
- "graphql": "^16.6.0",
35
- "@ttoss/graphql-api": "^0.7.4"
33
+ "graphql": "^16.6.0"
36
34
  },
37
35
  "devDependencies": {
38
- "@types/koa": "^2.14.0",
39
- "@types/koa__cors": "^5.0.0",
40
- "@types/koa__router": "^12.0.4",
41
36
  "@types/supertest": "^6.0.2",
42
37
  "graphql": "^16.8.1",
43
38
  "jest": "^29.7.0",
44
39
  "supertest": "^6.3.4",
45
40
  "tsup": "^8.3.0",
46
- "@ttoss/config": "^1.32.10",
47
- "@ttoss/graphql-api": "^0.7.4"
41
+ "@ttoss/config": "^1.34.0"
48
42
  },
49
43
  "keywords": [
50
44
  "api",
@@ -57,6 +51,6 @@
57
51
  },
58
52
  "scripts": {
59
53
  "build": "tsup",
60
- "test": "jest"
54
+ "test": "jest --projects tests/unit"
61
55
  }
62
56
  }
package/src/index.ts CHANGED
@@ -1,9 +1,7 @@
1
+ import { App, Router, cors } from '@ttoss/http-server';
1
2
  import { BuildSchemaInput, buildSchema } from '@ttoss/graphql-api';
2
3
  import { CognitoJwtVerifier } from '@ttoss/auth-core/amazon-cognito';
3
4
  import { createYoga } from 'graphql-yoga';
4
- import Koa from 'koa';
5
- import Router from '@koa/router';
6
- import cors from '@koa/cors';
7
5
 
8
6
  export { Router };
9
7
 
@@ -26,15 +24,15 @@ export const createServer = ({
26
24
  graphiql,
27
25
  cors: corsOptions,
28
26
  ...buildSchemaInput
29
- }: CreateServerInput): Koa => {
30
- const app = new Koa();
27
+ }: CreateServerInput): App => {
28
+ const app = new App();
31
29
 
32
30
  app.use(cors(corsOptions));
33
31
 
34
32
  /**
35
33
  * https://the-guild.dev/graphql/yoga-server/docs/integrations/integration-with-koa
36
34
  */
37
- const yoga = createYoga<Koa.ParameterizedContext>({
35
+ const yoga = createYoga<App.ParameterizedContext>({
38
36
  schema: buildSchema(buildSchemaInput),
39
37
  graphiql,
40
38
  landingPage: false,
package/dist/index.d.mts DELETED
@@ -1,19 +0,0 @@
1
- import { BuildSchemaInput } from '@ttoss/graphql-api';
2
- import Koa from 'koa';
3
- export { default as Router } from '@koa/router';
4
- import cors from '@koa/cors';
5
-
6
- type AuthenticationType = 'AMAZON_COGNITO_USER_POOLS';
7
- type CreateServerInput = {
8
- graphiql?: boolean;
9
- authenticationType?: AuthenticationType;
10
- userPoolConfig?: {
11
- userPoolId: string;
12
- tokenUse?: 'access' | 'id';
13
- clientId: string;
14
- };
15
- cors?: cors.Options;
16
- } & BuildSchemaInput;
17
- declare const createServer: ({ authenticationType, userPoolConfig, graphiql, cors: corsOptions, ...buildSchemaInput }: CreateServerInput) => Koa;
18
-
19
- export { type AuthenticationType, type CreateServerInput, createServer };
package/dist/index.js DELETED
@@ -1,115 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- "use strict";
3
-
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __export = (target, all) => {
11
- for (var name in all) __defProp(target, name, {
12
- get: all[name],
13
- enumerable: true
14
- });
15
- };
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
- get: () => from[key],
20
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
- });
22
- }
23
- return to;
24
- };
25
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
- // If the importer is in node compatibility mode or this is not an ESM
27
- // file that has been converted to a CommonJS file using a Babel-
28
- // compatible transform (i.e. "__esModule" has not been set), then set
29
- // "default" to the CommonJS "module.exports" for node compatibility.
30
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
31
- value: mod,
32
- enumerable: true
33
- }) : target, mod));
34
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
35
- value: true
36
- }), mod);
37
-
38
- // src/index.ts
39
- var src_exports = {};
40
- __export(src_exports, {
41
- Router: () => import_router.default,
42
- createServer: () => createServer
43
- });
44
- module.exports = __toCommonJS(src_exports);
45
- var import_graphql_api = require("@ttoss/graphql-api");
46
- var import_amazon_cognito = require("@ttoss/auth-core/amazon-cognito");
47
- var import_graphql_yoga = require("graphql-yoga");
48
- var import_koa = __toESM(require("koa"));
49
- var import_router = __toESM(require("@koa/router"));
50
- var import_cors = __toESM(require("@koa/cors"));
51
- var createServer = ({
52
- authenticationType,
53
- userPoolConfig,
54
- graphiql,
55
- cors: corsOptions,
56
- ...buildSchemaInput
57
- }) => {
58
- const app = new import_koa.default();
59
- app.use((0, import_cors.default)(corsOptions));
60
- const yoga = (0, import_graphql_yoga.createYoga)({
61
- schema: (0, import_graphql_api.buildSchema)(buildSchemaInput),
62
- graphiql,
63
- landingPage: false,
64
- logging: false,
65
- /**
66
- * Disable CORS, as it's handled by Koa middleware
67
- */
68
- cors: false
69
- });
70
- const jwtVerifier = (() => {
71
- if (authenticationType === "AMAZON_COGNITO_USER_POOLS") {
72
- if (!userPoolConfig) {
73
- throw new Error("userPoolConfig is required when using AMAZON_COGNITO_USER_POOLS authenticationType");
74
- }
75
- return import_amazon_cognito.CognitoJwtVerifier.create({
76
- tokenUse: "access",
77
- ...userPoolConfig
78
- });
79
- }
80
- return null;
81
- })();
82
- app.use(async (ctx, next) => {
83
- if (ctx.path !== "/graphql") {
84
- return next();
85
- }
86
- const isGraphiqlRequest = ctx.headers.accept?.includes("text/html") && graphiql;
87
- if (!isGraphiqlRequest) {
88
- try {
89
- if (authenticationType === "AMAZON_COGNITO_USER_POOLS" && jwtVerifier) {
90
- const token = ctx.headers.authorization?.replace("Bearer ", "");
91
- const identity = await jwtVerifier.verify(token || "");
92
- ctx.identity = identity;
93
- }
94
- } catch {
95
- ctx.status = 401;
96
- ctx.body = "Unauthorized";
97
- return;
98
- }
99
- }
100
- const response = await yoga.handleNodeRequest(ctx.req, ctx);
101
- ctx.status = response.status;
102
- for (const [key, value] of response.headers.entries()) {
103
- if (ctx.status != 401) {
104
- ctx.append(key, value);
105
- }
106
- }
107
- ctx.body = response.body;
108
- });
109
- return app;
110
- };
111
- // Annotate the CommonJS export names for ESM import in node:
112
- 0 && (module.exports = {
113
- Router,
114
- createServer
115
- });