Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommytrg committed Jun 1, 2021
0 parents commit b77014f
Show file tree
Hide file tree
Showing 55 changed files with 30,281 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
19 changes: 19 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Run lint, test and build

on: pull_request

jobs:
lint_and_test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/[email protected]
with:
node-version: '14'
- run: yarn
- run: yarn bootstrap
- run: yarn lint
- run: yarn test
- run: yarn build
116 changes: 116 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# 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/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# 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
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# 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-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
Empty file added README.md
Empty file.
6 changes: 6 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: [
"@commitlint/config-conventional",
"@commitlint/config-lerna-scopes",
],
}
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: "3.8"

x-var: &DB_NAME database

services:
*DB_NAME:
image: mongo:4
container_name: *DB_NAME
ports:
- $MONGO_PORT:27017
environment:
MONGO_DATABASE_USERNAME: $MONGO_DATABASE_USERNAME
MONGO_DATABASE_PASSWORD: $MONGO_DATABASE_PASSWORD
MONGO_INITDB_DATABASE: $MONGO_INITDB_DATABASE
MONGO_INITDB_ROOT_USERNAME: $MONGO_INITDB_ROOT_USERNAME
MONGO_INITDB_ROOT_PASSWORD: $MONGO_INITDB_ROOT_PASSWORD
volumes:
- ./init-mongo.sh:/docker-entrypoint-initdb.d/init-mongo.sh
- mongodb_data_container:/data/db

mongo-express:
image: "mongo-express"
container_name: mongo-express
ports:
- "8081:8081"
depends_on:
- *DB_NAME
environment:
ME_CONFIG_MONGODB_SERVER: *DB_NAME
ME_CONFIG_MONGODB_AUTH_DATABASE: $MONGO_INITDB_DATABASE
ME_CONFIG_MONGODB_AUTH_USERNAME: $MONGO_DATABASE_USERNAME
ME_CONFIG_MONGODB_AUTH_PASSWORD: $MONGO_DATABASE_PASSWORD
ME_CONFIG_BASICAUTH_USERNAME: $ME_CONFIG_BASICAUTH_USERNAME
ME_CONFIG_BASICAUTH_PASSWORD: $ME_CONFIG_BASICAUTH_PASSWORD
ME_CONFIG_MONGODB_ENABLE_ADMIN: "false"

volumes:
mongodb_data_container:
21 changes: 21 additions & 0 deletions init-mongo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -e;

# a default non-root role
MONGO_NON_ROOT_ROLE="${MONGO_NON_ROOT_ROLE:-readWrite}"

echo ">>>>>>> Creating database and users..."
if [ -n "${MONGO_DATABASE_USERNAME:-}" ] && [ -n "${MONGO_DATABASE_PASSWORD:-}" ]; then
mongo -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD <<-EOF
db=db.getSiblingDB("$MONGO_INITDB_DATABASE");
use $MONGO_INITDB_DATABASE
db.createUser({
user: $(_js_escape "$MONGO_DATABASE_USERNAME"),
pwd: $(_js_escape "$MONGO_DATABASE_PASSWORD"),
roles: [ { role: $(_js_escape "$MONGO_NON_ROOT_ROLE"), db: $(_js_escape "$MONGO_INITDB_DATABASE") } ]
})
EOF
else
echo "Database and user creation failed. The variables listed in .env.sample must be provided in a .env file."
exit 403
fi
13 changes: 13 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"packages": [
"packages/*"
],
"npmClient": "yarn",
"version": "0.0.0",
"useWorkspaces": true,
"nohoist": [
"parcel-bundler"
]
}


37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "data-feed-app",
"private": true,
"version": "1.0.0",
"description": "",
"main": "index.js",
"author": "",
"license": "GPL-3.0",
"workspaces": [
"packages/*"
],
"scripts": {
"bootstrap": "yarn lerna bootstrap",
"build": "yarn lerna run build --stream --concurrency 1",
"test": "yarn lerna run test --stream ",
"lint": "yarn lerna run lint --stream --concurrency 1",
"clean": "yarn lerna run clean --concurrency 4"
},
"devDependencies": {
"lerna": "^3.22.1",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@commitlint/config-lerna-scopes": "^11.0.0",
"commitlint": "^11.0.0",
"husky": "^4.3.0",
"prettier-standard": "^16.4.1"
},
"volta": {
"node": "14.15.4",
"yarn": "1.22.10"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
4 changes: 4 additions & 0 deletions packages/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
build
src/generated
node_modules
2 changes: 2 additions & 0 deletions packages/api/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/*.sh
**/*.yml
4 changes: 4 additions & 0 deletions packages/api/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node'
}
6 changes: 6 additions & 0 deletions packages/api/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": ["src"],
"ext": "ts",
"ignore": [".git", "node_modules"],
"exec": "npx ts-node --require dotenv/config ./src/server.ts"
}
41 changes: 41 additions & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc -p .",
"codegen": "graphql-codegen --config codegen.yml",
"lint": "prettier-standard --format",
"dev": "nodemon",
"start": "node dist/server.js",
"test": "jest"
},
"license": "ISC",
"devDependencies": {
"@graphql-codegen/cli": "^1.21.5",
"@graphql-codegen/typescript-mongodb": "^1.19.1",
"@graphql-codegen/typescript-resolvers": "^1.19.2",
"@graphql-codegen/typescript": "^1.22.1",
"@graphql-tools/schema": "^7.1.5",
"@types/jest": "^26.0.23",
"@types/mongodb": "^3.6.16",
"@types/node": "^15.6.1",
"apollo-datasource-mongodb": "^0.4.1",
"apollo-server-testing": "^2.25.0",
"husky": "^6.0.0",
"mongodb-memory-server": "^6.9.6",
"nodemon": "^2.0.7",
"prettier-standard": "^16.4.1",
"ts-jest": "^27.0.1",
"ts-node": "^10.0.0",
"typescript": "^4.3.2"
},
"dependencies": {
"apollo-server": "^2.22.1",
"dotenv": "^10.0.0",
"graphql": "^15.5.0",
"jest": "^27.0.1",
"mongodb": "^3.6.9"
}
}
1 change: 1 addition & 0 deletions packages/api/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# apollo-server + mongodb + jest boilerplate
10 changes: 10 additions & 0 deletions packages/api/sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SERVER_PORT=3100
DB_HOSTNAME=localhost
MONGO_PORT=27017
MONGO_DATABASE_USERNAME=your_username
MONGO_DATABASE_PASSWORD=your_password
MONGO_INITDB_DATABASE=database
MONGO_INITDB_ROOT_USERNAME=your_admin_username
MONGO_INITDB_ROOT_PASSWORD=your_admin_password
ME_CONFIG_BASICAUTH_USERNAME=your_mongo_express_username
ME_CONFIG_BASICAUTH_PASSWORD=your_mongo_express_password
46 changes: 46 additions & 0 deletions packages/api/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ApolloServer, gql } from 'apollo-server'

async function main () {
const app = await createApp()

// app.listen()
}

async function createApp (): Promise<any> {
const feeds = [
{
name: 'btc/usd',
price: 50000.0001
},
{
title: 'eth/usd',
price: 3000.0001
}
]

const typeDefs = gql`
type Feed {
name: String
price: Float
}
type Query {
feeds: [Feed]
}
`

const resolvers = {
Query: {
feeds: () => feeds
}
}

const server = new ApolloServer({ typeDefs, resolvers })

// The `listen` method launches a web server.
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`)
})
}

main()
Loading

0 comments on commit b77014f

Please sign in to comment.