How to query inside next.js middleware? #3577
Replies: 2 comments
-
I don't think a middleware is meant to use |
Beta Was this translation helpful? Give feedback.
-
Hello, good for this you can use the same makeClient function that passes to the ApolloNextAppProvider: `'use client' import { ApolloLink, RequestHandler, split } from '@apollo/client' import { import { createUploadLink } from 'apollo-upload-client' const URL_API_HTTP = const URL_API_WS = export function makeClient () { const errorLink = onError(({ graphQLErrors, networkError }) => {
}) const combinedLink = ApolloLink.from([ const splitLink = split( return new ApolloClient({ export function ApolloWrapper ({ children }: React.PropsWithChildren) { then in your middleware you can use it like this: middleware.ts ` export async function middleware (req: NextRequest) {
return NextResponse.next() export const config = { ` |
Beta Was this translation helpful? Give feedback.
-
I am using urql in next.js 14 with app router and I am trying to query backend in middleware and I am getting this error
What am I doing wrong?
Here is the code
middleware.ts
urql client
Beta Was this translation helpful? Give feedback.
All reactions