@graphql-mesh/http 1.0.0-alpha-20230524144709-24ad76be9 → 1.0.0-alpha-20230524151151-439b8293d

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.
Files changed (3) hide show
  1. package/cjs/index.js +25 -22
  2. package/esm/index.js +25 -22
  3. package/package.json +5 -5
package/cjs/index.js CHANGED
@@ -16,7 +16,7 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, pla
16
16
  return (0, server_1.createServerAdapter)((0, graphqlHandler_js_1.graphqlHandler)(() => mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig), {
17
17
  plugins: [
18
18
  {
19
- async onRequest({ request, url, endResponse }) {
19
+ onRequest({ request, url, endResponse }) {
20
20
  if (!mesh$) {
21
21
  mesh$ = getBuiltMesh().then(mesh => {
22
22
  readyFlag = true;
@@ -37,21 +37,22 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, pla
37
37
  return;
38
38
  }
39
39
  if (readyFlag) {
40
- const { pubsub } = await mesh$;
41
- for (const eventName of pubsub.getEventNames()) {
42
- if (eventName === `webhook:${request.method.toLowerCase()}:${url.pathname}`) {
43
- const body = await request.text();
44
- logger.debug(`Received webhook request for ${url.pathname}`, body);
45
- pubsub.publish(eventName, request.headers.get('content-type') === 'application/json'
46
- ? JSON.parse(body)
47
- : body);
48
- endResponse(new server_1.Response(null, {
49
- status: 204,
50
- statusText: 'OK',
51
- }));
52
- return;
40
+ return mesh$.then(async (mesh) => {
41
+ for (const eventName of mesh.pubsub.getEventNames()) {
42
+ if (eventName === `webhook:${request.method.toLowerCase()}:${url.pathname}`) {
43
+ const body = await request.text();
44
+ logger.debug(`Received webhook request for ${url.pathname}`, body);
45
+ mesh.pubsub.publish(eventName, request.headers.get('content-type') === 'application/json'
46
+ ? JSON.parse(body)
47
+ : body);
48
+ endResponse(new server_1.Response(null, {
49
+ status: 204,
50
+ statusText: 'OK',
51
+ }));
52
+ return;
53
+ }
53
54
  }
54
- }
55
+ });
55
56
  }
56
57
  if (staticFiles && request.method === 'GET') {
57
58
  let relativePath = url.pathname;
@@ -60,13 +61,15 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, pla
60
61
  }
61
62
  const absoluteStaticFilesPath = cross_helpers_1.path.join(baseDir, staticFiles);
62
63
  const absolutePath = cross_helpers_1.path.join(absoluteStaticFilesPath, relativePath);
63
- if (absolutePath.startsWith(absoluteStaticFilesPath) &&
64
- (await (0, utils_1.pathExists)(absolutePath))) {
65
- const readStream = cross_helpers_1.fs.createReadStream(absolutePath);
66
- endResponse(new server_1.Response(readStream, {
67
- status: 200,
68
- }));
69
- return;
64
+ if (absolutePath.startsWith(absoluteStaticFilesPath)) {
65
+ return (0, utils_1.pathExists)(absolutePath).then(exists => {
66
+ if (exists) {
67
+ const readStream = cross_helpers_1.fs.createReadStream(absolutePath);
68
+ endResponse(new server_1.Response(readStream, {
69
+ status: 200,
70
+ }));
71
+ }
72
+ });
70
73
  }
71
74
  }
72
75
  else if (graphqlPath !== '/' && url.pathname === '/') {
package/esm/index.js CHANGED
@@ -13,7 +13,7 @@ export function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig =
13
13
  return createServerAdapter(graphqlHandler(() => mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig), {
14
14
  plugins: [
15
15
  {
16
- async onRequest({ request, url, endResponse }) {
16
+ onRequest({ request, url, endResponse }) {
17
17
  if (!mesh$) {
18
18
  mesh$ = getBuiltMesh().then(mesh => {
19
19
  readyFlag = true;
@@ -34,21 +34,22 @@ export function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig =
34
34
  return;
35
35
  }
36
36
  if (readyFlag) {
37
- const { pubsub } = await mesh$;
38
- for (const eventName of pubsub.getEventNames()) {
39
- if (eventName === `webhook:${request.method.toLowerCase()}:${url.pathname}`) {
40
- const body = await request.text();
41
- logger.debug(`Received webhook request for ${url.pathname}`, body);
42
- pubsub.publish(eventName, request.headers.get('content-type') === 'application/json'
43
- ? JSON.parse(body)
44
- : body);
45
- endResponse(new Response(null, {
46
- status: 204,
47
- statusText: 'OK',
48
- }));
49
- return;
37
+ return mesh$.then(async (mesh) => {
38
+ for (const eventName of mesh.pubsub.getEventNames()) {
39
+ if (eventName === `webhook:${request.method.toLowerCase()}:${url.pathname}`) {
40
+ const body = await request.text();
41
+ logger.debug(`Received webhook request for ${url.pathname}`, body);
42
+ mesh.pubsub.publish(eventName, request.headers.get('content-type') === 'application/json'
43
+ ? JSON.parse(body)
44
+ : body);
45
+ endResponse(new Response(null, {
46
+ status: 204,
47
+ statusText: 'OK',
48
+ }));
49
+ return;
50
+ }
50
51
  }
51
- }
52
+ });
52
53
  }
53
54
  if (staticFiles && request.method === 'GET') {
54
55
  let relativePath = url.pathname;
@@ -57,13 +58,15 @@ export function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig =
57
58
  }
58
59
  const absoluteStaticFilesPath = path.join(baseDir, staticFiles);
59
60
  const absolutePath = path.join(absoluteStaticFilesPath, relativePath);
60
- if (absolutePath.startsWith(absoluteStaticFilesPath) &&
61
- (await pathExists(absolutePath))) {
62
- const readStream = fs.createReadStream(absolutePath);
63
- endResponse(new Response(readStream, {
64
- status: 200,
65
- }));
66
- return;
61
+ if (absolutePath.startsWith(absoluteStaticFilesPath)) {
62
+ return pathExists(absolutePath).then(exists => {
63
+ if (exists) {
64
+ const readStream = fs.createReadStream(absolutePath);
65
+ endResponse(new Response(readStream, {
66
+ status: 200,
67
+ }));
68
+ }
69
+ });
67
70
  }
68
71
  }
69
72
  else if (graphqlPath !== '/' && url.pathname === '/') {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@graphql-mesh/http",
3
- "version": "1.0.0-alpha-20230524144709-24ad76be9",
3
+ "version": "1.0.0-alpha-20230524151151-439b8293d",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@graphql-mesh/cross-helpers": "0.4.0-alpha-20230524144709-24ad76be9",
7
- "@graphql-mesh/runtime": "1.0.0-alpha-20230524144709-24ad76be9",
8
- "@graphql-mesh/types": "1.0.0-alpha-20230524144709-24ad76be9",
9
- "@graphql-mesh/utils": "1.0.0-alpha-20230524144709-24ad76be9",
6
+ "@graphql-mesh/cross-helpers": "0.4.0-alpha-20230524151151-439b8293d",
7
+ "@graphql-mesh/runtime": "1.0.0-alpha-20230524151151-439b8293d",
8
+ "@graphql-mesh/types": "1.0.0-alpha-20230524151151-439b8293d",
9
+ "@graphql-mesh/utils": "1.0.0-alpha-20230524151151-439b8293d",
10
10
  "graphql": "*",
11
11
  "tslib": "^2.4.0"
12
12
  },