import { GET_BRAND_BY_SLUG } from '@graphql/queries/standalone/brands'; import type { IBrandsResponse } from '@types'; export async function useBrandBySlug(slug: string) { const brand = computed(() => data.value?.brands.edges[0]?.node ?? null); const { data, error } = await useAsyncQuery(GET_BRAND_BY_SLUG, { slug, }); if (!data.value?.brands?.edges?.length) { throw createError({ status: 404, statusText: 'Brand not found', fatal: true }); } watch(error, (err) => { if (err) { console.error('useBrandsBySlug error:', err); } }); return { brand, seoMeta: computed(() => brand.value?.seoMeta), }; }