Skip to content

NextJs Api Routes #1697

Answered by JoviDeCroock
lorenzo-moni asked this question in Q&A
Discussion options

You must be logged in to vote

Let's make a few distinctions here, when you are creating an api-route you mean you are creating a rest-api that uses urql to contact an external server so your front-end calls that lambda through REST and that lambda calls a graphql api? Why are you not calling the auth directly, a lambda is not part of SSR, so using next-urql in an api-route is not intended.

You can instead just call createClient and use everything from @urql/core, if however you are talking about calling a function that uses @urql/core you can pass in your client from the React-component through useClient. Another good option would be to use the authExchange.

Your api-route can look something like this:

import { create…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kitten
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants