- Composable content through powerful & flexible content modeling.
- Localization ready.
- SEO ready.
- Incremental Static Regeneration with Next.js1.
- Generation of GraphQL2 typed code (schema, and types), in sync with the content types through graphql-codegen3.
- Enhanced Developer Experience with TypeScript4.
To get started, read the following guidelines.
In order to authenticate the requests to the Contentful APIs, the following values are necessary:
- Your space ID: https://www.contentful.com/help/find-space-id/
- Contentful Delivery API token: https://www.contentful.com/developers/docs/references/content-delivery-api/
- Contentful Preview API token: https://www.contentful.com/developers/docs/references/content-preview-api/
Rename the .env.example
file to .env
and add the necessary values.
To install the necessary dependencies, run:
yarn
yarn dev
It should be up and running on http://localhost:3000
.
All necessary dependencies are installed under node_modules
and any necessary tools can be accessed via npm scripts.
This project makes use of Contentful's GraphQL API.
API calls made to the Contentful GraphQL endpoint are made through graphql-request
.
The types are generated from the .graphql
files located in the /lib/graphql/
directory:
lib/graphql/[fileName].graphql
is detected by the codegenlib/__generated/sdk.ts
is generated- Within the generated file, their types and a new
getSdk
function are generated - The
getSdk
function can now be imported and used within thegetStaticProps
in the pages files
We use graphql-codegen
to generate a type-safe API client, utilizing GraphQLClient as the "client".
In order to (re-)generate the GraphQL schema, types and sdk, please use either of the following commands:
yarn graphql-codegen:generate
generates a schema, types and code to fetch data from the Contentful APIsyarn graphql-codegen:watch
similar to thegenerate
command, but it runs as a watch task which will rerun the steps when changes are made in the.graphql
files
The first steps of the codegen generate files that contain the GraphQL schema and matching TypeScript types. All these files are located in the src/lib/graphql
folder.
They're generated to the src/lib/__generated
folder and ought to be committed once altered/added to the repository.
The TS types for these files are generated in the same location, in a __generated
folder and like the other files ought to be committed.
The configuration for the codegen can be found in codegen.ts
, located in the root of the project.
MIT License, see LICENSE.