@graphql-mesh/http 1.0.0-alpha-20230424113259-560b18922 → 1.0.0-alpha-20230522105300-fe9c79867

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.
@@ -7,8 +7,6 @@ const graphqlHandler = (getBuiltMesh, playgroundTitle, playgroundEnabled, graphq
7
7
  return (request, ...args) => {
8
8
  if (!yoga$) {
9
9
  yoga$ = getBuiltMesh().then(mesh => (0, graphql_yoga_1.createYoga)({
10
- parserCache: false,
11
- validationCache: false,
12
10
  plugins: [
13
11
  ...mesh.plugins,
14
12
  (0, graphql_yoga_1.useLogger)({
package/cjs/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createMeshHTTPHandler = void 0;
4
+ const fets_1 = require("fets");
4
5
  const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
5
6
  const utils_1 = require("@graphql-mesh/utils");
6
- const router_1 = require("@whatwg-node/router");
7
7
  const graphqlHandler_js_1 = require("./graphqlHandler.js");
8
8
  function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, playgroundTitle, }) {
9
9
  let readyFlag = false;
@@ -13,67 +13,101 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, pla
13
13
  // TODO
14
14
  // trustProxy = 'loopback',
15
15
  } = rawServeConfig;
16
- const router = (0, router_1.createRouter)();
17
- router.all('*', () => {
18
- if (!mesh$) {
19
- mesh$ = getBuiltMesh().then(mesh => {
20
- readyFlag = true;
21
- logger = mesh.logger.child('HTTP');
22
- return mesh;
16
+ const router = (0, fets_1.createRouter)();
17
+ router
18
+ .route({
19
+ path: '*',
20
+ handler() {
21
+ if (!mesh$) {
22
+ mesh$ = getBuiltMesh().then(mesh => {
23
+ readyFlag = true;
24
+ logger = mesh.logger.child('HTTP');
25
+ return mesh;
26
+ });
27
+ }
28
+ },
29
+ })
30
+ .route({
31
+ path: '/healthcheck',
32
+ handler() {
33
+ return new fets_1.Response(null, {
34
+ status: 200,
23
35
  });
24
- }
25
- });
26
- router.all('/healthcheck', () => new router_1.Response(null, {
27
- status: 200,
28
- }));
29
- router.all('/readiness', () => new router_1.Response(null, {
30
- status: readyFlag ? 204 : 503,
31
- }));
32
- router.post('*', async (request) => {
33
- if (readyFlag) {
34
- const { pubsub } = await mesh$;
35
- for (const eventName of pubsub.getEventNames()) {
36
- const { pathname } = new URL(request.url);
37
- if (eventName === `webhook:${request.method.toLowerCase()}:${pathname}`) {
38
- const body = await request.text();
39
- logger.debug(`Received webhook request for ${pathname}`, body);
40
- pubsub.publish(eventName, request.headers.get('content-type') === 'application/json' ? JSON.parse(body) : body);
41
- return new router_1.Response(null, {
42
- status: 204,
43
- statusText: 'OK',
44
- });
36
+ },
37
+ })
38
+ .route({
39
+ path: '/readiness',
40
+ handler() {
41
+ return new fets_1.Response(null, {
42
+ status: readyFlag ? 204 : 503,
43
+ });
44
+ },
45
+ })
46
+ .route({
47
+ path: '*',
48
+ method: 'POST',
49
+ async handler(request) {
50
+ if (readyFlag) {
51
+ const { pubsub } = await mesh$;
52
+ for (const eventName of pubsub.getEventNames()) {
53
+ const { pathname } = new URL(request.url);
54
+ if (eventName === `webhook:${request.method.toLowerCase()}:${pathname}`) {
55
+ const body = await request.text();
56
+ logger.debug(`Received webhook request for ${pathname}`, body);
57
+ pubsub.publish(eventName, request.headers.get('content-type') === 'application/json'
58
+ ? JSON.parse(body)
59
+ : body);
60
+ return new fets_1.Response(null, {
61
+ status: 204,
62
+ statusText: 'OK',
63
+ });
64
+ }
45
65
  }
46
66
  }
47
- }
48
- return undefined;
67
+ return undefined;
68
+ },
49
69
  });
50
70
  if (staticFiles) {
51
- router.get('/:relativePath+', async (request) => {
52
- let { relativePath } = request.params;
53
- if (!relativePath) {
54
- relativePath = 'index.html';
55
- }
56
- const absoluteStaticFilesPath = cross_helpers_1.path.join(baseDir, staticFiles);
57
- const absolutePath = cross_helpers_1.path.join(absoluteStaticFilesPath, relativePath);
58
- if (absolutePath.startsWith(absoluteStaticFilesPath) && (await (0, utils_1.pathExists)(absolutePath))) {
59
- const readStream = cross_helpers_1.fs.createReadStream(absolutePath);
60
- return new router_1.Response(readStream, {
61
- status: 200,
62
- });
63
- }
64
- return undefined;
71
+ router.route({
72
+ path: '/:relativePath+',
73
+ method: 'GET',
74
+ async handler(request) {
75
+ let { relativePath } = request.params;
76
+ if (!relativePath) {
77
+ relativePath = 'index.html';
78
+ }
79
+ const absoluteStaticFilesPath = cross_helpers_1.path.join(baseDir, staticFiles);
80
+ const absolutePath = cross_helpers_1.path.join(absoluteStaticFilesPath, relativePath);
81
+ if (absolutePath.startsWith(absoluteStaticFilesPath) && (await (0, utils_1.pathExists)(absolutePath))) {
82
+ const readStream = cross_helpers_1.fs.createReadStream(absolutePath);
83
+ return new fets_1.Response(readStream, {
84
+ status: 200,
85
+ });
86
+ }
87
+ return undefined;
88
+ },
65
89
  });
66
90
  }
67
91
  else if (graphqlPath !== '/') {
68
- router.get('/', () => new router_1.Response(null, {
69
- status: 302,
70
- headers: {
71
- Location: graphqlPath,
92
+ router.route({
93
+ path: '/',
94
+ method: 'GET',
95
+ handler() {
96
+ return new fets_1.Response(null, {
97
+ status: 302,
98
+ headers: {
99
+ Location: graphqlPath,
100
+ },
101
+ });
72
102
  },
73
- }));
103
+ });
74
104
  }
75
- router.all('*', utils_1.withCookies);
76
- router.all('*', (0, graphqlHandler_js_1.graphqlHandler)(() => mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig));
77
- return router;
105
+ return router.route({
106
+ path: '*',
107
+ handler: [
108
+ utils_1.withCookies,
109
+ (0, graphqlHandler_js_1.graphqlHandler)(() => mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig),
110
+ ],
111
+ });
78
112
  }
79
113
  exports.createMeshHTTPHandler = createMeshHTTPHandler;
@@ -4,8 +4,6 @@ export const graphqlHandler = (getBuiltMesh, playgroundTitle, playgroundEnabled,
4
4
  return (request, ...args) => {
5
5
  if (!yoga$) {
6
6
  yoga$ = getBuiltMesh().then(mesh => createYoga({
7
- parserCache: false,
8
- validationCache: false,
9
7
  plugins: [
10
8
  ...mesh.plugins,
11
9
  useLogger({
package/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { createRouter, Response } from 'fets';
1
2
  import { fs, path } from '@graphql-mesh/cross-helpers';
2
3
  import { DefaultLogger, pathExists, withCookies } from '@graphql-mesh/utils';
3
- import { createRouter, Response } from '@whatwg-node/router';
4
4
  import { graphqlHandler } from './graphqlHandler.js';
5
5
  export function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, playgroundTitle, }) {
6
6
  let readyFlag = false;
@@ -11,65 +11,99 @@ export function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig =
11
11
  // trustProxy = 'loopback',
12
12
  } = rawServeConfig;
13
13
  const router = createRouter();
14
- router.all('*', () => {
15
- if (!mesh$) {
16
- mesh$ = getBuiltMesh().then(mesh => {
17
- readyFlag = true;
18
- logger = mesh.logger.child('HTTP');
19
- return mesh;
14
+ router
15
+ .route({
16
+ path: '*',
17
+ handler() {
18
+ if (!mesh$) {
19
+ mesh$ = getBuiltMesh().then(mesh => {
20
+ readyFlag = true;
21
+ logger = mesh.logger.child('HTTP');
22
+ return mesh;
23
+ });
24
+ }
25
+ },
26
+ })
27
+ .route({
28
+ path: '/healthcheck',
29
+ handler() {
30
+ return new Response(null, {
31
+ status: 200,
20
32
  });
21
- }
22
- });
23
- router.all('/healthcheck', () => new Response(null, {
24
- status: 200,
25
- }));
26
- router.all('/readiness', () => new Response(null, {
27
- status: readyFlag ? 204 : 503,
28
- }));
29
- router.post('*', async (request) => {
30
- if (readyFlag) {
31
- const { pubsub } = await mesh$;
32
- for (const eventName of pubsub.getEventNames()) {
33
- const { pathname } = new URL(request.url);
34
- if (eventName === `webhook:${request.method.toLowerCase()}:${pathname}`) {
35
- const body = await request.text();
36
- logger.debug(`Received webhook request for ${pathname}`, body);
37
- pubsub.publish(eventName, request.headers.get('content-type') === 'application/json' ? JSON.parse(body) : body);
38
- return new Response(null, {
39
- status: 204,
40
- statusText: 'OK',
41
- });
33
+ },
34
+ })
35
+ .route({
36
+ path: '/readiness',
37
+ handler() {
38
+ return new Response(null, {
39
+ status: readyFlag ? 204 : 503,
40
+ });
41
+ },
42
+ })
43
+ .route({
44
+ path: '*',
45
+ method: 'POST',
46
+ async handler(request) {
47
+ if (readyFlag) {
48
+ const { pubsub } = await mesh$;
49
+ for (const eventName of pubsub.getEventNames()) {
50
+ const { pathname } = new URL(request.url);
51
+ if (eventName === `webhook:${request.method.toLowerCase()}:${pathname}`) {
52
+ const body = await request.text();
53
+ logger.debug(`Received webhook request for ${pathname}`, body);
54
+ pubsub.publish(eventName, request.headers.get('content-type') === 'application/json'
55
+ ? JSON.parse(body)
56
+ : body);
57
+ return new Response(null, {
58
+ status: 204,
59
+ statusText: 'OK',
60
+ });
61
+ }
42
62
  }
43
63
  }
44
- }
45
- return undefined;
64
+ return undefined;
65
+ },
46
66
  });
47
67
  if (staticFiles) {
48
- router.get('/:relativePath+', async (request) => {
49
- let { relativePath } = request.params;
50
- if (!relativePath) {
51
- relativePath = 'index.html';
52
- }
53
- const absoluteStaticFilesPath = path.join(baseDir, staticFiles);
54
- const absolutePath = path.join(absoluteStaticFilesPath, relativePath);
55
- if (absolutePath.startsWith(absoluteStaticFilesPath) && (await pathExists(absolutePath))) {
56
- const readStream = fs.createReadStream(absolutePath);
57
- return new Response(readStream, {
58
- status: 200,
59
- });
60
- }
61
- return undefined;
68
+ router.route({
69
+ path: '/:relativePath+',
70
+ method: 'GET',
71
+ async handler(request) {
72
+ let { relativePath } = request.params;
73
+ if (!relativePath) {
74
+ relativePath = 'index.html';
75
+ }
76
+ const absoluteStaticFilesPath = path.join(baseDir, staticFiles);
77
+ const absolutePath = path.join(absoluteStaticFilesPath, relativePath);
78
+ if (absolutePath.startsWith(absoluteStaticFilesPath) && (await pathExists(absolutePath))) {
79
+ const readStream = fs.createReadStream(absolutePath);
80
+ return new Response(readStream, {
81
+ status: 200,
82
+ });
83
+ }
84
+ return undefined;
85
+ },
62
86
  });
63
87
  }
64
88
  else if (graphqlPath !== '/') {
65
- router.get('/', () => new Response(null, {
66
- status: 302,
67
- headers: {
68
- Location: graphqlPath,
89
+ router.route({
90
+ path: '/',
91
+ method: 'GET',
92
+ handler() {
93
+ return new Response(null, {
94
+ status: 302,
95
+ headers: {
96
+ Location: graphqlPath,
97
+ },
98
+ });
69
99
  },
70
- }));
100
+ });
71
101
  }
72
- router.all('*', withCookies);
73
- router.all('*', graphqlHandler(() => mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig));
74
- return router;
102
+ return router.route({
103
+ path: '*',
104
+ handler: [
105
+ withCookies,
106
+ graphqlHandler(() => mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig),
107
+ ],
108
+ });
75
109
  }
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@graphql-mesh/http",
3
- "version": "1.0.0-alpha-20230424113259-560b18922",
3
+ "version": "1.0.0-alpha-20230522105300-fe9c79867",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@graphql-mesh/cross-helpers": "^0.3.4",
7
- "@graphql-mesh/types": "1.0.0-alpha-20230424113259-560b18922",
8
- "@graphql-mesh/utils": "1.0.0-alpha-20230424113259-560b18922",
6
+ "@graphql-mesh/cross-helpers": "0.4.0-alpha-20230522105300-fe9c79867",
7
+ "@graphql-mesh/runtime": "1.0.0-alpha-20230522105300-fe9c79867",
8
+ "@graphql-mesh/types": "1.0.0-alpha-20230522105300-fe9c79867",
9
+ "@graphql-mesh/utils": "1.0.0-alpha-20230522105300-fe9c79867",
9
10
  "graphql": "*",
10
11
  "tslib": "^2.4.0"
11
12
  },
12
13
  "dependencies": {
13
- "@graphql-mesh/runtime": "1.0.0-alpha-20230424113259-560b18922",
14
- "@whatwg-node/router": "0.3.0",
15
- "graphql-yoga": "3.9.1"
14
+ "fets": "^0.1.1",
15
+ "graphql-yoga": "^3.9.1"
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
@@ -1,7 +1,7 @@
1
- import { MeshInstance } from '@graphql-mesh/runtime';
1
+ import { Router } from 'fets';
2
+ import type { MeshInstance } from '@graphql-mesh/runtime';
2
3
  import { YamlConfig } from '@graphql-mesh/types';
3
- import { Router } from '@whatwg-node/router';
4
- export type MeshHTTPHandler<TServerContext> = Router<TServerContext>;
4
+ export type MeshHTTPHandler<TServerContext> = Router<TServerContext, {}, {}>;
5
5
  export declare function createMeshHTTPHandler<TServerContext>({ baseDir, getBuiltMesh, rawServeConfig, playgroundTitle, }: {
6
6
  baseDir: string;
7
7
  getBuiltMesh: () => Promise<MeshInstance>;
@@ -1,7 +1,7 @@
1
- import { MeshInstance } from '@graphql-mesh/runtime';
1
+ import { Router } from 'fets';
2
+ import type { MeshInstance } from '@graphql-mesh/runtime';
2
3
  import { YamlConfig } from '@graphql-mesh/types';
3
- import { Router } from '@whatwg-node/router';
4
- export type MeshHTTPHandler<TServerContext> = Router<TServerContext>;
4
+ export type MeshHTTPHandler<TServerContext> = Router<TServerContext, {}, {}>;
5
5
  export declare function createMeshHTTPHandler<TServerContext>({ baseDir, getBuiltMesh, rawServeConfig, playgroundTitle, }: {
6
6
  baseDir: string;
7
7
  getBuiltMesh: () => Promise<MeshInstance>;