Skip to content

Commit

Permalink
chore: update ssr example with refs []
Browse files Browse the repository at this point in the history
  • Loading branch information
2wce committed Nov 21, 2024
1 parent ad3359c commit 58c3152
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
11 changes: 11 additions & 0 deletions examples/next-app-router-ssr/app/components/post-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export default function PostLayout({ post }: { post: Post }) {
>
{post.description}
</p>
{post.banner && (
<img
{...ContentfulLivePreview.getProps({
entryId: post.banner.sys.id,
fieldId: 'title',
locale: 'en-US',
})}
alt={post.banner.title}
src={post.banner.file.url}
/>
)}
</>
);
}
30 changes: 23 additions & 7 deletions examples/next-app-router-ssr/lib/api-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export interface Post {
slug: string;
title: string;
description: string;
banner: {
sys: Sys;
title: string;
file: {
url: string;
};
};
}

interface PostCollection {
Expand All @@ -21,13 +28,22 @@ interface FetchResponse {
}

const POST_GRAPHQL_FIELDS = `
__typename
sys {
id
}
slug
title
description
__typename
sys {
id
}
slug
title
description
banner {
sys {
id
}
title
file {
url
}
}
`;

async function fetchGraphQL(query: string, draftMode = false): Promise<FetchResponse> {
Expand Down

0 comments on commit 58c3152

Please sign in to comment.