<script setup lang="ts">
const { path: uri } = useRoute();
const { data } = await useGraphQLQuery("NodeByUri", { uri });

// Resolve and validate Node component
if (!data.value.nodeByUri) {
  throw createError({ statusCode: 404, message: `La page demandée est introuvable: ${uri}` });
}
const componentName = `Node${data.value.nodeByUri.__typename}`;
if (!useNuxtApp().vueApp.component(componentName)) {
  throw createError({ statusCode: 404, message: `La page demandée ne peut pas être affichée correctement: ${componentName}` });
}
</script>

<template>
  <div v-if="data.nodeByUri" id="page-node-from-uri">
    <Component :is="componentName" v-bind="data.nodeByUri" />
  </div>
</template>
