Code Monkey home page Code Monkey logo

next-conduit's Introduction

next-real-world

About

This codebase was created to demonstrate a fully fledged fullstack application built with Next.js, Apollo GraphQL stack and Prisma including CRUD operations, authentication, routing, pagination, and more.

Used Stacks

backend

  • Prisma ORM (v4.0 seems supports Node version 14 or later)
  • Apollo Server mounted on the API route of Next.js pages
  • Nexus as a code-first GraphQL schema generator

frontend

Features

  • Pagination: use Prisma cursor-based query as well as Apollo Client fetchMore approach to implement a infinity load-more feature on the feed list and comment list.
  • Form Validation: including a Yup schema check and React Hook Form for frontend form validation.

Folder Structure

  • pages All pages of a regular Next.js app.
  • pages/api/index.ts The API route, mounting a GraphQL server instance within a Prisma client.
  • components Contains all page components.
  • generated Codes generated by Nexus and GraphQL Code Generator.
  • lib/api Schema definitions of the GraphQL server.
  • lib/api/prisma.ts Prisma client configs here.
  • lib/cache/index.ts Cache config of Apollo client.
  • lib/schemas Schema definitions for the frontend.
  • lib/constants.ts App configs init.
  • prisma/schema.prisma Definitions of database.
  • config.js Build configs used in next.config.original.js.

Getting Started

First, install dependencies

yarn

And setup your owner MySQL server config in a .env file(see example in .env.example)

DATABASE_URL="mysql://root:pass@localhost/real_blog?useUnicode=true&characterEncoding=utf8&useSSL=false"

Then run a Prisma migration script on your database

yarn db:migrate

Next, generate a JWK key pairs for the JWT based authentication, this script just print out the key pairs in the console

yarn generate:jwk

You should put the new generated PRIVATE_JWK into the .env file and the PUBLIC_JWK to lib/constants.ts as below

PRIVATE_JWK={your_generated_private_jwk}
export const PUBLIC_JWK = {
  kty: 'RSA' as const,
  ...
};

Last, run the common Next.js script to start

yarn dev

Point http://localhost:3000 to the app's home page and http://localhost:3000/api would redirect to Apollo Studio to show all the GraphQL API(Only accessible in a development env)

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

next-conduit's People

Contributors

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