ssrQuery
This ensures appropriate middleware is run before/after your query function
Example
import {ssrQuery, GetServerSideProps, Link, BlitzPage, PromiseReturnType} from "blitz"import getProducts from "app/products/queries/getProducts"type PageProps = {products: PromiseReturnType<typeof getProducts>}export const getServerSideProps: GetServerSideProps<PageProps> = async ({req, res}) => {const products = await ssrQuery(getProducts, {orderBy: {id: "desc"}}, {req, res})return {props: {products},}}const Page: BlitzPage<PageProps> = function ({products}) {return (<div><h1>Products</h1><div id="products">{products.map((product) => (<p key={product.id}><Link href="/products/[handle]" as={`/products/${product.handle}`}><a>{product.name}</a></Link></p>))}</div></div>)}export default Page
API
const queryFunctionResults = await ssrQuery(blitzQueryFunction, queryInputArguments, {req, res}))
Arguments
blitzQueryFunction:
A Blitz query function- Required
queryInputArguments
- Required
- The arguments that will be passed to
blitzQueryFunction
- Other
req
- Required
- The BlitzApiRequest object
res
- Required
- The BlitzApiResponse object
Returns
queryFunctionResults
- The exact results returned from the query function