hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.2k stars 2.77k forks source link

Support `HASURA_GRAPHQL_REDIRECT_GET_REQUESTS` environment variable #7732

Open bitjson opened 3 years ago

bitjson commented 3 years ago

Is your proposal related to a problem?

I'm serving a public API with Hasura which I would like to make easy for developers to start using. Right now, developers who are new to the API sometimes attempt to navigate to https://api.example.com/, where they see only:

{"path":"$","error":"resource does not exist","code":"not-found"}

Developers also occasionally send GET requests to /v1/graphql, where they see the same error. (Which can be particularly confusing – its plausible that they made a valid request but the server didn't find any results.)

Describe the solution you'd like

I'd like Hasura to send back a 302 redirect to a helpful URL from the HASURA_GRAPHQL_REDIRECT_GET_REQUESTS environment variable, e.g. https://docs.example.com or https://try.example.com (where I've set up graphql-playground preset to my API).

If Hasura is considering rendering some sort of standard, more descriptive error message on GET requests to /v1/graphql, it might instead be a good idea to have two environment variables, e.g. HASURA_GRAPHQL_REDIRECT_GET_ROOT (for redirecting traffic from /) and HASURA_GRAPHQL_REDIRECT_GET_ENDPOINT for redirecting GET traffic from /v1/graphql and other endpoints (/v1beta1/relay, etc.). A descriptive error message would be sufficient for GET requests to /v1/graphql, but I would still like to redirect users from the root https://api.example.com/ to my https://try.example.com/.

Describe alternatives you've considered

If I was running my own infrastructure, I could do this myself, but since I'm using Hasura Cloud, I can't even e.g. configure Kubernetes ingress rules or CDN rules. I'm stuck with the error messages unless I migrate off of Hasura Cloud.

If the feature is approved, would you be willing to submit a PR?

Certainly! (Though I'm very new to Haskell, so I'd appreciate hints about how best to implement it.)

bitjson commented 3 years ago

As an example, I ended up switching away from Hasura Cloud, so I was able to implement this outside of Hasura for https://demo.chaingraph.cash. (Automatically redirects to https://try.chaingraph.cash.)

LeulAria commented 6 months ago

any solution found here ?