Resolver Utilities

invalidateQuery

This allows you to invalidate a specific query.

Example

import {invalidateQuery} from "blitz"
import getProducts from "app/products/queries/getProducts"
const Page = function ({products}) {
return (
<div>
<button
onClick={() => {
invalidateQuery(getProducts)
}}
>
Invalidate
</button>
</div>
)
}
export default Page

API

const refetchedQueries = await invalidateQuery(resolver, inputArgs?)

Arguments

  • resolver: A Blitz query resolver or mutation resolver
    • Required
  • inputArgs
    • Optional
    • The arguments that will be passed to resolver
    • If you don't provide this, it will invalidate all resolver queries
    • If you do provide this, it will only invalidate queries for resolver with matching inputArgs

Returns

This function returns a promise that will resolve when all of the queries are done being refetched.

getQueryKey

This allows you to get the query key for a query

Example

import {getQueryKey} from "blitz"
import getProducts from "app/products/queries/getProducts"
const Page = function ({products}) {
return (
<div>
<button
onClick={async () => {
const queryKey = getQueryKey(getProducts)
queryCache.invalidateQueries(queryKey)
const queryKey = getQueryKey(getProducts, {where: {ordId: 1}})
queryCache.invalidateQueries(queryKey)
}}
>
Invalidate
</button>
</div>
)
}
export default Page

API

const queryKey = getQueryKey(resolver, inputArgs?)

Arguments

  • resolver: A Blitz query resolver or mutation resolver
    • Required
  • inputArgs
    • Optional
    • The arguments that will be passed to resolver
    • If you don't provide this, it will return the base query key for all resolver queries
    • If you do provide this, it will return the specific query key for the resolver and inputArgs combination

Returns

  • results
    • The exact results returned from the resolver
Idea for improving this page?Edit it on GitHub