Configuration object.
React component that receives { data?: T; loading: boolean } plus any extra props.
Async function that returns the data to pass to the component. Runs on the server.
Async function that returns the data to pass to the component. Runs on the server.
React component that receives { data?: T; loading: boolean } plus any extra props.
Optional. Any additional props to pass to Component. Required if the Component has props other than data and loading.
A React element that suspends until fetch() completes, then renders Component with the data.
import { Injector } from "naystack/graphql/server";
import getCurrentUser from "@/app/api/(graphql)/User/resolvers/get-current-user";
import AuthChecker from "./components/auth-checker";
export default async function Layout({ children }: { children: React.ReactNode }) {
return (
<div>
{children}
<Injector fetch={getCurrentUser.authCall} Component={AuthChecker} />
</div>
);
}
import { Injector } from "naystack/graphql/server";
import getCurrentUser from "@/app/api/(graphql)/User/resolvers/get-current-user";
import getChats from "@/app/api/(graphql)/Chat/resolvers/get-chats";
import { ChatWindow } from "./components/chat-window";
export default async function ChatPage() {
return (
<Injector
fetch={async () => ({
user: await getCurrentUser.authCall(),
chats: await getChats.authCall(),
})}
Component={ChatWindow}
/>
);
}
Server component that wraps a client component with server-fetched data using Suspense.
While the
fetchfunction is resolving, theComponentis rendered withloading={true}(and nodata). Once the fetch resolves, theComponentre-renders withloading={false}anddataset to the result.This is the primary way to inject server-side data into client components in naystack. Use
.authCall()or.call()from your query definitions inside thefetchfunction.