Skip to content

Commit

Permalink
Update 202304 (#123)
Browse files Browse the repository at this point in the history
* Bump nx

* Bump gql codegen-related packages

* Fix graph-backend

* Update dev-tools

* Use PayloadError

* Update README

* Cleanup

* Bump prisma

* Pin cypress and node
  • Loading branch information
eddeee888 authored Apr 10, 2023
1 parent b775b64 commit d02070b
Show file tree
Hide file tree
Showing 103 changed files with 3,179 additions and 3,029 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
*.generated.*
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ on:
- 'master'

env:
node-version: '16.14'
node-version: '18.x'

jobs:
precheck:
name: Check jobs to run
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
outputs:
affected-main: ${{ steps.affected.outputs.main }}
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.10.0
uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ github.token }}

Expand All @@ -37,11 +37,12 @@ jobs:
- name: Check affected apps
id: affected
run: |
echo "::set-output name=main::$(./ops/bin/check-affected.sh apps main origin/master)"
main_affected=`./ops/bin/check-affected.sh apps main origin/master`
echo "::set-output name=main::$main_affected"
main:
name: Main app CI
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
needs: precheck
if: ${{ needs.precheck.outputs.affected-main == 'true' }}
steps:
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
34 changes: 12 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,34 @@ Note: This setup is for Mac, you will have to do the equivalent if you use Linux
- [Nx](https://nx.dev/)
- [Docker](https://www.docker.com/)

### 🌟 Setting up CLI (Recommended)
### ⚡️ Get Started!

To start on MacOS, setting up the CLI command to make development easier. Go to the root of the project and run the init script.

For convenience, this will install packages, set up SSL, etc.

```
$ ./dev-tools/bin/init.sh
```

### ⚡️ Start the Apps!
#### Set Up Networking

Set up DNS resolver to point related traffic to your host machine using the following command:

```
$ bam vm-up
```bash
$ nx nw-cert dev # Set up TLS certificate
$ nx nw-up dev # Set up DNS resolver
```

Create a base dev image to be shared in the apps. We do this to avoid installing packages multiple times.
#### Start the app

```bash
$ nx serve main
$ nx up dev
```
$ bam build-dev-images
```

#### Generate dummy data

```
$ bam up
$ nx init-database main-prisma
```

Once the containers have been successfully built, go to the following URLs from your favourite browser:

- `https://bam.dev`: Main app
- `https://bam.dev/api/graphql`: GraphQL endpoint

#### Generate dummy data

```
$ nx init-database main-prisma
```

Made with ♥ by Eddy Nguyen
https://eddeee888.me
2 changes: 1 addition & 1 deletion apps/main-e2e/Dockerfile.e2e
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16.14-alpine
FROM node:18.14-alpine

WORKDIR /usr/src/app

Expand Down
2 changes: 1 addition & 1 deletion apps/main-e2e/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.7'

services:
cypress:
image: cypress/included:10.7.0
image: cypress/included:12.9.0
working_dir: /e2e
volumes:
- ../..:/e2e
Expand Down
7 changes: 4 additions & 3 deletions apps/main-e2e/project.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "main-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/main-e2e/src",
"projectType": "application",
Expand All @@ -20,7 +21,7 @@
}
},
"setup": {
"executor": "@nrwl/workspace:run-commands",
"executor": "nx:run-commands",
"defaultConfiguration": "prod",
"configurations": {
"dev": {
Expand All @@ -35,13 +36,13 @@
}
},
"teardown": {
"executor": "@nrwl/workspace:run-commands",
"executor": "nx:run-commands",
"options": {
"command": "apps/main-e2e/bin/teardown.sh"
}
},
"run": {
"executor": "@nrwl/workspace:run-commands",
"executor": "nx:run-commands",
"defaultConfiguration": "host",
"configurations": {
"host": {
Expand Down
2 changes: 1 addition & 1 deletion apps/main/.env.local
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PRISMA_DATABASE_URL=mysql://root:root@main-db:3306/main?schema=public
PRISMA_DATABASE_URL=mysql://root:root@localhost:3306/main?schema=public
PRISMA_BINARY_TARGET=["native","linux-musl"]
5 changes: 2 additions & 3 deletions apps/main/frontend/pageComponents/home/Home.generated.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import * as Types from '@bam/graph-frontend/generated-types';

import { DocumentNode } from 'graphql';
Expand All @@ -9,7 +8,7 @@ export type HomeQueryVariables = Types.Exact<{ [key: string]: never }>;
export type HomeQuery = {
__typename: 'Query';
users:
| { __typename: 'UsersError'; error: Types.ErrorType }
| { __typename: 'PayloadError'; error: Types.ErrorType }
| { __typename: 'UsersResult'; result: Array<{ __typename: 'User'; id: string; displayName: string }> };
};

Expand Down Expand Up @@ -51,7 +50,7 @@ export const HomeDocument = {
},
{
kind: 'InlineFragment',
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'UsersError' } },
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'PayloadError' } },
selectionSet: {
kind: 'SelectionSet',
selections: [{ kind: 'Field', name: { kind: 'Name', value: 'error' } }],
Expand Down
2 changes: 1 addition & 1 deletion apps/main/frontend/pageComponents/home/Home.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ query Home {
displayName
}
}
... on UsersError {
... on PayloadError {
error
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/main/frontend/pageComponents/home/Home.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Homepage', () => {
expect(await screen.findByText('2 - User Two')).toBeInTheDocument();
});

it('should render UsersError correctly', async () => {
it('should render PayloadError correctly', async () => {
render(
<MockedProvider
mocks={[
Expand All @@ -74,7 +74,7 @@ describe('Homepage', () => {
result: {
data: {
users: {
__typename: 'UsersError',
__typename: 'PayloadError',
error: ErrorCodes.FORBIDDEN_ERROR,
},
},
Expand Down
2 changes: 1 addition & 1 deletion apps/main/frontend/pageComponents/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const Home: FunctionComponent = () => {
return <div>Error!</div>;
}

if (data.users.__typename === 'UsersError') {
if (data.users.__typename === 'PayloadError') {
return <div>{errorMessage(data.users.error)}</div>;
}

Expand Down
2 changes: 0 additions & 2 deletions apps/main/graphql-codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ generates:
plugins:
- typescript-operations
- typescript-react-apollo
- add:
content: '/* eslint-disable @typescript-eslint/explicit-function-return-type */'
config:
enumsAsTypes: true
nonOptionalTypename: true
Expand Down
21 changes: 11 additions & 10 deletions apps/main/pages/api/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { createServer } from '@graphql-yoga/node';
import { enableIf } from '@envelop/core';
import { createYoga, createSchema } from 'graphql-yoga';
import { useDisableIntrospection } from '@envelop/disable-introspection';
import { User } from '@bam/main-prisma';
import { resolvers, getTypeDefs } from '@bam/graph-backend';
import type { User } from '@bam/main-prisma';
import { resolvers, typeDefs } from '@bam/graph-backend';
import { prisma } from '../../backend/database/client';

const mode = process.env.NODE_ENV;
const isDev = mode === 'development';

const server = createServer<{
interface NextDefaultContext {
req: NextApiRequest;
res: NextApiResponse;
}>({
schema: {
typeDefs: getTypeDefs(),
}
const server = createYoga<NextDefaultContext>({
schema: createSchema<NextDefaultContext>({
typeDefs: typeDefs,
resolvers: resolvers,
},
}),
landingPage: isDev,
graphiql: isDev,
parserCache: true,
validationCache: true,
maskedErrors: !isDev,
// eslint-disable-next-line react-hooks/rules-of-hooks
plugins: [enableIf(!isDev, useDisableIntrospection())],
plugins: [!isDev && useDisableIntrospection()],
context: async () => {
const user: User | null = null;

Expand Down
18 changes: 8 additions & 10 deletions apps/main/project.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "main",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/main",
"projectType": "application",
Expand All @@ -16,17 +17,12 @@
"outputPath": "apps/main"
},
"production": {
"fileReplacements": [
{
"replace": "libs/graph-backend/src/schemas/utils/getTypeDefs.ts",
"with": "libs/graph-backend/src/schemas/utils/getTypeDefs.prod.js"
}
]
"fileReplacements": []
}
}
},
"build-for-runtime": {
"executor": "@nrwl/workspace:run-commands",
"executor": "nx:run-commands",
"defaultConfiguration": "vercel",
"configurations": {
"vercel": {
Expand All @@ -47,7 +43,9 @@
"configurations": {
"development": {
"buildTarget": "main:build:development",
"dev": true
"dev": true,
"hostname": "0.0.0.0",
"port": 4200
},
"production": {
"buildTarget": "main:build:production",
Expand All @@ -63,7 +61,7 @@
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/apps/main"],
"outputs": ["{workspaceRoot}/coverage/apps/main"],
"options": {
"jestConfig": "apps/main/jest.config.ts",
"passWithNoTests": true
Expand All @@ -78,7 +76,7 @@
},
"graphql-codegen": {
"executor": "@eddeee888/nx-graphql-code-generator:codegen",
"outputs": ["apps/main/frontend/graph/generated"],
"outputs": ["{projectRoot}/frontend/graph/generated"],
"options": {
"configFile": "apps/main/graphql-codegen.yml",
"watch": false
Expand Down
7 changes: 0 additions & 7 deletions dev-tools/.env.docker-compose

This file was deleted.

69 changes: 0 additions & 69 deletions dev-tools/bin/core.sh

This file was deleted.

Loading

0 comments on commit d02070b

Please sign in to comment.