Last active
September 22, 2023 21:15
-
-
Save danielwaltz/cdee2705a28d43ff74c22f6d7fd41af2 to your computer and use it in GitHub Desktop.
Vue Apollo useSuspenseQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup lang="ts"> | |
import { useSuspenseQuery } from './useSuspenseQuery'; | |
const { result } = await useSuspenseQuery(...); | |
</script> | |
<template> | |
<pre>{{ result }}</pre> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useLazyQuery } from '@vue/apollo-composable'; | |
export const useSuspenseQuery = async < | |
TResult = any, | |
TVariables extends Record<string, unknown> = any, | |
>( | |
...params: Parameters<typeof useLazyQuery<TResult, TVariables>> | |
): Promise<ReturnType<typeof useLazyQuery<TResult, TVariables>>> => { | |
const result = useLazyQuery(...params); | |
await result.load(); | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment