Skip to content

Using urql with Next.js 13.2 #3080

Answered by hgiasac
NgoranA asked this question in Q&A
Mar 19, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

The urql package is tightly coupled with React. The library initializes a React Context at startup that causes exceptions on the server side. You must create the client from the @urql/core package in the server component instead. Avoid importing urql in the file.

import {
  Client,
  createClient,
  dedupExchange,
  fetchExchange,
} from "@urql/core";

const client = createClient({
    URL: "https://example.com/v1/graphql",
    exchanges: [dedupExchange, fetchExchange],
});

const result = await client.query(GetUsersDocument).toPromise();

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@EfstathiadisD
Comment options

Answer selected by JoviDeCroock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants