Skip to content

Commit a1c049f

Browse files
committed
first blood
0 parents  commit a1c049f

25 files changed

+683
-0
lines changed

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# https://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_style = tab
7+
charset = utf-8
8+
end_of_line = lf
9+
indent_size = 4
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true

.env

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PORT=3000
2+
JWT_SECRET_KEY=4Z9pB2cT8aX7fN6qR5vY3gH1jM0wE2sD

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PORT=3000
2+
JWT_SECRET_KEY=4Z9pB2cT8aX7fN6qR5vY3gH1jM0wE2sD

.eslintrc.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
project: 'tsconfig.json',
5+
tsconfigRootDir: __dirname,
6+
sourceType: 'module',
7+
},
8+
plugins: ['@typescript-eslint/eslint-plugin'],
9+
extends: [
10+
'plugin:@typescript-eslint/recommended',
11+
'plugin:prettier/recommended',
12+
],
13+
root: true,
14+
env: {
15+
node: true,
16+
jest: true,
17+
},
18+
ignorePatterns: ['.eslintrc.js'],
19+
rules: {
20+
'@typescript-eslint/interface-name-prefix': 'off',
21+
'@typescript-eslint/explicit-function-return-type': 'off',
22+
'@typescript-eslint/explicit-module-boundary-types': 'off',
23+
'@typescript-eslint/no-explicit-any': 'off',
24+
},
25+
};

.gitignore

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel
35+
36+
**/*.trace
37+
**/*.zip
38+
**/*.tar.gz
39+
**/*.tgz
40+
**/*.log
41+
package-lock.json
42+
**/*.bun

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm run format

.prettierrc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"singleQuote": false,
3+
"printWidth": 120,
4+
"proseWrap": "always",
5+
"tabWidth": 4,
6+
"useTabs": false,
7+
"parser": "typescript",
8+
"trailingComma": "all",
9+
"bracketSpacing": true,
10+
"semi": true,
11+
"endOfLine": "lf",
12+
"arrowParens": "always"
13+
}

.vscode/.settings.json

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"workbench.iconTheme": "material-icon-theme",
3+
"workbench.colorTheme": "Omni",
4+
"[jsonc]": {
5+
"editor.defaultFormatter": "vscode.json-language-features"
6+
},
7+
"workbench.editor.wrapTabs": true,
8+
"diffEditor.ignoreTrimWhitespace": false,
9+
"workbench.statusBar.visible": true,
10+
"explorer.confirmDelete": true,
11+
"editor.suggestSelection": "first",
12+
"javascript.updateImportsOnFileMove.enabled": "always",
13+
"typescript.updateImportsOnFileMove.enabled": "always",
14+
"editor.formatOnPaste": true,
15+
"json.format.keepLines": false,
16+
"editor.codeActionsOnSave": {
17+
"source.fixAll": "explicit"
18+
},
19+
"javascript.format.insertSpaceBeforeFunctionParenthesis": false,
20+
"javascript.format.placeOpenBraceOnNewLineForControlBlocks": false,
21+
"javascript.format.placeOpenBraceOnNewLineForFunctions": false,
22+
"typescript.format.insertSpaceBeforeFunctionParenthesis": false,
23+
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": false,
24+
"typescript.format.placeOpenBraceOnNewLineForFunctions": false,
25+
"explorer.confirmDragAndDrop": true,
26+
"editor.inlineSuggest.enabled": true,
27+
"git.autofetch": true,
28+
"css.format.enable": false,
29+
"php.validate.enable": false,
30+
"editor.insertSpaces": false,
31+
"json.format.enable": true,
32+
"editor.unicodeHighlight.invisibleCharacters": false,
33+
"[json]": {
34+
"editor.defaultFormatter": "vscode.json-language-features"
35+
},
36+
"editor.fontSize": 16,
37+
"editor.wordWrap": "on",
38+
"editor.formatOnSave": true,
39+
"files.exclude": {
40+
"**/.trunk/*out": true,
41+
"**/.trunk/*out/": true,
42+
"**/.trunk/*actions/": true,
43+
"**/.trunk/*logs/": true,
44+
"**/.trunk/*plugins/": true
45+
},
46+
"files.watcherExclude": {
47+
"**/.trunk/*out": true,
48+
"**/.trunk/*out/": true,
49+
"**/.trunk/*actions/": true,
50+
"**/.trunk/*logs/": true,
51+
"**/.trunk/*plugins/": true
52+
},
53+
"errorLens.excludeBySource": [
54+
"dockerfile-utils(37)"
55+
],
56+
"[typescript]": {},
57+
"files.associations": {
58+
"*.ts": "typescript"
59+
},
60+
"window.zoomLevel": 1,
61+
"workbench.editor.empty.hint": "hidden"
62+
}

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<div align="center">
2+
<h1 align="center">ToDo GraphQL API using Redis</a>
3+
</div>
4+
5+
## Introduction
6+
7+
- A personal project I created to learn and improve my skills in:
8+
- [Elysia](https://elysiajs.com/)
9+
- [Redis](https://redis.io/)
10+
- [Apollo GraphQL](https://www.apollographql.com/)
11+
12+
- Techonologies:
13+
- [NodeJS v20](https://nodejs.org/en)
14+
- [TypeScript](https://www.typescriptlang.org/)
15+
- [Bun](https://bun.sh/)
16+
- [JWT](https://jwt.io/)
17+
18+
## Development Setup Local
19+
20+
1. Clone repository
21+
```
22+
git clone [email protected]:AlexGalhardo/todo-graphql-api-using-redis.git
23+
```
24+
25+
2. Install dependencies
26+
```
27+
bun install
28+
```
29+
30+
3. Create .env
31+
```
32+
cp .env.example .env
33+
```
34+
35+
4. Up Apollo GraphQL server
36+
```
37+
bun run server
38+
```
39+
40+
41+
## [Single-file executable](https://bun.sh/docs/bundler/executables)
42+
43+
- Building Server
44+
```
45+
bun build --compile --minify ./src/server.ts --outfile server
46+
```
47+
48+
- Executing binary
49+
```
50+
./server
51+
```
52+
53+
54+
## License
55+
56+
[MIT](http://opensource.org/licenses/MIT)
57+
58+
Copyright (c) April 2024-present, [Alex Galhardo](https://github.com/AlexGalhardo)

bun.lockb

122 KB
Binary file not shown.

curl/signup.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
curl -X POST \
2+
http://localhost:3000/graphql \
3+
-H 'Content-Type: application/json' \
4+
-d '{
5+
"query": "mutation signup($name: String!, $email: String!, $password: String!) { signup(name: $name, email: $email, password: $password) { success message user { id name email password updated_at created_at jwt_token_session } } }",
6+
"variables": {
7+
"name": "test",
8+
"email": "[email protected]",
9+
"password": "testqweBR@123"
10+
}
11+
}'

docker-compose.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '3'
2+
3+
services:
4+
redis:
5+
image: redis:latest
6+
container_name: redis
7+
restart: unless-stopped
8+
ports:
9+
- "6379:6379"

package.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "todo-graphql-api-using-redis",
3+
"scripts": {
4+
"server": "bun run --watch src/server.ts",
5+
"format": "prettier --write \"src/**/*.ts\"",
6+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
7+
"husky": "husky install",
8+
"build": "bun build --compile --minify ./src/server.ts --outfile server",
9+
"prod:server": "./server"
10+
},
11+
"dependencies": {
12+
"@apollo/server": "^4.10.4",
13+
"@elysiajs/apollo": "^1.0.3",
14+
"@elysiajs/cors": "^1.0.2",
15+
"@types/node": "^20.12.7",
16+
"bcryptjs": "^2.4.3",
17+
"dotenv": "^16.4.5",
18+
"elysia": "latest",
19+
"graphql": "^16.8.1",
20+
"ioredis": "^5.4.1",
21+
"joi": "^17.13.0",
22+
"jsonwebtoken": "^9.0.2"
23+
},
24+
"devDependencies": {
25+
"@types/bcryptjs": "^2.4.6",
26+
"@types/jsonwebtoken": "^9.0.6",
27+
"bun-types": "latest",
28+
"@faker-js/faker": "^8.4.1",
29+
"@types/body-parser": "^1.19.5",
30+
"eslint-config-prettier": "^9.1.0",
31+
"eslint-plugin-prettier": "^5.1.3",
32+
"prettier": "^3.2.5",
33+
"@typescript-eslint/eslint-plugin": "^7.7.1",
34+
"@typescript-eslint/parser": "^7.7.1",
35+
"eslint": "^8.57.0",
36+
"husky": "^9.0.11"
37+
}
38+
}

rest-client/login.http

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
POST http://localhost:3000/form
2+
Content-Type: "application/json"
3+
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2VtYWlsIjoiYWxlZXhndmllaXJhQGdtYWlsLmNvbSJ9.-H3Psc0mmQe4J82gq16tAp4xZCSxMZgTD2lyD17lZjo
4+
5+
{
6+
"username": "alex",
7+
"email": "[email protected]",
8+
"password": "123456"
9+
}

rest-client/signup.http

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
POST http://localhost:3000/graphql
2+
Content-Type: application/json
3+
4+
{
5+
"query": "mutation signup($name: String!, $email: String!, $password: String!) { signup(name: $name, email: $email, password: $password) { success message user { id name email password updated_at created_at jwt_token_session } } }",
6+
"variables": {
7+
"name": "test",
8+
"email": "[email protected]",
9+
"password": "pedrooooooooooBR@123"
10+
}
11+
}

rest-client/todos.http

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GET http://localhost:3000/id/pakspoas

src/config/redis.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Redis from "ioredis";
2+
3+
export const redis = new Redis({
4+
port: 6379,
5+
host: "127.0.0.1",
6+
name: "default",
7+
password: "my-top-secret",
8+
db: 0,
9+
});

0 commit comments

Comments
 (0)