Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

sendIntrospectionQuery gives ECONNREFUSED with localhost server #180

Open
NicholasLYang opened this issue Mar 7, 2019 · 8 comments
Open

Comments

@NicholasLYang
Copy link

This is a bit of a puzzler (and quite possibly not the fault of this library at all). I'm running my Rust/Juniper GraphQL server on localhost (port 4000) and attempting to run sendIntrospectionQuery.

A quick aside, the docs aren't really friendly to people who are using npm. Any idea what the equivalent npm command is? I'd be happy to open a PR to add it to the documentation. I'm running node node_modules/graphql_ppx/sendIntrospectionQuery if it matters.

Anyways, the script fails with an ECONNREFUSED and my server doesn't even appear to notice the request. However, when I proxy the server using ngrok, this request goes through. Any idea why this happens?

Thanks,
Nicholas

@Gregoirevda
Copy link
Contributor

Gregoirevda commented Mar 7, 2019

From npm@5.2, you can use npx
npx send-introspection-query http://my-api.example.com/api
otherwise, you need to expand your scripts in package.json

 scripts : {
     send-introspection-query: send-introspection-query http://my-api.example.com/api
 }

Can you provide details of the ECONNREFUSED?
Do you have cors enabled on your GraphQL server?

@NicholasLYang
Copy link
Author

Ah, okay. I get the following error, which doesn't appear to be that useful:

Could not send introspection query:  { Error: connect ECONNREFUSED 127.0.0.1:4000
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 4000 }

I do have CORS enabled on my server. Quite honestly I'm leaning towards something weird on my end, because I read the sendIntrospectionQuery code and it looks pretty straightforward.

@Gregoirevda
Copy link
Contributor

Can you call it from a client supporting GraphQL like Insomnia?
Strange it only works from ngrock, sure it running in the correct place? lsof -i tcp:4000

@NicholasLYang
Copy link
Author

Yeah, the server is running in the right place. I even did a kill -9 and restarted it to make sure it wasn't a hidden process that I didn't kill properly. My GraphiQL client works properly too. And actually, my front end app also works too now that I set up the schema via ngrok.

@idkjs
Copy link
Contributor

idkjs commented May 17, 2019

@NicholasLYang you ever figure this out?

I just switch and endpoint from https://eu1.prisma.sh/prisma-783922/graphql-crud/dev" which works to localhost:4000 and get:

Could not send introspection query:  { Error: connect ECONNREFUSED 127.0.0.1:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1088:14)
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 80 }

Any idea what is cause of this?

I tried with ngrok and got same result:

ngrok by @inconshreveable                                                            (Ctrl+C to quit)

Session Status                online
Account                       Enso (Plan: Free)
Version                       2.3.28
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://fce66f54.ngrok.io -> http://localhost:4000
Forwarding                    https://fce66f54.ngrok.io -> http://localhost:4000

Connections                   ttl     opn     rt1     rt5     p50     p90
                              0       0       0.00    0.00    0.00    0.00

If run npx fetch-graphql-schema http://localhost:4000 it works. Can I use that in place of yarn send-introspection-query?

@idkjs
Copy link
Contributor

idkjs commented May 17, 2019

Disregard my comments. Typo in url. Had http://localhost/4000 instead of http://localhost:4000

@Ejhfast
Copy link

Ejhfast commented Apr 17, 2020

@NicholasLYang this issue also drove me a bit crazy today. It seems that Rocket has some issues serving on localhost: https://stackoverflow.com/a/59668606

For me the following worked:
npx get-graphql-schema http://[::1]:4000/graphql -j

Whereas the query I would typically do does not work:
npx get-graphql-schema http://localhost:4000/graphql -j

This was really surprising and hard to debug. I imagine many people are combining a Rust/Rocket/Juniper backend and Reason/Apollo frontend, so perhaps it is worth calling out this issue somewhere in the documentation.

So that search engines can further index on the error state, the error I was initially getting was:
FetchError: request to http://localhost:4000/ failed, reason: connect ECONNREFUSED 127.0.0.1:4000

@renehauck
Copy link

For my future self and also all other help seekers: If you use the local route ip via ifconfig instead of localhost, it worked for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants