I am attempting to extract data from a table by filtering based on the relationship with the Blitzjs framework. However, I am facing difficulties using queries as it seems to be the only option available. Every time I try to call the query in my component, an error pops up that I am unable to troubleshoot on my own.
// Query function
import { Ctx, NotFoundError } from "blitz"
import { resolver } from "@blitzjs/rpc"
import { z } from "zod"
import db from "db"
const GetProfile = z.object({
id: z.number().optional().refine(Boolean, "Required"),
})
export default resolver.pipe(
resolver.zod(GetProfile),
resolver.authorize(),
async ({ id }, ctx: Ctx) => {
// TODO: in multi-tenant app, you must add validation to ensure correct tenant
const profile = await db.annonceur.findFirst({
where: {
user: {
id: {
equals: Number(ctx.session.userId),
},
},
},
})
if (!profile) throw new NotFoundError()
return profile
}
)
Calling the query within my component
import { useMutation, useQuery } from "@blitzjs/rpc"
import getProfile from "src/profiles/queries/getProfile"
export default function SideBar({ children, active }: Props) {
const [profile] = useQuery(getProfile, { })
console.log(profile)
return (
...
)
}
Encountering the Error
[Rendering Suspense fallback...: DYNAMIC_SERVER_USAGE] {
digest: 'DYNAMIC_SERVER_USAGE'
}
- error {
name: 'Rendering Suspense fallback...',
source: 'server',
message: 'DYNAMIC_SERVER_USAGE',
digest: 'DYNAMIC_SERVER_USAGE'
}