-
Notifications
You must be signed in to change notification settings - Fork 74
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
Test/edge function #1772
Changes from all commits
8695aff
2e0cc0c
18ad725
ef8c4f5
41b87a5
e522dad
2ebe8b1
1c2704b
18dfd72
8cb1579
0b8c84a
93d6569
97b5548
c8938cd
df4b936
e19a89d
6fd2884
aa59cff
0352017
3404065
2b100b0
2c8ddb8
a6737d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ const nextConfig = { | |
}, | ||
experimental: { | ||
scrollRestoration: true, | ||
runtime: 'experimental-edge', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: { | ||
|
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' } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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 = | ||
}, | ||
}, | ||
); | ||
- } | ||
+ // } | ||
}, | ||
}; | ||
|
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: { |
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(); |
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) { |
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) { |
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) { |
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); |
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`. |
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 |
There was a problem hiding this comment.
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: