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

Using relative url with next.js api routes #484

Closed
BjoernRave opened this issue Dec 10, 2019 · 8 comments
Closed

Using relative url with next.js api routes #484

BjoernRave opened this issue Dec 10, 2019 · 8 comments
Labels
needs more info ✋ A question or report that needs more info to be addressable

Comments

@BjoernRave
Copy link
Contributor

BjoernRave commented Dec 10, 2019

I am not a 100% sure if this restriction comes from urql, but it only allows absolute urls. When using next.js api routes it hinders me from an easier config, since I could theoretically just pass'/api/graphql' as url

@BjoernRave BjoernRave added the bug 🐛 Oh no! A bug or unintented behaviour. label Dec 10, 2019
@kitten kitten added the needs more info ✋ A question or report that needs more info to be addressable label Jan 9, 2020
@kitten
Copy link
Member

kitten commented Jan 20, 2020

Sorry for not replying to this for so long. I don't think this has anything to do with urql. Most likely you're trying to use an absolute URL on the server-side which won't work? Could that be?

If your API is on the same server as the app, it may be worth to create a small fetchExchange for the server-side that instead just uses your GraphQL schema directly.

@kitten kitten added question 🙋 and removed bug 🐛 Oh no! A bug or unintented behaviour. labels Jan 20, 2020
@kitten
Copy link
Member

kitten commented Feb 5, 2020

Closed due to inactivity. next-urql is maybe the better place to ask this at.

@kitten kitten closed this as completed Feb 5, 2020
@BjoernRave
Copy link
Contributor Author

BjoernRave commented Jun 8, 2020

I would like to ask this again. My problem is, that I am using next.js api routes for my graphql server, so my api routes are on the same domain. My application has a subdomain for every user and it would make things much easier if every subdomain would send requests to their "own" api routes, so that cookies get passed accordingly

@dsebastien
Copy link

I also wonder about this. Why can't we pass a relative URL to urql?

If your API is on the same server as the app, it may be worth to create a small fetchExchange for the server-side that instead just uses your GraphQL schema directly.

I'm curious about this. I get the idea, but is there an example somewhere? I'm not too sure about how to create/use a fetchExchange.

@kitten
Copy link
Member

kitten commented Feb 25, 2021

Typically this should work but I never looked into this because of the lack of reproductiveness without spinning up a full Next project for this. The url option is just passed to fetch so the same rules apply as for any other fetch call, ergo this shouldn't be an issue. What is probably an issue is if you make this call on the server-side which means that it'll fail

@dsebastien
Copy link

Alright, I'll try again tonight. Yesterday I couldn't wrap my head around what you meant with "a small fetchExchange". Tried a few things, but didn't get anywhere. Indeed the code must run on the server (initiated through Next's getServerSideProps), which is why I was trying to figure out how to require the schema and pass it directly to the urql client.

@JoviDeCroock
Copy link
Collaborator

Hey @dsebastien if you can make a small example in https://codesandbox.io/ I'm up to take a look

@dsebastien
Copy link

It's alright. I was just using it wrong ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info ✋ A question or report that needs more info to be addressable
Projects
None yet
Development

No branches or pull requests

4 participants