Skip to content

Commit c12d51e

Browse files
committed
initial commit
1 parent 16ee8cb commit c12d51e

36 files changed

+8713
-15709
lines changed

.env

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Environment variables declared in this file are automatically made available to Prisma.
2+
# See the documentation for more detail: https://pris.ly/d/prisma-schema#using-environment-variables
3+
4+
# Prisma supports the native connection string format for PostgreSQL, MySQL and SQLite.
5+
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
6+
7+
DATABASE_URL="file:./dev.db"

.eslintignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.next/
22
node_modules/
33
charts/
4-
prisma/
4+
prisma/
5+
gen/
6+
next.config.js

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
# misc
77
.DS_Store
8-
.env
98
.env.local
10-
.env
119
.env.development.local
1210
.env.test.local
1311
.env.production.local

.prettierignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ charts/
44
prisma/migrations/
55
prisma/schema.prisma
66
CHANGELOG.md
7-
coverage/
7+
coverage/
8+
gen/

README.md

+152-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1-
# Next.js TypeScript Material UI quality checking project
1+
# Next.js TypeScript Material UI quality checking project <!-- omit in toc -->
22

33
Includes TypeScript, Material UI, ESLint, Jest, and React Testing Library
44

5-
- [Deploy your own](#deploy-your-own)
6-
- [How to use](#how-to-use)
5+
- [App startup](#app-startup)
6+
- [SQLite](#sqlite)
7+
- [Postgres](#postgres)
8+
- [Using Prisma](#using-prisma)
9+
- [Adding a table to your database](#adding-a-table-to-your-database)
10+
- [Creating migrations](#creating-migrations)
11+
- [Seeding sample data](#seeding-sample-data)
12+
- [Using prisma client to perform database actions](#using-prisma-client-to-perform-database-actions)
713
- [Scripts](#scripts)
14+
- [generate-types](#generate-types)
15+
- [watch-queries](#watch-queries)
16+
- [generate](#generate)
17+
- [migrate](#migrate)
18+
- [deploy](#deploy)
19+
- [reset](#reset)
20+
- [seed](#seed)
21+
- [studio](#studio)
22+
- [prisma](#prisma)
823
- [build](#build)
924
- [dev](#dev)
1025
- [format](#format)
@@ -15,28 +30,152 @@ Includes TypeScript, Material UI, ESLint, Jest, and React Testing Library
1530
- [quality](#quality)
1631
- [Accessibility ](#accessibility)
1732

18-
## Deploy your own
33+
## App startup
1934

20-
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
35+
Choose how to start your development server based on your database configuration below.
2136

22-
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/MileTwo/nextjs-typescript-material-ui-eslint-jest)
37+
### SQLite
2338

24-
## How to use
39+
First time starting your app make sure to run `prisma` then start your app.
2540

26-
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
41+
```
42+
npm run prisma && npm run dev
43+
```
44+
45+
### Postgres
46+
47+
Ensure you have a `.env` file with a `DATABASE_URL` variable following the [format required by prisma](https://www.prisma.io/docs/concepts/database-connectors/postgresql#connection-details) and using the credentials found in your `docker-compose.yml` file.
48+
49+
```
50+
DATABASE_URL=postgresql://[POSTGRES_USER]:[POSTGRES_PASSWORD]@[POSTGRES_HOST]:[PORT]?schema=public
51+
```
52+
53+
Start up your development server with the following command:
54+
55+
```
56+
docker-compose up
57+
```
58+
59+
Once your development server is up and running, in a new terminal run the following command:
60+
61+
```
62+
npm run prisma && npm run dev
63+
```
64+
65+
`npm run prisma` will do a few things for us:
66+
67+
- Format your `prisma/schema.prisma` file (`prisma format`) | [prisma format documentation](https://www.prisma.io/docs/reference/api-reference/command-reference#format)
68+
- Keeps your `prisma/schema.prisma` file in sync with your database by auto generating migrations when needed (`npm run migrate`) | [prisma migration documentation](https://www.prisma.io/docs/concepts/components/prisma-migrate)
69+
- Seed your database with (`npm run seed`) | [prisma seeding documentation](https://www.prisma.io/docs/guides/database/seed-database/)
70+
71+
## Using Prisma
72+
73+
> Prisma helps app developers build faster and make fewer errors with an open source ORM for PostgreSQL, MySQL and SQLite. | [Source](https://www.prisma.io/)
74+
75+
### Adding a table to your database
76+
77+
Adding a table is as easy as adding a model to your `schema.prisma` file, followed by [creating a migration](#Creating-migrations). For a tutorial on this visit the [prisma schema documentation](https://www.prisma.io/docs/concepts/components/prisma-schema).
78+
79+
### Creating migrations
80+
81+
Once you've made the [appropriate changes to your `schema.prisma`](#Adding-a-table-to-your-database) file you can auto generate a migration using
2782

2883
```bash
29-
npx create-next-app --example https://github.com/MileTwo/nextjs-typescript-material-ui-eslint-jest
30-
# or
31-
yarn create next-app --example https://github.com/MileTwo/nextjs-typescript-material-ui-eslint-jest
84+
npm run migrate
3285
```
3386

34-
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
87+
This will generate a new folder under `prisma/migrations` with a SQL file outlining the changes to be reflected to your database and also generate new TypeScript code for prisma client usage.
88+
89+
To learn more visit the [prisma migration documentation](https://www.prisma.io/docs/concepts/components/prisma-migrate) or the [prisma generate documentation](https://www.prisma.io/docs/reference/api-reference/command-reference#generate).
90+
91+
### Seeding sample data
92+
93+
To seed your database, using [prisma client](#Using-prisma-client-to-perform-database-actions), add in sample data in the `prisma/seed.ts` file.
94+
95+
To learn more visit the [prisma seeding documentation](https://www.prisma.io/docs/guides/database/seed-database/).
96+
97+
### Using prisma client to perform database actions
98+
99+
Using the prisma client you can do the various actions required to build applications utilizing a database.
100+
101+
To learn more visit [working with the prisma client](https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient).
35102

36103
## Scripts
37104

38105
All scripts can be run by prefixing with `npm run`, for example `npm run build`
39106

107+
### generate-types
108+
109+
Using [graphql code generator](https://www.graphql-code-generator.com/) this generates types based on the `codegen.yml` configuration. In the initial setup this will update files under the `gen/` directory.
110+
111+
```bash
112+
npm run generate-types
113+
```
114+
115+
### watch-queries
116+
117+
Using [graphql code generator](https://www.graphql-code-generator.com/) this command listens for changes based on the `documents` key in the `codegen.yml` file, and generates types.
118+
119+
```bash
120+
npm run watch-queries
121+
```
122+
123+
### generate
124+
125+
See the [prisma generate documentation](https://www.prisma.io/docs/reference/api-reference/command-reference#generate).
126+
127+
```bash
128+
npm run generate
129+
```
130+
131+
### migrate
132+
133+
See the [prisma migration documentation](https://www.prisma.io/docs/concepts/components/prisma-migrate).
134+
135+
```bash
136+
npm run migrate
137+
```
138+
139+
### deploy
140+
141+
> To apply pending migrations to development, staging, or testing environments, run the `migrate deploy` command as part of your CI/CD pipeline | [Source](https://www.prisma.io/docs/guides/deployment/deploy-database-changes-with-prisma-migrate).
142+
143+
```bash
144+
npm run deploy
145+
```
146+
147+
### reset
148+
149+
When you want to reset your database to a clean slate, this clears all migrations and re-runs the migration list, then seeds the database. For more visit [prisma migrate reset](https://www.prisma.io/docs/reference/api-reference/command-reference/#migrate-reset).
150+
151+
```bash
152+
npm run reset
153+
```
154+
155+
### seed
156+
157+
Runs the `prisma/seed.ts` script to seed your database. See the [prisma seeding documentation](https://www.prisma.io/docs/guides/database/seed-database/).
158+
159+
```bash
160+
npm run seed
161+
```
162+
163+
### studio
164+
165+
Allows you to interact with and manage your data interactively. For more visit [prisma studio](https://www.prisma.io/docs/reference/api-reference/command-reference/#studio).
166+
167+
```bash
168+
npm run studio
169+
```
170+
171+
### prisma
172+
173+
An aggregate command used to format your schema file, check for differences from schema to db, generate a prisma client, and seed your database.
174+
175+
```bash
176+
npm run prisma
177+
```
178+
40179
### build
41180

42181
Builds the production application in the .next folder.
@@ -49,7 +188,7 @@ npm run build
49188

50189
Starts the application in development mode with hot-code reloading, error reporting, and more:
51190

52-
The application will start at http://localhost:3000 by default. The default port can be changed with -p, like so:
191+
The application will start at http://localhost:3000 by default. The default port can be changed with `-p`, like so:
53192

54193
```bash
55194
npm run dev -p 4000

codegen.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## codegen.yml
2+
overwrite: true
3+
schema: 'http://localhost:3000/api/graphql'
4+
documents: '{components,pages}/**/*.{ts,tsx}'
5+
generates:
6+
types/gen/graphql-types.tsx:
7+
config:
8+
dedupeOperationSuffix: true
9+
withHooks: true
10+
withComponent: false
11+
withHOC: false
12+
plugins:
13+
- 'typescript'
14+
- 'typescript-operations'
15+
- 'typescript-react-apollo'

components/Image.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React, { ReactElement } from 'react';
22
import NextImage from 'next/image';
33
import { Avatar, createStyles, makeStyles, Theme } from '@material-ui/core';
4-
import { Image as ImageType } from '../pages';
4+
5+
import { Maybe } from '../types/gen/graphql-types';
56

67
interface Props {
7-
image: ImageType | undefined;
8+
image: Maybe<string> | undefined;
89
name: string;
910
}
1011

@@ -25,14 +26,14 @@ export default function Image({ image, name }: Props): ReactElement {
2526
return <Avatar className={classes.avatar}>{firstLetter}</Avatar>;
2627
}
2728

28-
if (image.src.startsWith('/')) {
29-
return <NextImage src={image.src || firstLetter} width={50} height={50} alt={name} data-testid="image" />;
29+
if (image.startsWith('/')) {
30+
return <NextImage src={image || firstLetter} width={50} height={50} alt={name} data-testid="image" />;
3031
}
3132

3233
return (
3334
<>
3435
{/* used for non optimizable entries (files not stored in public directory) */}
35-
<img data-testid="image" src={image.src || firstLetter} width={50} height={50} alt={name} />
36+
<img data-testid="image" src={image || firstLetter} width={50} height={50} alt={name} />
3637
</>
3738
);
3839
}

0 commit comments

Comments
 (0)