Skip to content

Instantly share code, notes, and snippets.

@danielwaltz
Last active September 22, 2023 21:15
Show Gist options
  • Save danielwaltz/cdee2705a28d43ff74c22f6d7fd41af2 to your computer and use it in GitHub Desktop.
Save danielwaltz/cdee2705a28d43ff74c22f6d7fd41af2 to your computer and use it in GitHub Desktop.
Vue Apollo useSuspenseQuery
<script setup lang="ts">
import { useSuspenseQuery } from './useSuspenseQuery';
const { result } = await useSuspenseQuery(...);
</script>
<template>
<pre>{{ result }}</pre>
</template>
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