-
-
Notifications
You must be signed in to change notification settings - Fork 678
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
Make it work on edge functions #1440
Comments
Have you tried bundling the app and configuring webpack/other bundler to use dummy mock instead of node.js packages? Something like this for browser: |
I try to see if this is possible with vercel@edge where you actually have no control of the bundler |
it looks like there's no similar way or, at the least, I wasn't able to find one |
I mean you should bundle your project by yourself (in order to mock node.js api) and then publish the bundle to vercel edge |
I see. Definitely harder but doable. Thanks |
I just finished building a Next.js project with with type-graphql 2.0.0-beta.2 and love it so much. Unfortunately when trying to run my graphql route in @MichalLytek Would making I suspect if Full error
|
@Enalmada as a temporary workaround I forked the project and created the package |
I tried several approach to this and trying to alias the node libraries is too hard to make it reasonable. It only works in very simple setup, but for example in mine I have a separated prisma project that uses type-grapqhl-prisma to generate code which introduce other problems. Also, Also, this would allow using this library with prisma accelerate that instead runs on edge runtime. |
Any progress on that? Would be awesome to run it with CF workers. |
@akhdefault I'm only going to work on it if this is the direction the maintainer of the library wants to pursuit. |
@ramiel
In ideal world we would have I think you should try to use some JS bundler to pack your source code with node_modules dependencies, just like we do for the browser: This way, as the code is not actually called, replacing the imports with empty modules won't cause any runtime issues. |
So, let me reply to each point
import {buildSchema} from 'type-graphql';
import {emitSchemaFile} from 'type-graphql-utils';
const schema = buildSchema();
emitSchemaFile({schema, filePath: 'schema.graphql'});
I know that building the project mocking node library looks a good solution, but in real world complex scenario is not. For example in my monorepo, with pnpm and tsup (esbuild) the resolution of packages lead to have the alias not working in deeped imported packages (where the imports are not aliased by design). In any case, I fully understand if this is something the project doesn't want to do. In that case, feel free to close this issue, or maybe try to understand how much of your userbase is interested in this. Well, do what you feel right, of course :D |
This is a workaround. After releasing that "fix" there will be new issues opened that TypeGraphQL does not see the definitions from other packages, etc. 😕 |
What do you mean? The definition is the only untouched part |
I mean the definitions - classes decorated with TypeGraphQL's decorators. Like someones publish Relay helpers for TypeGraphQL as an npm package - in some edge cases you might end in multiple version of |
Oh, I see what you mean. The current solution in type-graphql is a workaround to actually be sure there's only one instance of typegraphql in node_modules. For example it's the same with the Anyway, for the general discussion of this issue, I'd suggest to maybe close it. I understand this is not a direction this project wants to pursuit and there's nothing bad. I will try to come up with another package that follow yours. I also have to do the same for typegraphql-prisma. Maybe you can revisit this proposal or a similar one in the future. Thanks for all the attention! |
Supporting all runtimes is the direction I want to follow with this project. The issue with fs will be solved as soon as we switch to the monorepo and separate packages. Then the core could be run on any platform as it would be almost zero deps (only graphql-js). The issue with global might be not relevant in today times. |
This message makes me very happy. I'll also be very happy of helping if there's any need |
+1 for edge |
Is your feature request related to a problem? Please describe.
typegraphql
cannot work, at the moment, on edge function engines, like the one of cloudflare workers or vercel@edge. The only reason why it cannot work is because the "emit schema to file" feature relies onpath
andfs
libraries. No other part of the code is problematic. This is a little shame because a secondary feature is preventing it to work.Describe the solution you'd like
Since the only feature is
emitSchemaFile
we could isolate this functionality into a different package (e.g.typegraphql-schema-emit
or as submoduletypegraphql/schema-emit
) and have it as optional peer dependency, so that, when the user want to use the non programmatic way of emitting schema they need that dependency. As well, when they want to use the programmatic way, they need to referthat dependency directly.Describe alternatives you've considered
It's not easy to isolate some parts of a library. Maybe tree shaking can help but it's not easy.
The text was updated successfully, but these errors were encountered: