Aller au contenu

QAQuestion builder

Le builder QAQuestion crée une entité Question, injecte son @type, valide les données de manière synchrone et rejette les propriétés inconnues.

// Astro — shown first when Astro is selected
import { QAQuestion } from '@unschema-graph/astro';
// Svelte 5
import { QAQuestion } from '@unschema-graph/svelte';
// Core / Node.js
import { QAQuestion } from '@unschema-graph/core';
import { QAQuestionSchema } from '@unschema-graph/core';

Le schéma Zod QAQuestionSchema est également exporté pour la composition et la validation avancées.

import {
QAQuestionSchema,
type SchemaInput,
type SchemaOutput,
} from '@unschema-graph/core';
type QAQuestionInput = SchemaInput<typeof QAQuestionSchema>;
type QAQuestionOutput = SchemaOutput<typeof QAQuestionSchema, 'Question'>;
Propriété Type d’entrée Obligatoire Valeur par défaut / contraintes
@id string Non —
name string Oui non-empty
text string Non —
author string | Person | Organization | EntityReference Non non-empty
datePublished string | number | Date Non non-empty
acceptedAnswer object Non —
suggestedAnswer object | Array Non —

Les alias ci-dessus restent la référence exacte, notamment pour les objets imbriqués. Le builder accepte aussi une configuration de validation en second argument et possède une sortie dont le @type vaut toujours Question.

import { QAQuestion } from '@unschema-graph/core';
const entity = QAQuestion({
"name": "How do I render JSON-LD in Astro?",
"text": "I need a server-rendered graph."
});
{
"@type": "Question",
"name": "How do I render JSON-LD in Astro?",
"text": "I need a server-rendered graph."
}
  • Passer une propriété inconnue au builder strict.
  • Utiliser une donnée source privée d’une propriété obligatoire.
  • Supposer qu’un Schema.org valide garantit un affichage dans la recherche.

Utilisez QAQuestion.safeParse(input) pour les données externes. Pour une extension Schema.org non encore modélisée, validez d’abord l’entité puis utilisez withAdditionalProperties(). N’ajoutez jamais une propriété inventée au builder.