-
Notifications
You must be signed in to change notification settings - Fork 2
Top Tips
Alex Toff edited this page Nov 1, 2022
·
3 revisions
- Ensure graphql file for query inside the appropriate
graphql/queries
folder. yarn codegen
In component:
<script setup lang="ts">
import { use<queryName>Query } from '@/graphql/codegen/operations`
const { result } = useHomepageUpcomingProductionsQuery(); // NB: result is a ref. Access the data using result.value.data
...
Example https://github.com/BristolSTA/uobtheatre-web/blob/feat/nuxt3/pages/index.vue#L127
Running queries on page load (blocking navigation / must be run before page load) / switching from asyncData()
- Ensure graphql file for query inside the appropriate
graphql/queries
folder. yarn codegen
In component:
// <script setup lang="ts">
import { <queryName>Document, <queryName>Query, <queryName>QueryVariables} from '@/graphql/codegen/operations`
const { data } = await useAsyncQuery<<queryName>Query>(
<queryName>Document,
{ foo: 'bar' } as <queryName>QueryVariables
);
...
Example https://github.com/BristolSTA/uobtheatre-web/blob/feat/nuxt3/pages/venue/%5Bslug%5D/index.vue#L92