Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/edge function #1772

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/magento-graphcms/.meshrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ sources:
Content-Currency: "{context.headers['content-currency']}"
serve:
playground: true
cache:
localforage:
driver:
- 'INMEMORY_LRU'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't do anything but I'm getting:

Error: No available storage method found.
    at (../../node_modules/localforage/dist/localforage.js:2762:0)

1 change: 1 addition & 0 deletions examples/magento-graphcms/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const nextConfig = {
},
experimental: {
scrollRestoration: true,
runtime: 'experimental-edge',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work at all, crashes because of a memory error, not sure yet.

},
optimizeFonts: false,
images: {
Expand Down
11 changes: 9 additions & 2 deletions examples/magento-graphcms/pages/api/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { createServer } from '@graphcommerce/graphql-mesh'
import { createBuiltMeshHTTPHandler } from '@graphcommerce/graphql-mesh'
import { NextRequest } from 'next/server'

export default await createServer('/api/graphql')
const handler = createBuiltMeshHTTPHandler()

export default async function handle(request: NextRequest) {
return handler.fetch(request.url, request)
}

export const config = { runtime: 'edge' }
4 changes: 1 addition & 3 deletions packages/graphql-mesh/customFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
const fetchRetry = require('fetch-retry')

/** @type {fetchRetry.default} */
const fetcher = fetchRetry(
process.env.__NEXT_PROCESSED_ENV ? fetch : require('@whatwg-node/fetch').fetch,
)
const fetcher = fetchRetry(require('@whatwg-node/fetch').fetch)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were running into some issue where @whatwg-node/fetch is way slower than regular fetch, but using that will cause this to fail because @whatwg-node/fetch is implementing things that aren't in the edge runtime or something (URLPattern I believe)


/**
* @param {RequestInfo | URL} url
Expand Down
28 changes: 28 additions & 0 deletions patches/@graphql-mesh+cross-helpers+0.3.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/node_modules/@graphql-mesh/cross-helpers/browser.js b/node_modules/@graphql-mesh/cross-helpers/browser.js
index 26234f7..f9c16c6 100644
--- a/node_modules/@graphql-mesh/cross-helpers/browser.js
+++ b/node_modules/@graphql-mesh/cross-helpers/browser.js
@@ -13,10 +13,10 @@ const processObj =
: {
platform: 'linux',
get env() {
- try {
- // eslint-disable-next-line no-new-func
- return new Function('return import.meta.env')();
- } catch {
+ // try {
+ // // eslint-disable-next-line no-new-func
+ // return new Function('return import.meta.env')();
+ // } catch {
return new Proxy(
{},
{
@@ -28,7 +28,7 @@ const processObj =
},
},
);
- }
+ // }
},
};

54 changes: 54 additions & 0 deletions patches/@graphql-mesh+http+0.3.21.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff --git a/node_modules/@graphql-mesh/http/esm/index.js b/node_modules/@graphql-mesh/http/esm/index.js
index 5e35727..0351572 100644
--- a/node_modules/@graphql-mesh/http/esm/index.js
+++ b/node_modules/@graphql-mesh/http/esm/index.js
@@ -1,4 +1,5 @@
-import { fs, path } from '@graphql-mesh/cross-helpers';
+// import { fs } from '@graphql-mesh/cross-helpers';
+// import path from 'path-browserify';
import { DefaultLogger, pathExists, withCookies } from '@graphql-mesh/utils';
import { createRouter, Response } from '@whatwg-node/router';
import { graphqlHandler } from './graphqlHandler.js';
@@ -44,24 +45,24 @@ export function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig =
}
return undefined;
});
- if (staticFiles) {
- router.get('/:relativePath+', async (request) => {
- let { relativePath } = request.params;
- if (!relativePath) {
- relativePath = 'index.html';
- }
- const absoluteStaticFilesPath = path.join(baseDir, staticFiles);
- const absolutePath = path.join(absoluteStaticFilesPath, relativePath);
- if (absolutePath.startsWith(absoluteStaticFilesPath) && (await pathExists(absolutePath))) {
- const readStream = fs.createReadStream(absolutePath);
- return new Response(readStream, {
- status: 200,
- });
- }
- return undefined;
- });
- }
- else if (graphqlPath !== '/') {
+ // if (staticFiles) {
+ // router.get('/:relativePath+', async (request) => {
+ // let { relativePath } = request.params;
+ // if (!relativePath) {
+ // relativePath = 'index.html';
+ // }
+ // const absoluteStaticFilesPath = path.join(baseDir, staticFiles);
+ // const absolutePath = path.join(absoluteStaticFilesPath, relativePath);
+ // if (absolutePath.startsWith(absoluteStaticFilesPath) && (await pathExists(absolutePath))) {
+ // const readStream = fs.createReadStream(absolutePath);
+ // return new Response(readStream, {
+ // status: 200,
+ // });
+ // }
+ // return undefined;
+ // });
+ // }
+ if (graphqlPath !== '/') {
router.get('/', () => new Response(null, {
status: 302,
headers: {
14 changes: 14 additions & 0 deletions patches/@graphql-mesh+plugin-http-details-extensions+0.1.16.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/node_modules/@graphql-mesh/plugin-http-details-extensions/esm/index.js b/node_modules/@graphql-mesh/plugin-http-details-extensions/esm/index.js
index a9c7b3e..b888d0e 100644
--- a/node_modules/@graphql-mesh/plugin-http-details-extensions/esm/index.js
+++ b/node_modules/@graphql-mesh/plugin-http-details-extensions/esm/index.js
@@ -9,8 +9,7 @@ export default function useIncludeHttpDetailsInExtensions(opts) {
let ifFn = () => true;
if (typeof opts.if === 'string') {
ifFn = ({ url, context, info, options, env }) => {
- // eslint-disable-next-line no-new-func
- return new Function('url', 'context', 'info', 'options', 'env', 'return ' + opts.if)(url, context, info, options, env);
+ return true;
};
}
const httpDetailsByContext = new WeakMap();
66 changes: 66 additions & 0 deletions patches/@graphql-mesh+utils+0.43.15.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
diff --git a/node_modules/@graphql-mesh/utils/esm/defaultImportFn.js b/node_modules/@graphql-mesh/utils/esm/defaultImportFn.js
index a58e0ab..b5ff289 100644
--- a/node_modules/@graphql-mesh/utils/esm/defaultImportFn.js
+++ b/node_modules/@graphql-mesh/utils/esm/defaultImportFn.js
@@ -1,32 +1,4 @@
-import { path as pathModule } from '@graphql-mesh/cross-helpers';
async function defaultImportFn(path) {
- let module = await import(/* @vite-ignore */ path)
- .catch(e => {
- if (e.code === 'ERR_REQUIRE_ESM') {
- // eslint-disable-next-line no-new-func
- return new Function(`return import(${JSON.stringify(path)})`)();
- }
- throw e;
- })
- .catch(e => {
- if (pathModule.isAbsolute(path) && !path.endsWith('.js') && !path.endsWith('.ts')) {
- return defaultImportFn(`${path}.ts`);
- }
- throw e;
- });
- if (module.default != null) {
- module = module.default;
- }
- if (typeof module === 'object' && module != null) {
- const prototypeOfObject = Object.getPrototypeOf(module);
- if (prototypeOfObject == null || prototypeOfObject === Object.prototype) {
- const normalizedVal = {};
- for (const key in module) {
- normalizedVal[key] = module[key];
- }
- return normalizedVal;
- }
- }
- return module;
+ return import(path);
}
export { defaultImportFn };
diff --git a/node_modules/@graphql-mesh/utils/esm/resolve-additional-resolvers.js b/node_modules/@graphql-mesh/utils/esm/resolve-additional-resolvers.js
index d28606f..9b5c7d5 100644
--- a/node_modules/@graphql-mesh/utils/esm/resolve-additional-resolvers.js
+++ b/node_modules/@graphql-mesh/utils/esm/resolve-additional-resolvers.js
@@ -132,10 +132,7 @@ export function resolveAdditionalResolversWithoutImport(additionalResolver, pubs
const topic = stringInterpolator.parse(additionalResolver.pubsubTopic, resolverData);
return pubsub.asyncIterator(topic);
}, (root, args, context, info) => {
- return additionalResolver.filterBy
- ? // eslint-disable-next-line no-new-func
- new Function(`return ${additionalResolver.filterBy}`)()
- : true;
+ return true;
}),
resolve: (payload) => {
if (baseOptions.valuesFromResults) {
@@ -250,10 +247,7 @@ export function resolveAdditionalResolvers(baseDir, additionalResolvers, importF
const topic = stringInterpolator.parse(additionalResolver.pubsubTopic, resolverData);
return pubsub.asyncIterator(topic);
}, (root, args, context, info) => {
- return additionalResolver.filterBy
- ? // eslint-disable-next-line no-new-func
- new Function(`return ${additionalResolver.filterBy}`)()
- : true;
+ return true;
}),
resolve: (payload) => {
if (baseOptions.valuesFromResults) {
48 changes: 48 additions & 0 deletions patches/@graphql-tools+executor-http+0.1.9.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
diff --git a/node_modules/@graphql-tools/executor-http/esm/handleMultipartMixedResponse.js b/node_modules/@graphql-tools/executor-http/esm/handleMultipartMixedResponse.js
index 5bb1730..daa63cf 100644
--- a/node_modules/@graphql-tools/executor-http/esm/handleMultipartMixedResponse.js
+++ b/node_modules/@graphql-tools/executor-http/esm/handleMultipartMixedResponse.js
@@ -1,4 +1,4 @@
-import { meros as merosIncomingMessage } from 'meros/node';
+// import { meros as merosIncomingMessage } from 'meros/node';
import { meros as merosReadableStream } from 'meros/browser';
import { mapAsyncIterator } from '@graphql-tools/utils';
import { dset } from 'dset/merge';
@@ -10,24 +10,24 @@ export async function handleMultipartMixedResponse(response, controller) {
const body = response.body;
const contentType = response.headers.get('content-type') || '';
let asyncIterator;
- if (isIncomingMessage(body)) {
- // Meros/node expects headers as an object map with the content-type prop
- body.headers = {
- 'content-type': contentType,
- };
- // And it expects `IncomingMessage` and `node-fetch` returns `body` as `Promise<PassThrough>`
- const result = await merosIncomingMessage(body);
- if ('next' in result) {
- asyncIterator = result;
- }
- }
- else {
+ // if (isIncomingMessage(body)) {
+ // // Meros/node expects headers as an object map with the content-type prop
+ // body.headers = {
+ // 'content-type': contentType,
+ // };
+ // // And it expects `IncomingMessage` and `node-fetch` returns `body` as `Promise<PassThrough>`
+ // const result = await merosIncomingMessage(body);
+ // if ('next' in result) {
+ // asyncIterator = result;
+ // }
+ // }
+ // else {
// Nothing is needed for regular `Response`.
const result = await merosReadableStream(response);
if ('next' in result) {
asyncIterator = result;
}
- }
+ // }
const executionResult = {};
function handleResult(result) {
if (result.path) {
21 changes: 21 additions & 0 deletions patches/@whatwg-node+router+0.3.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/node_modules/@whatwg-node/router/index.mjs b/node_modules/@whatwg-node/router/index.mjs
index c20387c..81eb796 100644
--- a/node_modules/@whatwg-node/router/index.mjs
+++ b/node_modules/@whatwg-node/router/index.mjs
@@ -2,6 +2,7 @@ import * as DefaultFetchAPI from '@whatwg-node/fetch';
export { Response, URLPattern } from '@whatwg-node/fetch';
import { createServerAdapter } from '@whatwg-node/server';
export { useCORS, useErrorHandling } from '@whatwg-node/server';
+import { URLPattern } from 'urlpattern-polyfill';

const HTTP_METHODS = [
'GET',
@@ -36,7 +37,7 @@ function createRouterBase({ fetchAPI: givenFetchAPI, base: basePath = '/', } = {
else {
fullPath = `${basePath}${path}`;
}
- const pattern = new fetchAPI.URLPattern({ pathname: fullPath });
+ const pattern = new URLPattern({ pathname: fullPath });
methodPatternMaps.set(pattern, handlers);
}
async function handleRequest(request, context) {
21 changes: 21 additions & 0 deletions patches/dataloader+2.2.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/node_modules/dataloader/index.js b/node_modules/dataloader/index.js
index c760330..90bac7f 100644
--- a/node_modules/dataloader/index.js
+++ b/node_modules/dataloader/index.js
@@ -229,15 +229,7 @@ function () {
// setImmediate or setTimeout) at a potential performance penalty.


-var enqueuePostPromiseJob = typeof process === 'object' && typeof process.nextTick === 'function' ? function (fn) {
- if (!resolvedPromise) {
- resolvedPromise = Promise.resolve();
- }
-
- resolvedPromise.then(function () {
- process.nextTick(fn);
- });
-} : typeof setImmediate === 'function' ? function (fn) {
+var enqueuePostPromiseJob = typeof setImmediate === 'function' ? function (fn) {
setImmediate(fn);
} : function (fn) {
setTimeout(fn);
13 changes: 13 additions & 0 deletions patches/lodash.get+4.4.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/lodash.get/index.js b/node_modules/lodash.get/index.js
index 0eaadec..689a021 100644
--- a/node_modules/lodash.get/index.js
+++ b/node_modules/lodash.get/index.js
@@ -46,7 +46,7 @@ var freeGlobal = typeof global == 'object' && global && global.Object === Object
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;

/** Used as a reference to the global object. */
-var root = freeGlobal || freeSelf || Function('return this')();
+var root = freeGlobal || freeSelf || globalThis;

/**
* Gets the value at `key` of `object`.
13 changes: 13 additions & 0 deletions patches/lodash.topath+4.5.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/lodash.topath/index.js b/node_modules/lodash.topath/index.js
index a6ea795..2e5f602 100644
--- a/node_modules/lodash.topath/index.js
+++ b/node_modules/lodash.topath/index.js
@@ -44,7 +44,7 @@ var freeGlobal = typeof global == 'object' && global && global.Object === Object
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;

/** Used as a reference to the global object. */
-var root = freeGlobal || freeSelf || Function('return this')();
+var root = freeGlobal || freeSelf || globalThis;

/**
* A specialized version of `_.map` for arrays without support for iteratee