-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added graphql support for express and added some code improvements
- Loading branch information
1 parent
3293f17
commit d618ef1
Showing
81 changed files
with
7,550 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"env": { | ||
"node": true | ||
}, | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint", "import", "prettier"], | ||
"extends": [ | ||
"standard", | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier" | ||
], | ||
"rules": { | ||
"@typescript-eslint/no-var-requires": "off", | ||
"@typescript-eslint/no-empty-interface": "off", | ||
"arrow-parens": ["error", "as-needed"], | ||
"import/extensions": [ | ||
2, | ||
{ | ||
"ts": "never", | ||
"js": "always", | ||
"json": "always" | ||
} | ||
], | ||
"import/no-extraneous-dependencies": [ | ||
"error", | ||
{ | ||
"devDependencies": ["**/*.test.js", "webpack.config.js"], | ||
"optionalDependencies": ["**/*.test.js"], | ||
"peerDependencies": ["**/*.test.js"] | ||
} | ||
], | ||
"max-len": [ | ||
"error", | ||
{ | ||
"code": 80, | ||
"ignoreComments": true, | ||
"ignoreRegExpLiterals": true, | ||
"ignoreTemplateLiterals": true, | ||
"ignoreTrailingComments": true, | ||
"ignoreStrings": true, | ||
"ignoreUrls": true | ||
} | ||
], | ||
"newline-before-return": "error", | ||
"object-curly-spacing": ["error", "always"], | ||
"object-shorthand": ["error", "always"], | ||
"prefer-const": "error", | ||
"prettier/prettier": [ | ||
"error", | ||
{ | ||
"arrowParens": "avoid", | ||
"bracketSpacing": true, | ||
"printWidth": 80, | ||
"quoteProps": "as-needed", | ||
"semi": false, | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "none" | ||
} | ||
], | ||
"radix": ["error", "as-needed"], | ||
"spaced-comment": ["error", "always"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/node,yarn | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=node,yarn | ||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# Next.js build output | ||
.next | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode* | ||
|
||
### yarn ### | ||
# https://yarnpkg.com/advanced/qa#which-files-should-be-gitignored | ||
|
||
# .yarn/unplugged and .yarn/build-state.yml should likely always be ignored since | ||
# they typically hold machine-specific build artifacts. Ignoring them might however | ||
# prevent Zero-Installs from working (to prevent this, set enableScripts to false). | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
|
||
# .yarn/cache and .pnp.* may be safely ignored, but you'll need to run yarn install | ||
# to regenerate them between each branch switch. | ||
# Uncomment the following lines if you're not using Zero-Installs: | ||
# .yarn/cache | ||
# .pnp.* | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/node,yarn | ||
|
||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Example/express Graphql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM node:16-alpine | ||
|
||
WORKDIR /app | ||
|
||
COPY package.json ./ | ||
|
||
RUN yarn install --prod | ||
|
||
RUN yarn add webpack webpack-node-externals tsconfig-paths-webpack-plugin -D | ||
|
||
RUN yarn build | ||
|
||
RUN yarn remove webpack webpack-node-externals tsconfig-paths-webpack-plugin | ||
|
||
COPY dist /app/dist | ||
|
||
CMD [ "yarn", "start" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 AnthonyLzq | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Example/express Graphql | ||
|
||
This is a test using express with GraphQL. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build: | ||
docker: | ||
web: Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"watch": [ | ||
".env", | ||
"src" | ||
], | ||
"ext": "ts", | ||
"ignore": [ | ||
"src/**/*.test.ts" | ||
], | ||
"exec": "npx ts-node -r dotenv/config ./src/index" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"name": "example-express-graphql", | ||
"version": "0.1.0", | ||
"main": "src/index.ts", | ||
"description": "This is a test using express with GraphQL", | ||
"scripts": { | ||
"build:dev": "webpack --mode development", | ||
"build": "webpack --mode production", | ||
"lint": "eslint src/* --ext .ts --fix", | ||
"service": "nodemon", | ||
"start": "node dist/index.js", | ||
"release": "standard-version" | ||
}, | ||
"author": "AnthonyLzq <sluzquinosa@uni.pe>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@graphql-tools/schema": "^8.3.9", | ||
"@sinclair/typebox": "^0.23.4", | ||
"ajv": "^8.11.0", | ||
"ajv-formats": "^2.1.1", | ||
"apollo-server-core": "^3.6.7", | ||
"apollo-server-express": "^3.6.7", | ||
"cors": "^2.8.5", | ||
"express": "^4.17.3", | ||
"express-pino-logger": "^7.0.0", | ||
"graphql": "^16.3.0", | ||
"http-errors": "^2.0.0", | ||
"mongoose": "^6.3.0", | ||
"morgan": "^1.10.0", | ||
"pino-pretty": "^7.6.1", | ||
"swagger-ui-express": "^4.3.0" | ||
}, | ||
"devDependencies": { | ||
"@types/cors": "^2.8.12", | ||
"@types/express": "^4.17.13", | ||
"@types/express-pino-logger": "^4.0.3", | ||
"@types/http-errors": "^1.8.2", | ||
"@types/node": "^17.0.24", | ||
"@types/swagger-ui-express": "^4.1.3", | ||
"@typescript-eslint/eslint-plugin": "^5.19.0", | ||
"@typescript-eslint/parser": "^5.19.0", | ||
"dotenv": "^16.0.0", | ||
"eslint": "^8.13.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-config-standard": "^16.0.3", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-promise": "^6.0.0", | ||
"nodemon": "^2.0.15", | ||
"prettier": "^2.6.2", | ||
"standard-version": "^9.3.2", | ||
"ts-loader": "^9.2.8", | ||
"ts-node": "^10.7.0", | ||
"tsconfig-paths": "^3.14.1", | ||
"tsconfig-paths-webpack-plugin": "^3.5.2", | ||
"typescript": "^4.6.3", | ||
"webpack": "^5.72.0", | ||
"webpack-cli": "^4.9.2", | ||
"webpack-node-externals": "^3.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
type ExpressRequest = import('express').Request | ||
|
||
interface CustomRequest extends ExpressRequest { | ||
log: import('express-pino-logger').HttpLogger['logger'] | ||
body: { | ||
args?: import('schemas').UserDTO | ||
} | ||
// We can add custom headers via intersection, remember that for some reason | ||
// headers must be in Snake-Pascal-Case | ||
headers: import('http').IncomingHttpHeaders & { | ||
'Custom-Header'?: string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type ExpressResponse = import('express').Response | ||
|
||
interface CustomResponse extends ExpressResponse { | ||
newValue?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type Context = { | ||
log: import('express-pino-logger').HttpLogger['logger'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* eslint-disable no-var */ | ||
declare global {} | ||
|
||
export {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface UserDBO { | ||
id: string | ||
name: string | ||
lastName: string | ||
createdAt: Date | ||
updatedAt: Date | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './mongo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './models' | ||
export * from './queries' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './user' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { model, Schema } from 'mongoose' | ||
|
||
const UserSchema = new Schema<UserDBO>( | ||
{ | ||
lastName: { | ||
required: true, | ||
type: String | ||
}, | ||
name: { | ||
required: true, | ||
type: String | ||
} | ||
}, | ||
{ | ||
timestamps: true, | ||
versionKey: false, | ||
toObject: { | ||
transform: (_, ret) => { | ||
ret.id = ret._id.toString() | ||
delete ret._id | ||
} | ||
} | ||
} | ||
) | ||
|
||
const UserModel = model<UserDBO>('users', UserSchema) | ||
|
||
export { UserModel } |
Oops, something went wrong.