Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App router #62

Merged
merged 99 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
ca0c102
Update SST+Prisma
revmischa Mar 12, 2023
b321a0a
upgrade to prisma 4.13.0 and sst latest
revmischa Apr 27, 2023
d5d54d2
WIP
revmischa Apr 27, 2023
9241906
Update prisma etc
revmischa Jun 29, 2024
3223b49
WIP
revmischa Jun 29, 2024
6962d0c
WIP
revmischa Jun 29, 2024
00f6cb2
Init
rkyslyy Jul 1, 2024
b72a91a
Clear web
rkyslyy Jul 1, 2024
dc2d1b7
App Router web
rkyslyy Jul 1, 2024
3ab2a51
next-auth
rkyslyy Jul 1, 2024
32f144f
WIP
rkyslyy Jul 1, 2024
af7990f
Config
rkyslyy Jul 1, 2024
e492aed
WIP
rkyslyy Jul 1, 2024
48406f4
WIP
rkyslyy Jul 1, 2024
47762ef
WIP
rkyslyy Jul 1, 2024
4998c0f
WIP
rkyslyy Jul 1, 2024
9cdce61
Logged in
rkyslyy Jul 1, 2024
0cb3277
WIP
rkyslyy Jul 1, 2024
435b055
WIP
rkyslyy Jul 1, 2024
418d423
WIP
rkyslyy Jul 1, 2024
537fc38
WIP
rkyslyy Jul 1, 2024
ab4ccbe
Jwt
rkyslyy Jul 1, 2024
df0fbe8
Buttons
rkyslyy Jul 1, 2024
f80d55a
Clean up
rkyslyy Jul 1, 2024
fe46063
Clean up
rkyslyy Jul 1, 2024
2c496df
Clean up
rkyslyy Jul 1, 2024
a78fecc
Sentry
rkyslyy Jul 1, 2024
6299996
Vite
rkyslyy Jul 1, 2024
8d72ae7
WIP
rkyslyy Jul 1, 2024
63250ad
WIP
rkyslyy Jul 1, 2024
273090b
Splash
rkyslyy Jul 1, 2024
770fa17
Splash
rkyslyy Jul 1, 2024
ad5dc0d
Header
rkyslyy Jul 1, 2024
201797c
cdk.context.json should not be part of the template
revmischa Jul 1, 2024
4f088b1
fix graphql codegen
revmischa Jul 1, 2024
9421f23
Clean up
rkyslyy Jul 1, 2024
843297d
Clean up
rkyslyy Jul 1, 2024
f828c39
Clean up
rkyslyy Jul 1, 2024
ffc36c6
Clean up
rkyslyy Jul 1, 2024
fd79dad
Clean up
rkyslyy Jul 1, 2024
7e83aef
bundler, gql
revmischa Jul 2, 2024
f02d581
GHA
revmischa Jul 2, 2024
b425540
sst types
revmischa Jul 2, 2024
df443fe
More infra fixes, like secrets
revmischa Jul 2, 2024
19fc780
Merge remote-tracking branch 'origin/master' into app-router
revmischa Jul 2, 2024
fb02a0f
some auth cleanup
revmischa Jul 2, 2024
54d47fd
secrets
revmischa Jul 2, 2024
7691b8e
gql cleanup
revmischa Jul 2, 2024
6e8a4c7
assorted fixes
revmischa Jul 2, 2024
5b940c1
root build step
revmischa Jul 2, 2024
0e04062
CI DB connection string
revmischa Jul 2, 2024
4a24b6c
fix local DB
revmischa Jul 2, 2024
391a429
sst:types
revmischa Jul 2, 2024
f58d261
no semi
revmischa Jul 2, 2024
3fad399
types
revmischa Jul 2, 2024
fc90b27
bleh
revmischa Jul 2, 2024
22535e8
builds
revmischa Jul 2, 2024
4ea64de
DSN
revmischa Jul 2, 2024
1332f7c
eslint
revmischa Jul 2, 2024
b5c13a2
DB
revmischa Jul 2, 2024
13c9765
base lint passing
revmischa Jul 2, 2024
fcd4b6c
web lint?
revmischa Jul 2, 2024
0b3bda5
WIP
revmischa Jul 2, 2024
35372b8
vitest
revmischa Jul 2, 2024
30c1791
run
revmischa Jul 2, 2024
b2e25bd
tsc
revmischa Jul 2, 2024
6616267
bleh
revmischa Jul 2, 2024
274af59
bleh
revmischa Jul 2, 2024
fcf29ff
gql sample
revmischa Jul 2, 2024
283024d
prisma
revmischa Jul 2, 2024
00528c9
seed
revmischa Jul 2, 2024
f883939
webtest
revmischa Jul 2, 2024
45d2a49
webtest
revmischa Jul 2, 2024
27bd0f8
DB improvements
revmischa Jul 2, 2024
3d79ea2
Clean up
rkyslyy Jul 2, 2024
af856bd
Refactor auth
rkyslyy Jul 2, 2024
1f26f2f
Clean up
rkyslyy Jul 2, 2024
04da47a
Refactor
rkyslyy Jul 2, 2024
124deb4
Move things
rkyslyy Jul 2, 2024
994330e
Refactor
rkyslyy Jul 2, 2024
b8d8abb
Refactor
rkyslyy Jul 2, 2024
c041945
Fix match
rkyslyy Jul 2, 2024
af136ea
Refactor
rkyslyy Jul 2, 2024
214ef90
fix next.config
revmischa Jul 2, 2024
f1e0b79
fix open-next stuff
revmischa Jul 2, 2024
8d272ca
auth and cognito fixes
revmischa Jul 2, 2024
9a1c87f
DB secret name/desc
revmischa Jul 2, 2024
e4e1fd4
clean up stack config
revmischa Jul 2, 2024
d64e95c
clean up stack config
revmischa Jul 2, 2024
6e3b0ce
Refresh
rkyslyy Jul 2, 2024
a3171c4
resource cleanup
revmischa Jul 2, 2024
5949d06
husky
revmischa Jul 2, 2024
aa83b26
lint-staged
revmischa Jul 2, 2024
8d786c3
readme
revmischa Jul 2, 2024
df32cc0
secret naming
revmischa Jul 2, 2024
05cee3d
no DB secret names
revmischa Jul 2, 2024
8e3b6f0
domain
revmischa Jul 2, 2024
423edc7
WIP
revmischa Jul 2, 2024
6c95c50
outputs
revmischa Jul 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .env
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
PRISMA_CONNECTION_LIMIT=5
PRISMA_CONNECTION_LIMIT=15
CREATE_AURORA_DATABASE=true

# for local dev environments which use docker-compose, you can disable running migrations in AWS by setting this to false
# if you want to automatically run DB migrations on deployed environments
# (does not apply to local dev)
RUN_DB_MIGRATIONS=true

# set this for non-local-dev stages to your web URL
# WEB_DOMAIN=
# e.g. WEB_DOMAIN=d3s9sdc942lbai.cloudfront.net

# set this to enable a bastion EC2 host you can tunnel through to connect to the database
# create a keypair in your desired account and region and add the name here
# SSH_KEYPAIR_NAME=

# set this for non-local-dev stages to your web URL
# WEB_URL=
4 changes: 3 additions & 1 deletion .env.prod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
IS_PRODUCTION=true

# WEB_URL=https://mysite.com
# assumes you have a hosted zone set up in Route53
# HOSTED_ZONE=mysite.com
# WEB_DOMAIN=mysite.com
63 changes: 0 additions & 63 deletions .eslintrc.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
# generate types from infra
# needed for typechecks
- name: SST types
run: pnpm sst:types --stage test
run: pnpm run sst:types --stage test
- name: Type checks
run: pnpm build
- name: Lint
Expand All @@ -36,7 +36,7 @@ jobs:
test-backend:
name: Test backend
env:
DATABASE_URL: "postgresql://postgres:pass@localhost:5438/myapp?connection_limit=80"
DATABASE_URL: "postgresql://prisma:prisma@localhost:5432/tests?connection_limit=80"

services:
postgres:
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
- name: Install dependencies
run: pnpm install
- name: Type checks
run: pnpm -C web tsc
run: pnpm run -C web tsc
- uses: actions/cache@v4
name: Enable NextJS cache
# https://nextjs.org/docs/messages/no-cache#github-actions
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/generate-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Generate release for tag

on:
push:
tags:
- "*"

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: ncipollo/release-action@v1
with:
generateReleaseNotes: true
33 changes: 33 additions & 0 deletions .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build on push

on:
push:
branches:
- "**"

# don't run if a tag was pushed
tags-ignore:
- "v*"

# don't run if only package.json (version) was updated
paths-ignore:
- "package.json"

# This will cancel the workflow https://stackoverflow.com/questions/66335225/how-to-cancel-previous-runs-in-the-pr-when-you-push-new-commitsupdate-the-curre
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-and-test:
uses: ./.github/workflows/build-and-test.yml

# enable if PAT is provided
# update-version:
# # if on production branch, bump version
# if: github.ref == 'refs/heads/prod'
# needs: build-and-test
# uses: ./.github/workflows/update-version.yml
# secrets:
# # personal token is required to trigger other workflows
# RELEASE_PAT: ${{ secrets.RELEASE_PAT }}
38 changes: 38 additions & 0 deletions .github/workflows/update-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Bump version and tag

name: Update version and tag

on:
workflow_call:
secrets:
RELEASE_PAT:
# personal token is required to trigger other workflows
required: true
workflow_dispatch:

jobs:
update-version:
name: Update version and tag
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.RELEASE_PAT }}
- uses: pnpm/action-setup@v3
with:
version: 9
- name: Generate new version
run: |
git config --local user.email "[email protected]"
git config --local user.name "github-bot"
pnpm version patch
- name: Push new version
run: git push
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}
- name: Push new tag
run: git push --tags
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

!jest.config.js

# TSC build output
/dist

*.tsbuildinfo
4 changes: 2 additions & 2 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tabWidth: 2
semi: true
semi: false
printWidth: 120
trailingComma: es5
trailingComma: all
singleQuote: true
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ Assumes you have [Node 20](https://nodejs.org/en/download/current/) installed an

### Setup

Edit `sst.config.ts` and set your default AWS profile and region.

```shell
npm i -g pnpm # install pnpm globally
pnpm i # install dependencies + generate types from DB and GQL schemas
pnpm db:migrate # run DB migrations
pnpm dev # start local dev server
```

Expand All @@ -28,7 +31,6 @@ Set your default AWS profile and region in `sst.config.ts`.

Edit .env or .env.$stage to set infrastructure vars.


## Features

All features are optional, delete what you don't need.
Expand All @@ -37,19 +39,19 @@ Click links to learn more and view documentation.

- 🌩 [Serverless Stack](https://serverless-stack.com/) - powerful CDK developer experience tools
- 🌤 [AWS CDK](https://aws.amazon.com/cdk/) - cloud-native infrastructure as code
- ፨ [GraphQL API](https://docs.serverless-stack.com/constructs/GraphQLApi)
- ፨ [GraphQL API](https://docs.serverless-stack.com/constructs/GraphQLApi) (optional)
- ⇅ [AWS AppSync](https://docs.aws.amazon.com/appsync/latest/devguide/what-is-appsync.html) - serverless GraphQL AWS service
- ✽ [Code generation](https://www.graphql-code-generator.com/) of [TypeScript](https://www.graphql-code-generator.com/docs/guides/front-end-typescript-only) + [react client](https://the-guild.dev/graphql/codegen/docs/guides/react-vue)
- 🌐 [REST API gateway](https://docs.serverless-stack.com/api)
- 🖥 [NextJS](https://nextjs.org/) frontend w/ Material-UI
- 🎨 [Material-UI](https://mui.com/material-ui/getting-started/overview/) - react components and styling solution
- 🖥 [NextJS](https://nextjs.org/) nextjs app router
- 🎨 [Tailwind](https://tailwindcss.com/) - for styling
- 🔓 [NextAuth.js](https://next-auth.js.org/) - authentication and session management
- 🔓 [AWS Cognito](https://aws.amazon.com/cognito/) - authentication backend
- 💾 [Prisma ORM](https://www.prisma.io/docs/)
- 📚 Prisma engine lambda layer
- 📜 Prisma DB migration CDK script
- 🐳 Database integration test setup with postgres in docker
- 🔋 [Aurora Serverless RDS](https://aws.amazon.com/rds/aurora/serverless/) PostgreSQL
- 🔋 [Aurora Serverless v2 RDS](https://aws.amazon.com/rds/aurora/serverless/) PostgreSQL
- ⚡️ [Live local lambda development](https://docs.serverless-stack.com/live-lambda-development) (`pnpm dev`)
- 🐞 [Lambda debugging](https://docs.sst.dev/live-lambda-development#debugging-with-visual-studio-code) - set breakpoints on your lambda functions and step through in your IDE
- 📦 [pnpm](https://pnpm.io/) - fast and correct package manager
Expand Down
10 changes: 5 additions & 5 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"migrate": "pnpm run migrate:dev",
"migrate:dev": "pnpm run format && prisma migrate dev",
"migrate:test": "pnpm init:db:test && dotenv -e .env.vitest -- prisma migrate dev --skip-seed --skip-generate",
"init:db:test": "[ -n \"$CI\" ] || (docker-compose exec -T sst-local-db dropdb -U postgres --if-exists tests && docker-compose exec -T sst-local-db createdb -U postgres tests)",
"db:seed": "prisma db seed",
"db:seed:clean": "CLEAN_SEED=true prisma db seed",
"init:db:test": "[ -n \"$CI\" ] || (docker-compose exec -T database dropdb -U postgres --if-exists tests && docker-compose exec -T database createdb -U postgres tests)",
"seed": "prisma db seed",
"seed:clean": "CLEAN_SEED=true prisma db seed",
"generate": "prisma generate"
},
"prisma": {
Expand All @@ -26,7 +26,7 @@
"@aws-sdk/client-kms": "~3.145.0",
"@aws-sdk/client-secrets-manager": "~3.145.0",
"@aws-sdk/signature-v4-crt": "^3.130.0",
"@middy/core": "^2.5.7",
"@middy/core": "^5.4.2",
"@prisma/client": "5.16.1",
"@prisma/internals": "5.16.1",
"@prisma/migrate": "5.16.1",
Expand All @@ -38,7 +38,7 @@
"memoizee": "^0.4.15"
},
"devDependencies": {
"@chax-at/transactional-prisma-testing": "^0.5.0",
"@chax-at/transactional-prisma-testing": "^1.2.0",
"@faker-js/faker": "^7.5.0",
"@types/aws-lambda": "^8.10.70",
"@types/memoizee": "^0.4.7",
Expand Down
2 changes: 1 addition & 1 deletion backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

generator client {
provider = "prisma-client-js"
previewFeatures = []
previewFeatures = ["postgresqlExtensions"]
binaryTargets = ["native"]
}

Expand Down
3 changes: 1 addition & 2 deletions backend/seed-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ set -euxo pipefail
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$SCRIPT_DIR/.."

pnpm exec sst load-config -- \
pnpm tsx backend/src/db/seed/seedScript.ts
pnpm tsx backend/src/db/seed/seedScript.ts
24 changes: 10 additions & 14 deletions backend/src/api/resolver/greeting.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import { testCallResolver } from '../../util/testResolver';
import { GREETING } from './greeting';

const { getGreeting, greetInner } = await import('./greeting');
import { testCallResolver } from '../../util/testResolver'
import { getGreeting, GREETING, greetInner } from './greeting'

describe('Greeting resolvers', () => {
it('gets current greeting', async () => {
const greeting = await testCallResolver({
args: {},
resolverFunc: getGreeting,
});
expect(greeting.currentGreeting).toBe(GREETING);
});
const greeting = getGreeting()
expect(greeting.currentGreeting).toBe(GREETING)
})

it('greets user by name', async () => {
const greeting = await testCallResolver({
userName: 'cognitoUsername',
args: { name: 'Lebowski' },
resolverFunc: greetInner,
});
expect(greeting.greeting).toBe(`${GREETING}, Lebowski!`);
});
});
})
expect(greeting.greeting).toBe(`${GREETING}, Lebowski!`)
})
})
28 changes: 14 additions & 14 deletions backend/src/api/resolver/greeting.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { defaultAppSyncMiddleware } from '@backend/middleware/lambda';
import { logger } from '@backend/util/logger';
import { incrementMetric } from '@backend/util/metrics';
import { AppSyncResolverEvent } from 'aws-lambda';
import { GQL } from '@common/index';
import { defaultAppSyncMiddleware } from '@backend/middleware/lambda'
import { logger } from '@backend/util/logger'
import { incrementMetric } from '@backend/util/metrics'
import { AppSyncResolverEvent } from 'aws-lambda'
import { GreetingResponse, GreetingState, MutationGreetArgs } from '@common/generated/graphql/graphql'

export const GREETING = 'Yo yo';
export const GREETING = 'Yo yo'

// sample query
export const getGreeting = (): GQL.GreetingState => ({
export const getGreeting = (): GreetingState => ({
currentGreeting: GREETING,
});
})

// sample mutation
export const greetInner = async ({
arguments: { name },
}: AppSyncResolverEvent<GQL.MutationGreetArgs>): Promise<GQL.GreetingResponse> => {
incrementMetric('SaidHello');
logger.debug('Saying greeting to', { name });
}: AppSyncResolverEvent<MutationGreetArgs>): Promise<GreetingResponse> => {
incrementMetric('SaidHello')
logger.debug('Saying greeting to', { name })

return {
greeting: `${GREETING}, ${name}!`,
};
};
export const greet = defaultAppSyncMiddleware()(greetInner);
}
}
export const greet = defaultAppSyncMiddleware()(greetInner)
Loading