I have a nextjs project that is using apollo graphql to fetch data from the backend. I am trying to render my page using server side rendering. But I am currently using graphql apollo react hooks to fetch my data from the backend, and the react hooks prevents me from calling my backend inside of the getServerSideProps.
How do I solve this issue?
import * as React from "react";
import { useExampleQuery } from "graphql/types";
export const getServerSideProps = async ({ params }) => {
// Here we should probably call graphql function that is now called inside Page
return { props: { hash: params.hash } };
};
const Page = ({ hash }) => {
/*
I am currently calling my graphql query here using apollo react hooks,
that are generated inside graphql/types using @graphql-codegen (typescript)
*/
const { data, loading } = useExampleQuery({
variables: {
hash: hash,
},
});
return loading ? <p>{loading}</p> : <p>{data.example.text}</p>;
};
export default Page;