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

docs(readme): added QA section #62

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
91 changes: 91 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
push:
branches: ['main']
pull_request:
branches: ['main']

permissions:
checks: write
contents: write

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.17.0]
environment: test
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: yarn
- name: Create mongo Docker container
uses: DigiPie/mongo-action@v2.0.1
with:
image_version: latest
port: 27017
- name: Install mongosh command
run: |
sudo apt-get update
sudo apt-get install -y wget gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt-get update
sudo apt-get install -y mongodb-mongosh
- name: Test mongo connection
run: 'sudo mongosh localhost:27017'
- name: create env file
run: |
touch .env
echo GRAPHQL_PORT=$GRAPHQL_PORT >> .env
echo GRAPHQL_PORT_DEV=$GRAPHQL_PORT_DEV >> .env
echo HOSTNAME=$HOSTNAME >> .env d
echo DB_NAME=$DB_NAME >> .env
echo DB_HOST=$DB_HOST >> .env
echo DB_PORT=$DB_PORT >> .env
echo PORT=$PORT >> .env
echo JWTSECRET=$JWTSECRET >> .env
echo JWTKEY=$JWTKEY >> .env
echo USER_PASSWORD_TEST=$USER_PASSWORD_TEST >> .env
echo USER_PASSWORD_DUMMY_TEST=$USER_PASSWORD_DUMMY_TEST >> .env
echo USER_PASSWORD_ENCRYPTED_TEST=$USER_PASSWORD_ENCRYPTED_TEST >> .env
env:
GRAPHQL_PORT: ${{ vars.GRAPHQL_PORT }}
GRAPHQL_PORT_DEV: ${{ vars.GRAPHQL_PORT_DEV }}
DB_NAME: ${{ vars.DB_NAME }}
DB_HOST: ${{ vars.DB_HOST }}
DB_PORT: ${{ vars.DB_PORT }}
PORT: ${{ vars.PORT }}
JWTSECRET: ${{ secrets.JWTSECRET }}
JWTKEY: ${{ secrets.JWTKEY }}
USER_PASSWORD_TEST: ${{ secrets.USER_PASSWORD_TEST }}
USER_PASSWORD_DUMMY_TEST: ${{ secrets.USER_PASSWORD_DUMMY_TEST }}
USER_PASSWORD_ENCRYPTED_TEST: ${{ secrets.USER_PASSWORD_ENCRYPTED_TEST }}
- name: Run linters
uses: wearerequired/lint-action@v2
with:
eslint: true
prettier: true
- name: np build
run: npm run build --if-present
- name: Test and coverage
run: yarn jest --coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@
"connectionId": "jeresoftx",
"projectKey": "jeresoftx_supergraph-typescript"
},
"conventionalCommits.scopes": ["husky"]
"conventionalCommits.scopes": [
"husky",
"vscode",
"github",
"typescript",
"cspell",
"pnpm",
"Readme"
]
}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ You have successfully set up and started the application. If you encounter any i

[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)


## QA
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=jeresoftx_supergraph-typescript&metric=bugs)](https://sonarcloud.io/dashboard?id=jeresoftx_supergraph-typescript) [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=jeresoftx_supergraph-typescript&metric=code_smells)](https://sonarcloud.io/dashboard?id=jeresoftx_supergraph-typescript) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=jeresoftx_supergraph-typescript&metric=coverage)](https://sonarcloud.io/dashboard?id=jeresoftx_supergraph-typescript) [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=jeresoftx_supergraph-typescript&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=jeresoftx_supergraph-typescript) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=jeresoftx_supergraph-typescript&metric=ncloc)](https://sonarcloud.io/dashboard?id=jeresoftx_supergraph-typescript) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=jeresoftx_supergraph-typescript&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=jeresoftx_supergraph-typescript) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=jeresoftx_supergraph-typescript&metric=alert_status)](https://sonarcloud.io/dashboard?id=jeresoftx_supergraph-typescript) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=jeresoftx_supergraph-typescript&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=jeresoftx_supergraph-typescript) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=jeresoftx_supergraph-typescript&metric=security_rating)](https://sonarcloud.io/dashboard?id=jeresoftx_supergraph-typescript) [![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=jeresoftx_supergraph-typescript&metric=sqale_index)](https://sonarcloud.io/dashboard?id=jeresoftx_supergraph-typescript) [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=jeresoftx_supergraph-typescript&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=jeresoftx_supergraph-typescript)

## OTHERS

[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) [![Conventional commits: commitlint](https://img.shields.io/badge/Coventional_commits-commitlint-ff69b4.svg?style=flat-square)](https://www.conventionalcommits.org/)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) [![Coventional commits: commitlint](https://img.shields.io/badge/Coventional_commits-commitlint-ff69b4.svg?style=flat-square)](https://www.conventionalcommits.org/) [![jest tested](https://img.shields.io/badge/Jest-tested-eee.svg?logo=jest&labelColor=99424f)](https://github.com/jestjs/jest)
7 changes: 7 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM mongo:6.0.9-rc0

COPY docker-entrypoint.sh /usr/local/bin/
COPY ./json /json

RUN ["chmod", "+x", "/usr/local/bin/docker-entrypoint.sh"]
ENTRYPOINT ["sh", "/usr/local/bin/docker-entrypoint.sh"]
12 changes: 12 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.9'
services:
mongodb:
container_name: mongodb
build:
context: .
dockerfile: ./Docketfile
image: mongodb
ports:
- ${DB_PORT}:${DB_PORT}
volumes:
- ./json:/json
23 changes: 23 additions & 0 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -e

# Init Mongo service in background
mongod --fork --bind_ip_all --port 27017 --logpath /data/db/mongodb.log

# Sleep ten second while mongo start
sleep 10

# create the user collection if don't exists
mongosh --eval 'db = db.getSiblingDB("javascript_graphql_simple"); if (!db.users.countDocuments()) { db.createCollection("users"); }'

# Import user collection
mongoimport --host localhost --port 27017 --db javascript_graphql_simple --collection users --file ./json/users.json --jsonArray

# Import permissions collection
mongoimport --host localhost --port 27017 --db javascript_graphql_simple --collection permissions --file ./json/permissions.json --jsonArray

# Import roles collection
mongoimport --host localhost --port 27017 --db javascript_graphql_simple --collection roles --file ./json/roles.json --jsonArray

# Keep script running to keep MongoDB connection open
tail -f /dev/null
72 changes: 72 additions & 0 deletions docker/json/permissions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
[
{
"_id": {
"$oid": "6466bc0ac1ca2e6dca0597cb"
},
"name": "permissions",
"description": "Call used to browse a exist permission.",
"createdAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"updatedAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"__v": 0
},
{
"_id": {
"$oid": "6466bc0ab1ca2e6dca0597cb"
},
"name": "readPermission",
"description": "Call used to read a exist permission.",
"createdAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"updatedAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"__v": 0
},
{
"_id": {
"$oid": "6466bc0aa1ca2e6dca0597ca"
},
"name": "editPermission",
"description": "Call used to update a exist permission.",
"createdAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"updatedAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"__v": 0
},
{
"_id": {
"$oid": "6466bc0aa1ca2e6dca0597ce"
},
"name": "addPermission",
"description": "Call used to add a new permission into the database.",
"createdAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"updatedAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"__v": 0
},
{
"_id": {
"$oid": "6466bc0aa1ca2e6dca0595cb"
},
"name": "deletePermission",
"description": "Call used to delete a exist permission.",
"createdAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"updatedAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"__v": 0
}
]
52 changes: 52 additions & 0 deletions docker/json/roles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{
"_id": {
"$oid": "6466bc0aa1ca2e6dcd0597cb"
},
"name": "Super Admin",
"permissions": [
{
"id": "6466bc0aa1ca2e6dca0597bb",
"permission": "*"
}
],
"createdAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"updatedAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"__v": 0
},
{
"_id": {
"$oid": "6466bc0aa1ca2e6dcd0597ab"
},
"name": "Admin",
"permissions": [
{
"id": "6466bc0aa1cf2e6dca0597cb",
"permission": "browseUser"
},
{
"id": "6466bc0aa1c32e6dca0597cb",
"permission": "readUser"
},
{
"id": "6466bc0aa1ca2e6dca0597ca",
"permission": "editUser"
},
{
"id": "6466bc0aa1ca2e6dca0597ce",
"permission": "addUser"
}
],
"createdAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"updatedAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"__v": 0
}
]
39 changes: 39 additions & 0 deletions docker/json/users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
{
"_id": {
"$oid": "6466bc0aa1ca2e6dca0597cb"
},
"username": "jeresoft",
"name": "Joel",
"lastName": "Alvarez Mexia",
"fullName": "Joel Alvarez Mexia",
"emails": [
{
"email": "jeresoft@gmail.com",
"main": true
},
{
"email": "jeresoft+other@gmail.com",
"main": false
}
],
"phones": [
{
"phone": "6691230103",
"main": true
}
],
"roles": ["superAdmin"],
"password": "",
"createdAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"updatedAt": {
"$date": "2023-07-29T00:00:13.000Z"
},
"lastConnected": {
"$date": "2023-07-29T00:00:13.000Z"
},
"__v": 0
}
]
14 changes: 14 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sonar.projectKey=jeresoftx_supergraph-typescript
sonar.organization=jeresoftx

# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=javascript-grapqhl-simple
#sonar.projectVersion=1.0


# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=src
#sonar.coverage.exclusions=src/server/*.js,src/index.js

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
35 changes: 35 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import { buildSubgraphSchema } from '@apollo/subgraph';
import { readFileSync } from 'fs';
import gql from 'graphql-tag';

const typeDefs = gql(
readFileSync(__dirname.concat('/schema.graphql'), { encoding: 'utf-8' }),
);

import { resolvers } from './resolvers';

const startApolloServer = async () => {
const server = new ApolloServer({
schema: buildSubgraphSchema({ typeDefs, resolvers }),
});

const port = 4002;
const subgraphName = 'users';

try {
const { url } = await startStandaloneServer(server, {
context: async () => {
return {};
},
listen: { port },
});

console.log(`🚀 Subgraph ${subgraphName} running at ${url}`);
} catch (err) {
console.error(err);
}
};

startApolloServer();
Loading
Loading