improve graphql error handling

This commit is contained in:
2024-08-14 22:13:49 +02:00
parent 137a8c0b2f
commit 27477de14e
11 changed files with 175 additions and 61 deletions
+15 -3
View File
@@ -1,4 +1,5 @@
import { Metadata, ResolvingMetadata } from "next";
import { notFound } from "next/navigation";
import { graphql } from "@/gql";
import { ContactIndexFragment } from "@/gql/graphql";
import { getClient } from "@/app/client";
@@ -36,19 +37,30 @@ export async function generateMetadata(
parent: ResolvingMetadata
): Promise<Metadata | null> {
const { data, error } = await getClient().query(contactQuery, {});
const index = (data?.index ?? []) as ContactIndexFragment;
if (!index) {
if (error) {
throw new Error(error.message);
}
if (!data?.index) {
return null;
}
const index = data.index as ContactIndexFragment;
const metadata = await getSeoMetadata(index, parent);
return metadata;
}
export default async function Page() {
const { data, error } = await getClient().query(contactQuery, {});
const index = (data?.index ?? []) as ContactIndexFragment;
if (error) {
throw new Error(error.message);
}
if (!data?.index) {
return notFound();
}
const index = data.index as ContactIndexFragment;
return (
<main className="site-main" id="main">