Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Examples) update Grafbase example #54705

Merged
merged 17 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 11 additions & 13 deletions examples/with-grafbase/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import Link from 'next/link'

import { graphql } from '../gql'
import { grafbase } from '../lib/grafbase'
import type { Metadata } from 'next'

export const revalidate = 0

export const metadata = {
export const metadata: Metadata = {
title: 'Grafbase + Next.js',
description: 'Grafbase + Next.js',
}

const GetAllPostsDocument = graphql(/* GraphQL */ `
Expand All @@ -25,25 +27,25 @@ const GetAllPostsDocument = graphql(/* GraphQL */ `
}
`)

const RootLayout = async ({ children }: { children: React.ReactNode }) => {
export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const { postCollection } = await grafbase.request(GetAllPostsDocument, {
first: 50,
})

return (
<html lang="en">
<head>
<title>Grafbase + Next.js 13</title>
</head>
<body>
<div className="flex">
<nav className="w-[350px] flex flex-col justify-between h-screen overflow-y-auto bg-gray-100">
<ul className="p-8 space-y-2">
<li className="mb-6">
<Link
href="/"
className="py-2 rounded-md shadow-sm block px-3 text-gray-600 hover:text-gray-800 transition bg-white"
>
className="py-2 rounded-md shadow-sm block px-3 text-gray-600 hover:text-gray-800 transition bg-white">
Home
</Link>
</li>
Expand All @@ -55,8 +57,7 @@ const RootLayout = async ({ children }: { children: React.ReactNode }) => {
<li key={edge.node.id}>
<Link
href={`/posts/${edge.node.slug}`}
className="py-2 rounded-md shadow-sm block px-3 text-gray-600 hover:text-gray-800 transition bg-white"
>
className="py-2 rounded-md shadow-sm block px-3 text-gray-600 hover:text-gray-800 transition bg-white">
{edge.node.title}
</Link>
</li>
Expand All @@ -65,8 +66,7 @@ const RootLayout = async ({ children }: { children: React.ReactNode }) => {
<li>
<Link
href="/posts/not-found"
className="py-2 rounded-md shadow-sm block px-3 text-gray-600 hover:text-gray-800 transition bg-white"
>
className="py-2 rounded-md shadow-sm block px-3 text-gray-600 hover:text-gray-800 transition bg-white">
Show 404 page
</Link>
</li>
Expand All @@ -82,5 +82,3 @@ const RootLayout = async ({ children }: { children: React.ReactNode }) => {
</html>
)
}

export default RootLayout
4 changes: 1 addition & 3 deletions examples/with-grafbase/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Page = async () => {
export default function Page() {
return (
<>
<h1>Next.js 13 + Grafbase</h1>
Expand All @@ -9,5 +9,3 @@ const Page = async () => {
</>
)
}

export default Page
4 changes: 1 addition & 3 deletions examples/with-grafbase/app/posts/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const GetPostBySlugDocument = graphql(/* GraphQL */ `
}
`)

const Page = async ({ params }: { params: { slug: string } }) => {
export default async function Page({ params }: { params: { slug: string } }) {
const { post } = await grafbase.request(GetPostBySlugDocument, {
slug: params.slug,
})
Expand All @@ -28,5 +28,3 @@ const Page = async ({ params }: { params: { slug: string } }) => {
</>
)
}

export default Page
3 changes: 0 additions & 3 deletions examples/with-grafbase/next.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
experimental: {
runtime: 'experimental-edge',
},
}

module.exports = nextConfig