Previously, you created a GraphCommerce app and started building a custom header. You're now ready to build a Hygraph component.
Hygraph is the integrated Content Management System that is part of the magento-graphcms example.
In this tutorial, you'll accomplish a series of tasks to add some specific functionality to your app. The final result will be relatively simple, but you'll learn where to find resources to build more complex features on your own.
You've familiarized yourself with React ↗, Next.js ↗, and Mui ↗. GraphCommerce is a frontend React framework that uses Next.js for server-side rendering.
To be able to use the newly created model to add banners to pages, define the relationship between the Banner model and the Content field of the Page model.
yarn codegen
, this ensures the changes
you just made are added to your local environment.query {
pages(where: { url: "page/home" }) {
title
content {
__typename
}
}
}
Should output the following. Make note that 'Banner' is listed as a typename.
fragment Banner on Banner {
image {
...Asset
}
copy {
raw
}
}
BannerFragment
.fragment RowRenderer on Page @inject(into: ["HygraphPage"]) {
content {
__typename
... on Node {
id
}
...RowColumnOne
...RowColumnTwo
...RowColumnThree
...RowBlogContent
...RowHeroBanner
...RowSpecialBanner
...RowQuote
...RowButtonLinkList
...RowServiceOptions
...RowContentLinks
...RowProduct
...RowLinks
}
}
import { RichText } from '@graphcommerce/graphcms-ui'
import { BannerFragment } from './Banner.gql'
export function Banner(props: BannerFragment) {
const { copy, image } = props
return (
<div>
{image?.url}
<RichText
{...copy}
sxRenderer={{
paragraph: {
textAlign: 'center' as const,
},
'heading-one': (theme) => ({
color: theme.palette.primary.main,
}),
}}
/>
</div>
)
}
import { Banner } from './Banner'
const defaultRenderer: Partial<ContentTypeRenderer> = {
RowColumnOne,
RowColumnTwo,
RowColumnThree,
RowHeroBanner,
RowSpecialBanner,
RowQuote,
RowBlogContent,
RowButtonLinkList,
RowServiceOptions,
RowContentLinks,
RowProduct,
Banner,
}