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

[Bug?]: Calling serverless function does not work when server started with yarn rw serve #9355

Closed
1 task
standuprey opened this issue Oct 27, 2023 · 5 comments
Labels
bug/needs-info More information is needed for reproduction

Comments

@standuprey
Copy link
Contributor

What's not working?

I have a serverless function called from graphql to do some async work.
This works fine when the server is started with yarn rw dev or in production.
But when I start the server with yarn rw serve I get connect ECONNREFUSED ::1:8911

How do we reproduce the bug?

Here is a repo to reproduce the bug:

GitHub

If you start this with yarn rw dev there is a button on the homepage that works, but it doesn’t work if you start the app with rw build && rw serve

Ticket created from this discussion: https://community.redwoodjs.com/t/error-calling-a-function-from-graphql-when-started-with-rw-serve/5476

What's your environment? (If it applies)

System:
    OS: macOS 14.0
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - /private/var/folders/g7/0v2mwcd50dv822c6142lth1h0000gp/T/xfs-054dda13/node
    Yarn: 3.6.0 - /private/var/folders/g7/0v2mwcd50dv822c6142lth1h0000gp/T/xfs-054dda13/yarn
  Databases:
    SQLite: 3.39.5 - /usr/bin/sqlite3
  Browsers:
    Chrome: 118.0.5993.117
    Safari: 17.0
  npmPackages:
    @redwoodjs/cli-storybook: 6.3.2 => 6.3.2
    @redwoodjs/core: 6.3.2 => 6.3.2

Are you interested in working on this?

  • I'm interested in working on this
@standuprey standuprey added the bug/needs-info More information is needed for reproduction label Oct 27, 2023
@jtoar
Copy link
Contributor

jtoar commented Oct 27, 2023

Thanks for reporting and including a reproduction @standuprey! Funny I brought up edge cases like this just earlier this week. There's some differences between dev and serve:

I was going to make serve act the same as dev—just start two processes. But stepping back a bit, it looks like you want to call one of your api functions (here "myfunc") from graphql right? Or was there more to it than that?

@standuprey
Copy link
Contributor Author

yes, that’s it basically, calling a function from another function.

i had try to make executeAsync point to localhost:8910/.redwood/functions instead of localhost:8911 but I get the same error. see https://github.com/standuprey/redwood-async-func-call/pull/1/files

@dac09
Copy link
Collaborator

dac09 commented Nov 7, 2023

Hey @standuprey - I recently had to deal with a similar problem on ssr-streaming. I haven't reviewed your usecase though, so no thoughts on why you are trying to hit a function endpoint.

When you run on rw serve - the server doesn't listen on anything other than 127.0.0.1, so if you put in localhost you'll receive the error you're reporting. You could have a env var for this, and have a utility function that would just replace localhost for you:

function swapLocalhostFor127(hostString: string) {
  return hostString.replace('localhost', '127.0.0.1')
}

I hope this is helpful, and not actually making things worse 🤣, that's what I currently have in the experimental ssr setup!

@dthyresson
Copy link
Contributor

dthyresson commented Nov 7, 2023

I have a serverless function called from graphql to do some async work.

I still don't 100% understand why a function is called by the a graphql service resolver.

If the feature needs to be shared, the logic can be put in something shared like a lib.

The graphql resolver/service is async, so, I can't see which the async part need to be a function.

Is it that you want to "execute and forget" meaning trigger the async part but return right away?

If so, I think the new defer directive in realtime is what you may want.

See: #9235

and https://the-guild.dev/graphql/yoga-server/v4/features/defer-stream#using-defer

If these needs to be deployed on serverless like Vercel or Netlify, let me know -- I think defer should be possible.

@dac09
Copy link
Collaborator

dac09 commented Nov 29, 2023

Hey @standuprey! Just in triage mode at the moment - there's a few suggestions on this thread that are worth trying!

For now I'll close it the issue, but if you feel like you need more of a solution from the framework side feel free to comment and re-open.

@dac09 dac09 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/needs-info More information is needed for reproduction
Projects
None yet
Development

No branches or pull requests

4 participants