Giter Club home page Giter Club logo

zamec's Introduction

Features

  • 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.

$~$

Getting started

To get started, read the following guidelines.

$~$

Environment variables

In order to authenticate the requests to the Contentful APIs, the following values are necessary:

Rename the .env.example file to .env and add the necessary values.

$~$

Dependencies

To install the necessary dependencies, run:

yarn

Run the Starter Template in development mode

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.

$~$

Contentful API & GraphQL

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:

  1. lib/graphql/[fileName].graphql is detected by the codegen
  2. lib/__generated/sdk.ts is generated
  3. Within the generated file, their types and a new getSdk function are generated
  4. The getSdk function can now be imported and used within the getStaticProps in the pages files

$~$

GraphQL & code generation

We use graphql-codegen to generate a type-safe API client, utilizing GraphQLClient as the "client".


Commands

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 APIs
  • yarn graphql-codegen:watch similar to the generate 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.


Configuration

The configuration for the codegen can be found in codegen.ts, located in the root of the project.

$~$


License

MIT License, see LICENSE.

$~$

Footnotes

  1. Next.js docs

  2. GraphQL docs

  3. graphql-codegen

  4. TypeScript

zamec's People

Contributors

sananmaarouf avatar

Stargazers

Andreas Theodore Skaara avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.