├── webapp ├── src │ ├── assets │ │ └── .gitkeep │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── styles.css │ ├── favicon.ico │ ├── typings.d.ts │ ├── tsconfig.app.json │ ├── app │ │ ├── @core │ │ │ ├── operators.ts │ │ │ ├── core.component.ts │ │ │ ├── core.routing.ts │ │ │ └── core.module.ts │ │ ├── @shared │ │ │ ├── models │ │ │ │ └── thought.model.ts │ │ │ ├── components │ │ │ │ ├── loading │ │ │ │ │ ├── loading.component.ts │ │ │ │ │ └── loading.component.spec.ts │ │ │ │ └── menu │ │ │ │ │ ├── menu.component.ts │ │ │ │ │ └── menu.component.spec.ts │ │ │ ├── services │ │ │ │ ├── thoughts.service.spec.ts │ │ │ │ └── thoughts.service.ts │ │ │ ├── shared.module.ts │ │ │ ├── store │ │ │ │ ├── actions │ │ │ │ │ ├── create.action.ts │ │ │ │ │ ├── remove.action.ts │ │ │ │ │ ├── thoughts.action.ts │ │ │ │ │ └── thought-details.action.ts │ │ │ │ ├── reducers │ │ │ │ │ ├── create.reducer.ts │ │ │ │ │ ├── remove.reducer.ts │ │ │ │ │ ├── thoughts.reducer.ts │ │ │ │ │ └── thought-details.reducer.ts │ │ │ │ ├── index.ts │ │ │ │ └── effects │ │ │ │ │ └── thoughts.effect.ts │ │ │ └── utils │ │ │ │ └── helpers.ts │ │ ├── pages │ │ │ ├── home │ │ │ │ ├── home.component.ts │ │ │ │ ├── home.module.ts │ │ │ │ └── home.component.spec.ts │ │ │ ├── pages.component.ts │ │ │ ├── about │ │ │ │ ├── about.component.ts │ │ │ │ ├── about.module.ts │ │ │ │ └── about.component.spec.ts │ │ │ ├── pages.module.ts │ │ │ ├── thoughts │ │ │ │ ├── view │ │ │ │ │ ├── view.module.ts │ │ │ │ │ ├── view.component.spec.ts │ │ │ │ │ └── view.component.ts │ │ │ │ ├── list │ │ │ │ │ ├── list.module.ts │ │ │ │ │ ├── item.component.ts │ │ │ │ │ ├── item.component.spec.ts │ │ │ │ │ ├── list.component.spec.ts │ │ │ │ │ └── list.component.ts │ │ │ │ └── create │ │ │ │ │ ├── create.module.ts │ │ │ │ │ ├── create.component.spec.ts │ │ │ │ │ └── create.component.ts │ │ │ └── pages.routing.ts │ │ └── app.module.ts │ ├── index.html │ ├── tsconfig.spec.json │ ├── main.ts │ ├── test.ts │ └── polyfills.ts ├── e2e │ ├── app.po.ts │ ├── tsconfig.e2e.json │ └── app.e2e-spec.ts ├── .editorconfig ├── tsconfig.json ├── .gitignore ├── protractor.conf.js ├── karma.conf.js ├── README.md ├── .angular-cli.json ├── package.json └── tslint.json ├── api ├── src │ ├── config │ │ ├── env.ts │ │ ├── config.json │ │ └── database.json │ ├── models │ │ ├── index.ts │ │ └── thought.ts │ ├── schema │ │ ├── index.ts │ │ ├── query.ts │ │ ├── mutation.ts │ │ └── thoughts │ │ │ ├── fields │ │ │ ├── query.ts │ │ │ └── mutations.ts │ │ │ ├── type.ts │ │ │ └── resolvers.ts │ ├── index.ts │ └── setup │ │ ├── graphql.ts │ │ ├── loadModules.ts │ │ ├── databaseConnection.ts │ │ └── startServer.ts ├── gulpfile.js ├── tsconfig.json ├── .gitignore └── package.json ├── package.json ├── .gitignore ├── yarn.lock ├── LICENSE └── README.md /webapp/src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /api/src/config/env.ts: -------------------------------------------------------------------------------- 1 | export default process.env.NODE_ENV || 'development' 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "graphql-schema-decorator": "^0.8.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /webapp/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /webapp/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /webapp/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rafaesc/fullstack-graphql-angular/HEAD/webapp/src/favicon.ico -------------------------------------------------------------------------------- /webapp/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /api/src/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "graphqlEndpoint": "/", 3 | "port": 3000, 4 | "graphql": { 5 | "ide": true, 6 | "pretty": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /api/gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | 3 | gulp.task('copy', function () { 4 | return gulp.src('./src/config/**/*.json') 5 | .pipe(gulp.dest('./lib/config')); 6 | }); -------------------------------------------------------------------------------- /api/src/models/index.ts: -------------------------------------------------------------------------------- 1 | // App Imports 2 | import databaseConnection from '../setup/databaseConnection' 3 | 4 | const models: any = { 5 | Thought: databaseConnection.import('./thought') 6 | } 7 | 8 | export default models 9 | -------------------------------------------------------------------------------- /webapp/e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /webapp/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "baseUrl": "./", 6 | "module": "es2015", 7 | "types": [] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /api/src/schema/index.ts: -------------------------------------------------------------------------------- 1 | // Imports 2 | import { GraphQLSchema } from 'graphql' 3 | 4 | // App Imports 5 | import query from './query' 6 | import mutation from './mutation' 7 | 8 | // Schema 9 | const schema = new GraphQLSchema({ 10 | query, 11 | mutation 12 | }) 13 | 14 | export default schema 15 | -------------------------------------------------------------------------------- /webapp/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /webapp/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "jasminewd2", 11 | "node" 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IDEs and editors 2 | /.idea 3 | .project 4 | .classpath 5 | .c9/ 6 | *.launch 7 | .settings/ 8 | *.sublime-workspace 9 | 10 | # IDE - VSCode 11 | .vscode/* 12 | !.vscode/settings.json 13 | !.vscode/tasks.json 14 | !.vscode/launch.json 15 | !.vscode/extensions.json 16 | 17 | # System Files 18 | .DS_Store 19 | Thumbs.db -------------------------------------------------------------------------------- /webapp/src/app/@core/operators.ts: -------------------------------------------------------------------------------- 1 | // rxjs 2 | import 'rxjs/add/operator/catch'; 3 | import 'rxjs/add/operator/map'; 4 | import 'rxjs/add/operator/mergeMap'; 5 | import 'rxjs/add/operator/switchMap'; 6 | import 'rxjs/add/operator/delay'; 7 | import 'rxjs/add/operator/debounce'; 8 | import 'rxjs/add/operator/do'; 9 | import 'rxjs/add/operator/withLatestFrom'; 10 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/models/thought.model.ts: -------------------------------------------------------------------------------- 1 | export class Thought { 2 | public id?: string; 3 | public name: string; 4 | public thought: string; 5 | 6 | constructor(thought?: any) { 7 | this.id = thought ? thought.id : ''; 8 | this.name = thought ? thought.name : ''; 9 | this.thought = thought ? thought.thought : ''; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /api/src/models/thought.ts: -------------------------------------------------------------------------------- 1 | import { Sequelize, DataTypes } from 'sequelize'; 2 | 3 | // Thought 4 | export default (sequelize: Sequelize, dataTypes: DataTypes) => { 5 | return sequelize.define('thoughts', { 6 | name: { 7 | type: dataTypes.STRING 8 | }, 9 | thought: { 10 | type: dataTypes.TEXT 11 | } 12 | }) 13 | } -------------------------------------------------------------------------------- /webapp/e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('webapp App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to app!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /webapp/src/app/pages/home/home.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-home', 5 | template: ` 6 |

Home

7 |

8 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras mollis sem eu massa maximus. 9 |

10 | `, 11 | styles: [] 12 | }) 13 | export class HomeComponent {} 14 | -------------------------------------------------------------------------------- /webapp/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Webapp 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /api/src/schema/query.ts: -------------------------------------------------------------------------------- 1 | // Imports 2 | import { GraphQLObjectType } from 'graphql' 3 | 4 | // App Imports 5 | import * as thought from './thoughts/fields/query' 6 | 7 | // Query 8 | const query = new GraphQLObjectType({ 9 | name: 'query', 10 | description: '...', 11 | 12 | fields: () => ({ 13 | ...thought 14 | }) 15 | }) 16 | 17 | export default query -------------------------------------------------------------------------------- /api/src/schema/mutation.ts: -------------------------------------------------------------------------------- 1 | // Imports 2 | import { GraphQLObjectType } from 'graphql' 3 | 4 | // App Imports 5 | import * as thought from './thoughts/fields/mutations' 6 | 7 | // Mutation 8 | const mutation = new GraphQLObjectType({ 9 | name: 'mutations', 10 | description: '...', 11 | 12 | fields: { 13 | ...thought 14 | } 15 | }) 16 | 17 | export default mutation 18 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/components/loading/loading.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-loading', 5 | template: ` 6 |

7 | loading works! 8 |

9 | `, 10 | styles: [] 11 | }) 12 | export class LoadingComponent implements OnInit { 13 | 14 | constructor() { } 15 | 16 | ngOnInit() { 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /api/src/config/database.json: -------------------------------------------------------------------------------- 1 | { 2 | "development": { 3 | "username": "root", 4 | "password": "root", 5 | "database": "graphql", 6 | "host": "localhost", 7 | "dialect": "mysql" 8 | }, 9 | 10 | "production": { 11 | "username": "root", 12 | "password": "root", 13 | "database": "graphql_production", 14 | "host": "localhost", 15 | "dialect": "mysql" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /webapp/src/app/@core/core.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-core', 5 | template: ` 6 |
7 | 8 |
9 | `, 10 | styles: [] 11 | }) 12 | export class CoreComponent implements OnInit { 13 | 14 | constructor() { } 15 | 16 | ngOnInit() { 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /webapp/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | }, 13 | "files": [ 14 | "test.ts" 15 | ], 16 | "include": [ 17 | "**/*.spec.ts", 18 | "**/*.d.ts" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /webapp/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.log(err)); 13 | -------------------------------------------------------------------------------- /webapp/src/app/pages/pages.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-pages', 5 | template: ` 6 |
7 | 8 | 9 |
10 | `, 11 | styles: [] 12 | }) 13 | export class PagesComponent implements OnInit { 14 | 15 | constructor() { } 16 | 17 | ngOnInit() { 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /webapp/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `.angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /webapp/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "sourceMap": true, 6 | "declaration": false, 7 | "moduleResolution": "node", 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "target": "es5", 11 | "typeRoots": [ 12 | "node_modules/@types" 13 | ], 14 | "lib": [ 15 | "es2017", 16 | "dom" 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /api/src/index.ts: -------------------------------------------------------------------------------- 1 | // Imports 2 | import * as express from 'express'; 3 | 4 | // App Imports 5 | import setupLoadModules from './setup/loadModules' 6 | import setupGraphQL from './setup/graphql' 7 | import setupStartServer from './setup/startServer' 8 | 9 | // Create express server 10 | const server = express() 11 | 12 | // Setup load modules 13 | setupLoadModules(server) 14 | 15 | // Setup GraphQL 16 | setupGraphQL(server) 17 | 18 | // Start server 19 | setupStartServer(server) -------------------------------------------------------------------------------- /api/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es5", 5 | "noImplicitThis": true, 6 | "lib": ["es6", "dom", "esnext"], 7 | "alwaysStrict": true, 8 | "noImplicitAny": true, 9 | "strictNullChecks": false, 10 | "experimentalDecorators": true, 11 | "sourceMap": true, 12 | "outDir": "lib", 13 | "jsx": "react", 14 | "typeRoots": ["node_modules/@types"] 15 | }, 16 | "include": ["src/**/*.ts"] 17 | } 18 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/services/thoughts.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { ThoughtsService } from './thoughts.service'; 4 | 5 | describe('ThoughtsService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [ThoughtsService] 9 | }); 10 | }); 11 | 12 | it('should be created', inject([ThoughtsService], (service: ThoughtsService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /webapp/src/app/pages/about/about.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-about', 5 | template: ` 6 |

About

7 |

8 | Donec sed ultrices magna, vel ornare enim. Nunc egestas imperdiet nunc. Nullam ac egestas orci, a efficitur elit. 9 |

10 | `, 11 | styles: [] 12 | }) 13 | export class AboutComponent implements OnInit { 14 | 15 | constructor() { } 16 | 17 | ngOnInit() { 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /api/src/schema/thoughts/fields/query.ts: -------------------------------------------------------------------------------- 1 | // Imports 2 | import { GraphQLInt, GraphQLList } from 'graphql' 3 | 4 | // App Imports 5 | import ThoughtType from '../type' 6 | import { getAll, getById } from '../resolvers' 7 | 8 | // Thoughts All 9 | export const thoughts = { 10 | type: new GraphQLList(ThoughtType), 11 | resolve: getAll 12 | } 13 | 14 | // Thought By ID 15 | export const thought = { 16 | type: ThoughtType, 17 | args: { 18 | id: { type: GraphQLInt } 19 | }, 20 | resolve: getById 21 | } -------------------------------------------------------------------------------- /webapp/src/app/pages/pages.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | 4 | import { SharedModule } from '../@shared/shared.module'; 5 | import { PagesRoutingModule } from './pages.routing'; 6 | import { PagesComponent } from './pages.component'; 7 | 8 | @NgModule({ 9 | imports: [ 10 | CommonModule, 11 | PagesRoutingModule, 12 | SharedModule, 13 | ], 14 | declarations: [ 15 | PagesComponent, 16 | ] 17 | }) 18 | export class PagesModule { } 19 | -------------------------------------------------------------------------------- /webapp/src/app/pages/home/home.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { CommonModule } from '@angular/common'; 4 | import { HomeComponent } from './home.component'; 5 | 6 | const routes: Routes = [ 7 | { 8 | path: '', 9 | component: HomeComponent 10 | } 11 | ]; 12 | 13 | @NgModule({ 14 | imports: [ 15 | CommonModule, 16 | RouterModule.forChild(routes) 17 | ], 18 | declarations: [HomeComponent] 19 | }) 20 | export class HomeModule { } 21 | -------------------------------------------------------------------------------- /api/src/schema/thoughts/type.ts: -------------------------------------------------------------------------------- 1 | // Imports 2 | import { GraphQLObjectType, GraphQLString, GraphQLInt } from 'graphql' 3 | 4 | // Thought type 5 | const ThoughtType = new GraphQLObjectType({ 6 | name: 'thought', 7 | description: '...', 8 | 9 | fields: () => ({ 10 | id: { type: GraphQLInt }, 11 | name: { type: GraphQLString }, 12 | thought: { type: GraphQLString }, 13 | createdAt: { type: GraphQLString }, 14 | updatedAt: { type: GraphQLString } 15 | }) 16 | }) 17 | 18 | export default ThoughtType -------------------------------------------------------------------------------- /webapp/src/app/pages/about/about.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { CommonModule } from '@angular/common'; 4 | import { AboutComponent } from './about.component'; 5 | 6 | const routes: Routes = [ 7 | { 8 | path: '', 9 | component: AboutComponent 10 | } 11 | ]; 12 | 13 | @NgModule({ 14 | imports: [ 15 | CommonModule, 16 | RouterModule.forChild(routes) 17 | ], 18 | declarations: [AboutComponent] 19 | }) 20 | export class AboutModule { } 21 | -------------------------------------------------------------------------------- /webapp/src/app/pages/thoughts/view/view.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { CommonModule } from '@angular/common'; 4 | import { ViewComponent } from './view.component'; 5 | 6 | const routes: Routes = [ 7 | { 8 | path: '', 9 | component: ViewComponent 10 | } 11 | ]; 12 | 13 | @NgModule({ 14 | imports: [ 15 | CommonModule, 16 | RouterModule.forChild(routes) 17 | ], 18 | declarations: [ViewComponent] 19 | }) 20 | export class ViewModule { } 21 | -------------------------------------------------------------------------------- /webapp/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { HttpClientModule } from '@angular/common/http'; 3 | import { NgModule } from '@angular/core'; 4 | 5 | 6 | import { CoreModule } from './@core/core.module'; 7 | import { CoreComponent } from './@core/core.component'; 8 | 9 | @NgModule({ 10 | declarations: [], 11 | imports: [ 12 | HttpClientModule, 13 | BrowserModule, 14 | CoreModule, 15 | ], 16 | providers: [], 17 | bootstrap: [CoreComponent] 18 | }) 19 | export class AppModule { } 20 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | graphql-schema-decorator@^0.8.0: 6 | version "0.8.0" 7 | resolved "https://registry.yarnpkg.com/graphql-schema-decorator/-/graphql-schema-decorator-0.8.0.tgz#6d4034801c8f470b898e96ba0a2db053d69bacd3" 8 | dependencies: 9 | reflect-metadata "0.1.9" 10 | 11 | reflect-metadata@0.1.9: 12 | version "0.1.9" 13 | resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.9.tgz#987238dc87a516895fe457f130435ffbd763a4d4" 14 | -------------------------------------------------------------------------------- /webapp/src/app/@core/core.routing.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule, ExtraOptions } from '@angular/router'; 3 | 4 | export const CORE_ROUTES: Routes = [ 5 | { 6 | path: '', 7 | redirectTo: '/', pathMatch: 'full' 8 | }, 9 | { 10 | path: '**', 11 | redirectTo: '/', pathMatch: 'full' 12 | } 13 | ]; 14 | 15 | const config: ExtraOptions = { 16 | useHash: true, 17 | }; 18 | 19 | @NgModule({ 20 | imports: [RouterModule.forRoot(CORE_ROUTES, config)], 21 | exports: [RouterModule] 22 | }) 23 | export class CoreRoutingModule {} 24 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/components/menu/menu.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-menu', 5 | template: ` 6 | 11 | `, 12 | styles: [] 13 | }) 14 | export class MenuComponent implements OnInit { 15 | 16 | constructor() { } 17 | 18 | ngOnInit() { 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /api/src/setup/graphql.ts: -------------------------------------------------------------------------------- 1 | // Imports 2 | import * as graphqlHTTP from 'express-graphql' 3 | import { Express } from 'express'; 4 | 5 | // App Imports 6 | const config = require('../config/config.json'); 7 | import schema from '../schema'; 8 | 9 | // Setup GraphQL 10 | export default function setupGraphQL(server: Express): void { 11 | console.info('SETUP - GraphQL...') 12 | 13 | // API (GraphQL on route `/api`) 14 | server.use(config.graphqlEndpoint, graphqlHTTP(() => ({ 15 | schema, 16 | graphiql: config.graphql.ide, 17 | pretty: config.graphql.pretty 18 | }))) 19 | } -------------------------------------------------------------------------------- /webapp/src/app/pages/thoughts/list/list.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { CommonModule } from '@angular/common'; 4 | import { ListComponent } from './list.component'; 5 | import { ItemComponent } from './item.component'; 6 | 7 | const routes: Routes = [ 8 | { 9 | path: '', 10 | component: ListComponent 11 | } 12 | ]; 13 | 14 | @NgModule({ 15 | imports: [ 16 | CommonModule, 17 | RouterModule.forChild(routes) 18 | ], 19 | declarations: [ListComponent, ItemComponent] 20 | }) 21 | export class ListModule { } 22 | -------------------------------------------------------------------------------- /webapp/src/app/pages/thoughts/create/create.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { ReactiveFormsModule } from '@angular/forms'; 3 | import { RouterModule, Routes } from '@angular/router'; 4 | import { CommonModule } from '@angular/common'; 5 | import { CreateComponent } from './create.component'; 6 | 7 | const routes: Routes = [ 8 | { 9 | path: '', 10 | component: CreateComponent 11 | } 12 | ]; 13 | 14 | @NgModule({ 15 | imports: [ 16 | CommonModule, 17 | ReactiveFormsModule, 18 | RouterModule.forChild(routes) 19 | ], 20 | declarations: [CreateComponent] 21 | }) 22 | export class CreateModule { } 23 | -------------------------------------------------------------------------------- /webapp/src/app/pages/thoughts/list/item.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, Output, EventEmitter } from '@angular/core'; 2 | import { Thought } from '../../../@shared/models/thought.model'; 3 | 4 | @Component({ 5 | selector: 'app-item', 6 | template: ` 7 |
8 | {{ thought.thought }} - {{ thought.name }} 9 |    10 | 11 |   12 | 13 |
14 | `, 15 | styles: [] 16 | }) 17 | export class ItemComponent { 18 | @Input() thought: Thought; 19 | @Output() onDelete: EventEmitter = new EventEmitter(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /api/src/setup/loadModules.ts: -------------------------------------------------------------------------------- 1 | // Imports 2 | import * as cors from 'cors' 3 | import { Express } from 'express'; 4 | import * as bodyParser from 'body-parser' 5 | import * as cookieParser from 'cookie-parser' 6 | import * as morgan from 'morgan' 7 | 8 | // Load express modules 9 | export default function(server: Express): void { 10 | console.info('SETUP - Loading modules...') 11 | 12 | // Enable CORS 13 | server.use(cors()) 14 | 15 | // Request body parser 16 | server.use(bodyParser.json()) 17 | server.use(bodyParser.urlencoded({extended: false})) 18 | 19 | // Request body cookie parser 20 | server.use(cookieParser()) 21 | 22 | // HTTP logger 23 | server.use(morgan('tiny')) 24 | } -------------------------------------------------------------------------------- /webapp/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | testem.log 34 | /typings 35 | 36 | # e2e 37 | /e2e/*.js 38 | /e2e/*.map 39 | 40 | # System Files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /webapp/src/app/pages/home/home.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { HomeComponent } from './home.component'; 4 | 5 | describe('HomeComponent', () => { 6 | let component: HomeComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ HomeComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(HomeComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /api/src/schema/thoughts/resolvers.ts: -------------------------------------------------------------------------------- 1 | // App Imports 2 | import models from '../../models'; 3 | 4 | // Get thoughts by ID 5 | export async function getById(parentValue: any, args: any) { 6 | return await models.Thought.findOne({ where: { id: args.id }}) 7 | } 8 | 9 | // Get all thoughts 10 | export async function getAll() { 11 | return await models.Thought.findAll() 12 | } 13 | 14 | // Create thought 15 | export async function create(parentValue: any, args: any) { 16 | return await models.Thought.create({ 17 | name: args.name, 18 | thought: args.thought 19 | }) 20 | } 21 | 22 | // Delete thought 23 | export async function remove(parentValue: any, args: any) { 24 | return await models.Thought.destroy({ where: { id: args.id }}) 25 | } -------------------------------------------------------------------------------- /webapp/src/app/pages/about/about.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AboutComponent } from './about.component'; 4 | 5 | describe('AboutComponent', () => { 6 | let component: AboutComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AboutComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AboutComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /webapp/src/app/pages/thoughts/list/item.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ItemComponent } from './item.component'; 4 | 5 | describe('ItemComponent', () => { 6 | let component: ItemComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ItemComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ItemComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /webapp/src/app/pages/thoughts/list/list.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ListComponent } from './list.component'; 4 | 5 | describe('ListComponent', () => { 6 | let component: ListComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ListComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ListComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /webapp/src/app/pages/thoughts/view/view.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ViewComponent } from './view.component'; 4 | 5 | describe('ViewComponent', () => { 6 | let component: ViewComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ViewComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ViewComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/components/menu/menu.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { MenuComponent } from './menu.component'; 4 | 5 | describe('MenuComponent', () => { 6 | let component: MenuComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ MenuComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(MenuComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /webapp/src/app/pages/thoughts/create/create.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { CreateComponent } from './create.component'; 4 | 5 | describe('CreateComponent', () => { 6 | let component: CreateComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ CreateComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(CreateComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/components/loading/loading.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LoadingComponent } from './loading.component'; 4 | 5 | describe('LoadingComponent', () => { 6 | let component: LoadingComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LoadingComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LoadingComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /api/src/schema/thoughts/fields/mutations.ts: -------------------------------------------------------------------------------- 1 | // Imports 2 | import { GraphQLString, GraphQLInt } from 'graphql' 3 | 4 | // App Imports 5 | import ThoughtType from '../type' 6 | import { create, remove } from '../resolvers' 7 | 8 | // Thought create 9 | export const thoughtCreate = { 10 | type: ThoughtType, 11 | args: { 12 | name: { 13 | name: 'name', 14 | type: GraphQLString 15 | }, 16 | 17 | thought: { 18 | name: 'thought', 19 | type: GraphQLString 20 | } 21 | }, 22 | resolve: create 23 | } 24 | 25 | // Thought remove 26 | export const thoughtRemove = { 27 | type: ThoughtType, 28 | args: { 29 | id: { 30 | name: 'id', 31 | type: GraphQLInt 32 | } 33 | }, 34 | resolve: remove 35 | } -------------------------------------------------------------------------------- /webapp/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './e2e/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: 'e2e/tsconfig.e2e.json' 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /api/.gitignore: -------------------------------------------------------------------------------- 1 | ### Node ### 2 | # Logs 3 | logs 4 | *.log 5 | npm-debug.log* 6 | 7 | # Runtime data 8 | pids 9 | *.pid 10 | *.seed 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # nyc test coverage 19 | .nyc_output 20 | 21 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 22 | .grunt 23 | 24 | # node-waf configuration 25 | .lock-wscript 26 | 27 | # Compiled binary addons (http://nodejs.org/api/addons.html) 28 | build/Release 29 | 30 | # Dependency directories 31 | node_modules 32 | jspm_packages 33 | 34 | # Optional npm cache directory 35 | .npm 36 | 37 | # Optional REPL history 38 | .node_repl_history 39 | 40 | 41 | ### VisualStudioCode ### 42 | .vscode 43 | 44 | ### Webstorm ### 45 | .idea 46 | 47 | # App 48 | lib 49 | temp -------------------------------------------------------------------------------- /webapp/src/app/@shared/shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule, ModuleWithProviders } from '@angular/core'; 2 | import { RouterModule } from '@angular/router'; 3 | import { CommonModule } from '@angular/common'; 4 | 5 | import { ThoughtsService } from './services/thoughts.service'; 6 | 7 | import { MenuComponent } from './components/menu/menu.component'; 8 | import { LoadingComponent } from './components/loading/loading.component'; 9 | 10 | @NgModule({ 11 | imports: [ 12 | CommonModule, 13 | RouterModule, 14 | ], 15 | declarations: [ 16 | MenuComponent, 17 | LoadingComponent, 18 | ], 19 | exports: [ 20 | MenuComponent, 21 | LoadingComponent, 22 | ] 23 | }) 24 | export class SharedModule { 25 | static forRoot(): ModuleWithProviders { 26 | return { 27 | ngModule: SharedModule, 28 | providers: [ 29 | ThoughtsService, 30 | ] 31 | }; 32 | }} 33 | -------------------------------------------------------------------------------- /webapp/src/app/pages/pages.routing.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { PagesComponent } from './pages.component'; 4 | 5 | export const PAGES_ROUTES: Routes = [ 6 | { 7 | path: '', 8 | component: PagesComponent, 9 | children: [ 10 | { path: '', loadChildren: './home/home.module#HomeModule' }, 11 | { path: 'about', loadChildren: './about/about.module#AboutModule' }, 12 | { path: 'thoughts', loadChildren: './thoughts/list/list.module#ListModule' }, 13 | { path: 'thoughts/create', loadChildren: './thoughts/create/create.module#CreateModule' }, 14 | { path: 'thoughts/:id', loadChildren: './thoughts/view/view.module#ViewModule' }, 15 | ] 16 | }, 17 | ]; 18 | 19 | @NgModule({ 20 | imports: [RouterModule.forChild(PAGES_ROUTES)], 21 | exports: [RouterModule] 22 | }) 23 | export class PagesRoutingModule {} 24 | -------------------------------------------------------------------------------- /api/src/setup/databaseConnection.ts: -------------------------------------------------------------------------------- 1 | // Imports 2 | const Sequelize = require('sequelize'); 3 | 4 | // App Imports 5 | import env from '../config/env' 6 | const databaseConfig = require('../config/database.json'); 7 | 8 | // Load database config 9 | const databaseConfigEnv = databaseConfig[env] 10 | 11 | // Create new database connection 12 | const connection = new Sequelize(databaseConfigEnv.database, databaseConfigEnv.username, databaseConfigEnv.password, { 13 | host: databaseConfigEnv.host, 14 | dialect: databaseConfigEnv.dialect, 15 | logging: false, 16 | operatorsAliases: Sequelize.Op 17 | }) 18 | 19 | // Test connection 20 | console.info('SETUP - Connecting database...') 21 | 22 | connection 23 | .authenticate() 24 | .then(() => { 25 | console.info('INFO - Database connected.') 26 | }) 27 | .catch((err: any) => { 28 | console.error('ERROR - Unable to connect to the database:', err) 29 | }) 30 | 31 | export default connection -------------------------------------------------------------------------------- /webapp/src/app/@shared/store/actions/create.action.ts: -------------------------------------------------------------------------------- 1 | import { Action } from '@ngrx/store'; 2 | 3 | import { type } from '../../utils/helpers'; 4 | import { Thought } from '../../models/thought.model'; 5 | 6 | export const ActionTypes = { 7 | LOAD: type('[Create] Load'), 8 | LOAD_SUCCESS: type('[Create] Load Success'), 9 | LOAD_FAIL: type('[Create] Load Fail'), 10 | }; 11 | 12 | /** 13 | * Create Actions 14 | */ 15 | export class LoadAction implements Action { 16 | type = ActionTypes.LOAD; 17 | 18 | constructor(public payload: Thought) { } 19 | } 20 | 21 | export class LoadSuccessAction implements Action { 22 | type = ActionTypes.LOAD_SUCCESS; 23 | 24 | constructor(public payload: any = null) { } 25 | } 26 | 27 | export class LoadFailAction implements Action { 28 | type = ActionTypes.LOAD_FAIL; 29 | 30 | constructor(public payload: any = null) { } 31 | } 32 | 33 | export type Actions 34 | = LoadAction 35 | | LoadSuccessAction 36 | | LoadFailAction; 37 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/store/actions/remove.action.ts: -------------------------------------------------------------------------------- 1 | import { Action } from '@ngrx/store'; 2 | 3 | import { type } from '../../utils/helpers'; 4 | import { Thought } from '../../models/thought.model'; 5 | 6 | export const ActionTypes = { 7 | LOAD: type('[Remove] Load'), 8 | LOAD_SUCCESS: type('[Remove] Load Success'), 9 | LOAD_FAIL: type('[Remove] Load Fail'), 10 | }; 11 | 12 | /** 13 | * Remove Actions 14 | */ 15 | export class LoadAction implements Action { 16 | type = ActionTypes.LOAD; 17 | 18 | constructor(public payload: Thought) { } 19 | } 20 | 21 | export class LoadSuccessAction implements Action { 22 | type = ActionTypes.LOAD_SUCCESS; 23 | 24 | constructor(public payload: any = null) { } 25 | } 26 | 27 | export class LoadFailAction implements Action { 28 | type = ActionTypes.LOAD_FAIL; 29 | 30 | constructor(public payload: any = null) { } 31 | } 32 | 33 | export type Actions 34 | = LoadAction 35 | | LoadSuccessAction 36 | | LoadFailAction; 37 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/store/actions/thoughts.action.ts: -------------------------------------------------------------------------------- 1 | import { Action } from '@ngrx/store'; 2 | 3 | import { Thought } from '../../models/thought.model'; 4 | import { type } from '../../utils/helpers'; 5 | 6 | export const ActionTypes = { 7 | LOAD: type('[Thoughts] Load'), 8 | LOAD_SUCCESS: type('[Thoughts] Load Success'), 9 | LOAD_FAIL: type('[Thoughts] Load Fail'), 10 | }; 11 | 12 | /** 13 | * Thoughts Actions 14 | */ 15 | export class LoadAction implements Action { 16 | type = ActionTypes.LOAD; 17 | 18 | constructor(public payload: any = null) { } 19 | } 20 | 21 | export class LoadSuccessAction implements Action { 22 | type = ActionTypes.LOAD_SUCCESS; 23 | 24 | constructor(public payload: Array) { } 25 | } 26 | 27 | export class LoadFailAction implements Action { 28 | type = ActionTypes.LOAD_FAIL; 29 | 30 | constructor(public payload: any = null) { } 31 | } 32 | 33 | export type Actions 34 | = LoadAction 35 | | LoadSuccessAction 36 | | LoadFailAction; 37 | -------------------------------------------------------------------------------- /webapp/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular/cli'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular/cli/plugins/karma') 14 | ], 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | reports: [ 'html', 'lcovonly' ], 20 | fixWebpackSourcePaths: true 21 | }, 22 | angularCli: { 23 | environment: 'dev' 24 | }, 25 | reporters: ['progress', 'kjhtml'], 26 | port: 9876, 27 | colors: true, 28 | logLevel: config.LOG_INFO, 29 | autoWatch: true, 30 | browsers: ['Chrome'], 31 | singleRun: false 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /api/src/setup/startServer.ts: -------------------------------------------------------------------------------- 1 | // App Imports 2 | import { Express } from 'express'; 3 | import databaseConnection from '../setup/databaseConnection'; 4 | const config = require('../config/config.json'); 5 | 6 | // Sync database tables and start server 7 | export default function(server: Express): void { 8 | console.info('SETUP - Syncing database tables...') 9 | 10 | // Create tables 11 | databaseConnection.sync({}) 12 | .then(() => { 13 | console.info('INFO - Database sync complete.') 14 | 15 | console.info('SETUP - Starting server...') 16 | 17 | // Start web server 18 | server.listen(config.port, (error: any) => { 19 | if(error) { 20 | console.error('ERROR - Unable to start server.') 21 | } else { 22 | console.info(`INFO - Server started on port ${ config.port }.`) 23 | } 24 | }) 25 | }) 26 | .catch(() => { 27 | console.error('ERROR - Unable to sync database.') 28 | console.error('ERROR - Server not started.') 29 | }) 30 | } -------------------------------------------------------------------------------- /webapp/README.md: -------------------------------------------------------------------------------- 1 | # Webapp 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.5.0. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Rafael Escala 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/store/reducers/create.reducer.ts: -------------------------------------------------------------------------------- 1 | import * as actions from '../actions/create.action'; 2 | 3 | export interface State { 4 | loading: boolean; 5 | failed: boolean; 6 | } 7 | 8 | const INITIAL_STATE: State = { 9 | loading: false, 10 | failed: false, 11 | }; 12 | 13 | export function reducer(state = INITIAL_STATE, action: actions.Actions): State { 14 | if (!action) { 15 | return state; 16 | } 17 | 18 | switch (action.type) { 19 | case actions.ActionTypes.LOAD: { 20 | return Object.assign({}, state, { 21 | loading: true 22 | }); 23 | } 24 | 25 | case actions.ActionTypes.LOAD_SUCCESS: { 26 | return Object.assign({}, state, { 27 | loading: false, 28 | failed: false, 29 | }); 30 | } 31 | 32 | case actions.ActionTypes.LOAD_FAIL: { 33 | return Object.assign({}, state, { 34 | loading: false, 35 | failed: true, 36 | }); 37 | } 38 | 39 | default: { 40 | return state; 41 | } 42 | } 43 | } 44 | 45 | export const getLoading = (state: State) => state.loading; 46 | export const getFailed = (state: State) => state.failed; 47 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/store/reducers/remove.reducer.ts: -------------------------------------------------------------------------------- 1 | import * as actions from '../actions/remove.action'; 2 | 3 | export interface State { 4 | loading: boolean; 5 | failed: boolean; 6 | } 7 | 8 | const INITIAL_STATE: State = { 9 | loading: false, 10 | failed: false, 11 | }; 12 | 13 | export function reducer(state = INITIAL_STATE, action: actions.Actions): State { 14 | if (!action) { 15 | return state; 16 | } 17 | 18 | switch (action.type) { 19 | case actions.ActionTypes.LOAD: { 20 | return Object.assign({}, state, { 21 | loading: true 22 | }); 23 | } 24 | 25 | case actions.ActionTypes.LOAD_SUCCESS: { 26 | return Object.assign({}, state, { 27 | loading: false, 28 | failed: false, 29 | }); 30 | } 31 | 32 | case actions.ActionTypes.LOAD_FAIL: { 33 | return Object.assign({}, state, { 34 | loading: false, 35 | failed: true, 36 | }); 37 | } 38 | 39 | default: { 40 | return state; 41 | } 42 | } 43 | } 44 | 45 | export const getLoading = (state: State) => state.loading; 46 | export const getFailed = (state: State) => state.failed; 47 | -------------------------------------------------------------------------------- /webapp/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | import { getTestBed } from '@angular/core/testing'; 10 | import { 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting 13 | } from '@angular/platform-browser-dynamic/testing'; 14 | 15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 16 | declare const __karma__: any; 17 | declare const require: any; 18 | 19 | // Prevent Karma from running prematurely. 20 | __karma__.loaded = function () {}; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting() 26 | ); 27 | // Then we find all the tests. 28 | const context = require.context('./', true, /\.spec\.ts$/); 29 | // And load the modules. 30 | context.keys().map(context); 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/store/actions/thought-details.action.ts: -------------------------------------------------------------------------------- 1 | import { Action } from '@ngrx/store'; 2 | 3 | import { Thought } from '../../models/thought.model'; 4 | import { type } from '../../utils/helpers'; 5 | 6 | export const ActionTypes = { 7 | LOAD: type('[Thoughts Details] Load'), 8 | LOAD_SUCCESS: type('[Thoughts Details] Load Success'), 9 | LOAD_FAIL: type('[Thoughts Details] Load Fail'), 10 | RESET: type('[Thoughts Details] Reset'), 11 | }; 12 | 13 | /** 14 | * Thoughts Details Actions 15 | */ 16 | export class LoadAction implements Action { 17 | type = ActionTypes.LOAD; 18 | 19 | constructor(public payload: Number) { } 20 | } 21 | 22 | export class LoadSuccessAction implements Action { 23 | type = ActionTypes.LOAD_SUCCESS; 24 | 25 | constructor(public payload: Thought) { } 26 | } 27 | 28 | export class LoadFailAction implements Action { 29 | type = ActionTypes.LOAD_FAIL; 30 | 31 | constructor(public payload: any = null) { } 32 | } 33 | 34 | export class ResetAction implements Action { 35 | type = ActionTypes.LOAD_FAIL; 36 | 37 | constructor(public payload: any = null) { } 38 | } 39 | 40 | export type Actions 41 | = LoadAction 42 | | LoadSuccessAction 43 | | LoadFailAction 44 | | ResetAction; 45 | -------------------------------------------------------------------------------- /webapp/src/app/@core/core.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { StoreModule, compose } from '@ngrx/store'; 4 | import { EffectsModule } from '@ngrx/effects'; 5 | import { StoreDevtoolsModule } from '@ngrx/store-devtools'; 6 | 7 | // Operators 8 | import './operators'; 9 | 10 | // Modules 11 | import { CoreRoutingModule } from './core.routing'; 12 | import { PagesModule } from '../pages/pages.module'; 13 | import { SharedModule } from '../@shared/shared.module'; 14 | 15 | // Store 16 | import { reducers } from '../@shared/store'; 17 | 18 | // Effects 19 | import { ThoughtsEffects } from '../@shared/store/effects/thoughts.effect'; 20 | 21 | // Enviroment 22 | import { environment } from '../../environments/environment'; 23 | 24 | import { CoreComponent } from './core.component'; 25 | 26 | @NgModule({ 27 | imports: [ 28 | CommonModule, 29 | StoreModule.forRoot(reducers), 30 | !environment.production ? StoreDevtoolsModule.instrument() : [], 31 | EffectsModule.forRoot([ 32 | ThoughtsEffects, 33 | ]), 34 | PagesModule, 35 | CoreRoutingModule, 36 | SharedModule.forRoot(), 37 | ], 38 | declarations: [ 39 | CoreComponent 40 | ], 41 | exports: [ 42 | CoreComponent 43 | ], 44 | }) 45 | export class CoreModule { } 46 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/store/reducers/thoughts.reducer.ts: -------------------------------------------------------------------------------- 1 | import { Thought } from '../../models/thought.model'; 2 | import * as actions from '../actions/thoughts.action'; 3 | 4 | export interface State { 5 | loading: boolean; 6 | failed: boolean; 7 | data: Array; 8 | } 9 | 10 | const INITIAL_STATE: State = { 11 | loading: false, 12 | failed: false, 13 | data: [] 14 | }; 15 | 16 | export function reducer(state = INITIAL_STATE, action: actions.Actions): State { 17 | if (!action) { 18 | return state; 19 | } 20 | 21 | switch (action.type) { 22 | case actions.ActionTypes.LOAD: { 23 | return Object.assign({}, state, { 24 | loading: true 25 | }); 26 | } 27 | 28 | case actions.ActionTypes.LOAD_SUCCESS: { 29 | return Object.assign({}, state, { 30 | loading: false, 31 | failed: false, 32 | data: action.payload 33 | }); 34 | } 35 | 36 | case actions.ActionTypes.LOAD_FAIL: { 37 | return Object.assign({}, state, { 38 | loading: false, 39 | failed: true, 40 | data: [] 41 | }); 42 | } 43 | 44 | default: { 45 | return state; 46 | } 47 | } 48 | } 49 | 50 | export const getData = (state: State) => state.data; 51 | export const getLoading = (state: State) => state.loading; 52 | export const getFailed = (state: State) => state.failed; 53 | -------------------------------------------------------------------------------- /webapp/src/app/pages/thoughts/view/view.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; 2 | import { Router, ActivatedRoute } from '@angular/router'; 3 | import { Store } from '@ngrx/store'; 4 | import * as store from '../../../@shared/store'; 5 | import * as thoughtDetailsActions from '../../../@shared/store/actions/thought-details.action'; 6 | import { Thought } from '../../../@shared/models/thought.model'; 7 | 8 | @Component({ 9 | selector: 'app-view', 10 | template: ` 11 |

Thought

12 |

13 | Back 14 |

15 |
16 |

"{{ thought.thought }}"

17 |

- {{ thought.name }}

18 |
19 | `, 20 | styles: [] 21 | }) 22 | export class ViewComponent implements OnInit, OnDestroy { 23 | 24 | private thought = new Thought(); 25 | private thoughtDetails$ = this.appState$.select(store.getDetails); 26 | 27 | constructor( 28 | private activeRouter: ActivatedRoute, 29 | protected appState$: Store 30 | ) { } 31 | 32 | ngOnInit() { 33 | this.activeRouter.params.subscribe(params => { 34 | this.appState$.dispatch(new thoughtDetailsActions.LoadAction(parseInt(params.id, 10))); 35 | }); 36 | this.thoughtDetails$.subscribe(thought => { 37 | this.thought = thought; 38 | }); 39 | } 40 | 41 | ngOnDestroy() { 42 | this.appState$.dispatch(new thoughtDetailsActions.ResetAction()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/store/reducers/thought-details.reducer.ts: -------------------------------------------------------------------------------- 1 | import { Thought } from '../../models/thought.model'; 2 | import * as actions from '../actions/thought-details.action'; 3 | 4 | export interface State { 5 | loading: boolean; 6 | failed: boolean; 7 | data: Thought; 8 | } 9 | 10 | const INITIAL_STATE: State = { 11 | loading: false, 12 | failed: false, 13 | data: new Thought() 14 | }; 15 | 16 | export function reducer(state = INITIAL_STATE, action: actions.Actions): State { 17 | if (!action) { 18 | return state; 19 | } 20 | 21 | switch (action.type) { 22 | case actions.ActionTypes.LOAD: { 23 | return Object.assign({}, state, { 24 | loading: true 25 | }); 26 | } 27 | 28 | case actions.ActionTypes.LOAD_SUCCESS: { 29 | return Object.assign({}, state, { 30 | loading: false, 31 | failed: false, 32 | data: action.payload 33 | }); 34 | } 35 | 36 | case actions.ActionTypes.LOAD_FAIL: { 37 | return Object.assign({}, state, { 38 | loading: false, 39 | failed: true, 40 | data: [] 41 | }); 42 | } 43 | 44 | case actions.ActionTypes.RESET: { 45 | return Object.assign({}, INITIAL_STATE); 46 | } 47 | 48 | default: { 49 | return state; 50 | } 51 | } 52 | } 53 | 54 | export const getData = (state: State) => state.data; 55 | export const getLoading = (state: State) => state.loading; 56 | export const getFailed = (state: State) => state.failed; 57 | -------------------------------------------------------------------------------- /webapp/.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "webapp" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "polyfills": "polyfills.ts", 17 | "test": "test.ts", 18 | "tsconfig": "tsconfig.app.json", 19 | "testTsconfig": "tsconfig.spec.json", 20 | "prefix": "app", 21 | "styles": [ 22 | "styles.css" 23 | ], 24 | "scripts": [], 25 | "environmentSource": "environments/environment.ts", 26 | "environments": { 27 | "dev": "environments/environment.ts", 28 | "prod": "environments/environment.prod.ts" 29 | } 30 | } 31 | ], 32 | "e2e": { 33 | "protractor": { 34 | "config": "./protractor.conf.js" 35 | } 36 | }, 37 | "lint": [ 38 | { 39 | "project": "src/tsconfig.app.json", 40 | "exclude": "**/node_modules/**" 41 | }, 42 | { 43 | "project": "src/tsconfig.spec.json", 44 | "exclude": "**/node_modules/**" 45 | }, 46 | { 47 | "project": "e2e/tsconfig.e2e.json", 48 | "exclude": "**/node_modules/**" 49 | } 50 | ], 51 | "test": { 52 | "karma": { 53 | "config": "./karma.conf.js" 54 | } 55 | }, 56 | "defaults": { 57 | "styleExt": "css", 58 | "component": {} 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /webapp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webapp", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/animations": "^5.0.0", 16 | "@angular/common": "^5.0.0", 17 | "@angular/compiler": "^5.0.0", 18 | "@angular/core": "^5.0.0", 19 | "@angular/forms": "^5.0.0", 20 | "@angular/http": "^5.0.0", 21 | "@angular/platform-browser": "^5.0.0", 22 | "@angular/platform-browser-dynamic": "^5.0.0", 23 | "@angular/router": "^5.0.0", 24 | "@ngrx/effects": "^4.1.0", 25 | "@ngrx/store": "^4.1.0", 26 | "@ngrx/store-devtools": "^4.0.0", 27 | "core-js": "^2.4.1", 28 | "reselect": "^3.0.1", 29 | "rxjs": "^5.5.2", 30 | "zone.js": "^0.8.14" 31 | }, 32 | "devDependencies": { 33 | "@angular/cli": "1.5.0", 34 | "@angular/compiler-cli": "^5.0.0", 35 | "@angular/language-service": "^5.0.0", 36 | "@types/jasmine": "~2.5.53", 37 | "@types/jasminewd2": "~2.0.2", 38 | "@types/node": "~6.0.60", 39 | "codelyzer": "~3.2.0", 40 | "jasmine-core": "~2.6.2", 41 | "jasmine-spec-reporter": "~4.1.0", 42 | "karma": "~1.7.0", 43 | "karma-chrome-launcher": "~2.1.1", 44 | "karma-cli": "~1.0.1", 45 | "karma-coverage-istanbul-reporter": "^1.2.1", 46 | "karma-jasmine": "~1.1.0", 47 | "karma-jasmine-html-reporter": "^0.2.2", 48 | "protractor": "~5.1.2", 49 | "ts-node": "~3.2.0", 50 | "tslint": "~5.7.0", 51 | "typescript": "~2.4.2" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/services/thoughts.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | 4 | import { queryBuilder } from '../utils/helpers'; 5 | import { Thought } from '../models/thought.model'; 6 | 7 | const GRAPHQL_API = 'http://localhost:3000'; 8 | 9 | @Injectable() 10 | export class ThoughtsService { 11 | constructor(private http: HttpClient) {} 12 | 13 | public getList() { 14 | return this.http 15 | .post( 16 | GRAPHQL_API, 17 | queryBuilder({ 18 | type: 'query', 19 | operation: 'thoughts', 20 | fields: ['id', 'name', 'thought'] 21 | }) 22 | ) 23 | .map((res: any) => res.data.thoughts); 24 | } 25 | 26 | public get(id: Number) { 27 | return this.http 28 | .post( 29 | GRAPHQL_API, 30 | queryBuilder({ 31 | type: 'query', 32 | operation: 'thought', 33 | data: { id }, 34 | fields: ['id', 'name', 'thought'] 35 | }) 36 | ) 37 | .map((res: any) => res.data.thought); 38 | } 39 | 40 | public create(data: Thought) { 41 | return this.http 42 | .post( 43 | GRAPHQL_API, 44 | queryBuilder({ 45 | type: 'mutation', 46 | operation: 'thoughtCreate', 47 | data, 48 | fields: ['id'] 49 | }) 50 | ) 51 | .map((res: any) => res.data.thoughts); 52 | } 53 | 54 | public remove(data: Thought) { 55 | return this.http 56 | .post( 57 | GRAPHQL_API, 58 | queryBuilder({ 59 | type: 'mutation', 60 | operation: 'thoughtRemove', 61 | data: { id: data.id }, 62 | fields: ['id'] 63 | }) 64 | ) 65 | .map((res: any) => res.data.thoughts); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /webapp/src/app/pages/thoughts/list/list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Store } from '@ngrx/store'; 3 | import find from 'lodash/find'; 4 | import * as store from '../../../@shared/store'; 5 | import * as thoughtsActions from '../../../@shared/store/actions/thoughts.action'; 6 | import * as removeActions from '../../../@shared/store/actions/remove.action'; 7 | import { Thought } from '../../../@shared/models/thought.model'; 8 | 9 | @Component({ 10 | selector: 'app-list', 11 | template: ` 12 |

Thoughts

13 |

14 | Create 15 |

16 |
    17 |
  • 18 | 19 |
  • 20 |
21 | `, 22 | styles: [] 23 | }) 24 | export class ListComponent implements OnInit { 25 | 26 | public thoughts: Array; 27 | private thoughts$ = this.appState$.select(store.getThoughts); 28 | private removeState$ = this.appState$.select(store.getRemoveState); 29 | 30 | private removeLoaded$; 31 | 32 | constructor(protected appState$: Store) { 33 | appState$.dispatch(new thoughtsActions.LoadAction()); 34 | } 35 | 36 | ngOnInit() { 37 | this.thoughts$.subscribe(thoughts => { 38 | this.thoughts = thoughts; 39 | }); 40 | } 41 | 42 | handleOnDelete(id) { 43 | const check = window.confirm('Are you sure you want to delete this thought?'); 44 | if (check) { 45 | const thought = find(this.thoughts, {id}); 46 | this.appState$.dispatch(new removeActions.LoadAction(thought)); 47 | this.subscribeToRemoveChanges(); 48 | } 49 | } 50 | 51 | private subscribeToRemoveChanges() { 52 | if (this.removeLoaded$) { 53 | return; 54 | } 55 | 56 | this.removeLoaded$ = this.removeState$.subscribe(state => { 57 | if (!state.loading) { 58 | this.appState$.dispatch(new thoughtsActions.LoadAction()); 59 | } 60 | }); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /api/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "api", 3 | "version": "0.0.0", 4 | "description": "", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "build": "tsc && npm run copy", 9 | "build:watch": "tsc -w && npm run copy", 10 | "release": "npm-run-all -s clean build", 11 | "clean": "rimraf ./lib", 12 | "copy": "gulp copy", 13 | "start": "nodemon lib/index.js --exec babel-node --presets es2015,stage-2" 14 | }, 15 | "author": "", 16 | "license": "MIT", 17 | "devDependencies": { 18 | "@types/body-parser": "^1.16.7", 19 | "@types/chai": "^4.0.4", 20 | "@types/cookie-parser": "^1.4.1", 21 | "@types/cors": "^2.8.1", 22 | "@types/express": "^4.0.39", 23 | "@types/express-graphql": "^0.0.35", 24 | "@types/graphql": "^0.11.5", 25 | "@types/jsonwebtoken": "^7.2.3", 26 | "@types/mocha": "^2.2.44", 27 | "@types/morgan": "^1.7.35", 28 | "@types/node": "^8.0.47", 29 | "@types/sequelize": "^4.0.78", 30 | "@types/source-map-support": "^0.4.0", 31 | "babel-cli": "^6.26.0", 32 | "babel-preset-es2015": "^6.24.1", 33 | "babel-preset-stage-2": "^6.24.1", 34 | "chai": "^4.1.2", 35 | "cross-env": "^5.1.1", 36 | "gulp": "^3.9.1", 37 | "mocha": "^4.0.1", 38 | "ncp": "^2.0.0", 39 | "nodemon": "^1.12.1", 40 | "npm-run-all": "^4.1.1", 41 | "prettier": "^1.7.4", 42 | "rimraf": "^2.6.2", 43 | "source-map-support": "^0.5.0", 44 | "tslint": "^5.8.0", 45 | "typescript": "^2.6.1" 46 | }, 47 | "dependencies": { 48 | "bcrypt": "^1.0.3", 49 | "body-parser": "^1.18.2", 50 | "cookie-parser": "^1.4.3", 51 | "cors": "^2.8.4", 52 | "express": "^4.16.2", 53 | "express-graphql": "^0.6.11", 54 | "graphql": "^0.11.7", 55 | "graphql-schema-decorator": "^0.8.0", 56 | "jsonwebtoken": "^8.1.0", 57 | "morgan": "^1.9.0", 58 | "multer": "^1.3.0", 59 | "mysql2": "^1.4.2", 60 | "sequelize": "^4.20.3" 61 | }, 62 | "files": [ 63 | "lib", 64 | "README.md" 65 | ] 66 | } 67 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/store/index.ts: -------------------------------------------------------------------------------- 1 | import { createSelector } from 'reselect'; 2 | 3 | import * as fromThoughts from './reducers/thoughts.reducer'; 4 | import * as fromThoughtDetails from './reducers/thought-details.reducer'; 5 | import * as fromCreate from './reducers/create.reducer'; 6 | import * as fromRemove from './reducers/remove.reducer'; 7 | 8 | export interface State { 9 | thoughts: fromThoughts.State; 10 | thoughtDetails: fromThoughtDetails.State; 11 | create: fromCreate.State; 12 | remove: fromRemove.State; 13 | } 14 | 15 | export const reducers = { 16 | thoughts: fromThoughts.reducer, 17 | thoughtDetails: fromThoughtDetails.reducer, 18 | create: fromCreate.reducer, 19 | remove: fromRemove.reducer, 20 | }; 21 | 22 | /** 23 | * Thoughts store functions 24 | */ 25 | export const getThoughtsState = (state: State) => state.thoughts; 26 | export const getThoughts = createSelector(getThoughtsState, fromThoughts.getData); 27 | export const getThoughtsLoading = createSelector(getThoughtsState, fromThoughts.getLoading); 28 | export const getThoughtsFailed = createSelector(getThoughtsState, fromThoughts.getFailed); 29 | 30 | /** 31 | * Thought Details store functions 32 | */ 33 | export const getDetailsState = (state: State) => state.thoughtDetails; 34 | export const getDetails = createSelector(getDetailsState, fromThoughtDetails.getData); 35 | export const getDetailsLoading = createSelector(getDetailsState, fromThoughtDetails.getLoading); 36 | export const getDetailsFailed = createSelector(getDetailsState, fromThoughtDetails.getFailed); 37 | 38 | /** 39 | * Create store functions 40 | */ 41 | export const getCreateState = (state: State) => state.create; 42 | export const getCreateLoading = createSelector(getCreateState, fromCreate.getLoading); 43 | export const getCreateFailed = createSelector(getCreateState, fromCreate.getFailed); 44 | 45 | /** 46 | * Remove store functions 47 | */ 48 | export const getRemoveState = (state: State) => state.remove; 49 | export const getRemoveLoading = createSelector(getRemoveState, fromRemove.getLoading); 50 | export const getRemoveFailed = createSelector(getRemoveState, fromRemove.getFailed); 51 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/utils/helpers.ts: -------------------------------------------------------------------------------- 1 | // Helpers 2 | 3 | // Render element or component by provided condition 4 | export function renderIf(condition, renderFn) { 5 | return condition ? renderFn() : null; 6 | } 7 | 8 | // GraphQL Query Builder 9 | export function queryBuilder(options) { 10 | options.type = options.type ? options.type : 'query'; 11 | options.operation = options.operation ? options.operation : ''; 12 | options.fields = options.fields ? options.fields : []; 13 | options.data = options.data ? options.data : {}; 14 | options.variables = options.variables ? options.variables : {}; 15 | 16 | const query = { 17 | query: ` 18 | ${ options.type } ${ queryDataArgumentAndTypeMap(options.data) } { 19 | ${ options.operation } ${ queryDataNameAndArgumentMap(options.data) } { 20 | ${ options.fields.join(',') } 21 | } 22 | }`, 23 | variables: Object.assign(options.data, options.variables) 24 | }; 25 | 26 | console.log(query); 27 | 28 | return query; 29 | } 30 | 31 | // Private - Convert object to name and argument map eg: (id: $id) 32 | function queryDataNameAndArgumentMap(data) { 33 | // tslint:disable-next-line:max-line-length 34 | return Object.keys(data).length ? `(${ Object.keys(data).reduce((dataString, key, i) => `${ dataString }${ i !== 0 ? ', ' : '' }${ key }: $${ key }`, '' ) })` : ''; 35 | } 36 | 37 | // Private - Convert object to argument and type map eg: ($id: Int) 38 | function queryDataArgumentAndTypeMap(data) { 39 | // tslint:disable-next-line:max-line-length 40 | return Object.keys(data).length ? `(${ Object.keys(data).reduce((dataString, key, i) => `${ dataString }${ i !== 0 ? ', ' : '' }$${ key }: ${ queryDataType(data[key]) }`, '') })` : ''; 41 | } 42 | 43 | // Private - Get GraphQL equivalent type of data passed (String, Int, Float, Boolean) 44 | function queryDataType(data) { 45 | switch (typeof data) { 46 | case 'boolean': 47 | return 'Boolean'; 48 | case 'number': 49 | return (data % 1 === 0) ? 'Int' : 'Float'; 50 | case 'string': 51 | default: 52 | return 'String'; 53 | } 54 | } 55 | 56 | 57 | const typeCache: { [label: string]: boolean } = {}; 58 | 59 | /** 60 | * This function coerces a string into a string literal type. 61 | * Using tagged union types in TypeScript 2.0, this enables 62 | * powerful typechecking of our reducers. 63 | * 64 | * Since every action label passes through this function it 65 | * is a good place to ensure all of our action labels are unique. 66 | * 67 | * @param label 68 | */ 69 | export function type(label: T | ''): T { 70 | if (typeCache[label]) { 71 | throw new Error(`Action type "${label}" is not unqiue"`); 72 | } 73 | 74 | typeCache[label] = true; 75 | 76 | return label; 77 | } 78 | -------------------------------------------------------------------------------- /webapp/src/app/pages/thoughts/create/create.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Store } from '@ngrx/store'; 3 | import * as store from '../../../@shared/store'; 4 | import { 5 | FormBuilder, 6 | FormGroup, 7 | Validators, 8 | AbstractControl 9 | } from '@angular/forms'; 10 | import * as createActions from '../../../@shared/store/actions/create.action'; 11 | 12 | @Component({ 13 | selector: 'app-create', 14 | template: ` 15 |

Thought Create

16 |

17 | Back 18 |

19 |
20 | 25 |
26 | 27 |
28 |
29 |
30 | 36 |
37 | 38 |
39 |
40 |
41 | 42 |
43 | `, 44 | styles: [] 45 | }) 46 | export class CreateComponent implements OnInit { 47 | public submitted = false; 48 | public form: FormGroup; 49 | public name: AbstractControl; 50 | public thought: AbstractControl; 51 | 52 | private createState$ = this.appState$.select(store.getCreateState); 53 | 54 | private createLoaded$; 55 | 56 | constructor( 57 | private fb: FormBuilder, 58 | protected appState$: Store 59 | ) { } 60 | 61 | ngOnInit() { 62 | this.initForm(); 63 | } 64 | 65 | public initForm(): void { 66 | this.form = this.fb.group({ 67 | name: ['', Validators.required], 68 | thought: ['', Validators.required], 69 | }); 70 | this.name = this.form.controls['name']; 71 | this.thought = this.form.controls['thought']; 72 | } 73 | 74 | public onSubmit(): void { 75 | this.submitted = true; 76 | 77 | if (this.form.valid) { 78 | this.appState$.dispatch(new createActions.LoadAction({ 79 | name: this.name.value, 80 | thought: this.thought.value, 81 | })); 82 | this.subscribeToCreateChanges(); 83 | } 84 | } 85 | 86 | private subscribeToCreateChanges() { 87 | if (this.createLoaded$) { 88 | return; 89 | } 90 | 91 | this.createLoaded$ = this.createState$.subscribe(state => { 92 | if (!state.loading) { 93 | this.form.reset(); 94 | this.submitted = false; 95 | } 96 | }); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /webapp/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** IE10 and IE11 requires the following for the Reflect API. */ 41 | // import 'core-js/es6/reflect'; 42 | 43 | 44 | /** Evergreen browsers require these. **/ 45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. 46 | import 'core-js/es7/reflect'; 47 | 48 | 49 | /** 50 | * Required to support Web Animations `@angular/platform-browser/animations`. 51 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation 52 | **/ 53 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 54 | 55 | 56 | 57 | /*************************************************************************************************** 58 | * Zone JS is required by Angular itself. 59 | */ 60 | import 'zone.js/dist/zone'; // Included with Angular CLI. 61 | 62 | 63 | 64 | /*************************************************************************************************** 65 | * APPLICATION IMPORTS 66 | */ 67 | 68 | /** 69 | * Date, currency, decimal and percent pipes. 70 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 71 | */ 72 | // import 'intl'; // Run `npm install --save intl`. 73 | /** 74 | * Need to import at least one locale-data with intl. 75 | */ 76 | // import 'intl/locale-data/jsonp/en'; 77 | -------------------------------------------------------------------------------- /webapp/src/app/@shared/store/effects/thoughts.effect.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Store } from '@ngrx/store'; 3 | import { Effect, Actions } from '@ngrx/effects'; 4 | import { Action } from '@ngrx/store'; 5 | import { Observable } from 'rxjs/Observable'; 6 | import { of } from 'rxjs/observable/of'; 7 | import { ThoughtsService } from '../../services/thoughts.service'; 8 | import * as store from '../index'; 9 | import * as storeThoughts from '../reducers/thoughts.reducer'; 10 | import * as thoughtsActions from '../actions/thoughts.action'; 11 | import * as thoughtDetailsActions from '../actions/thought-details.action'; 12 | import * as createActions from '../actions/create.action'; 13 | import * as removeActions from '../actions/remove.action'; 14 | import { Thought } from '../../models/thought.model'; 15 | 16 | @Injectable() 17 | export class ThoughtsEffects { 18 | /** 19 | * Load Thoughts effect 20 | */ 21 | @Effect() 22 | loadThoughts$: Observable = this.actions$ 23 | .ofType(thoughtsActions.ActionTypes.LOAD) 24 | .map((action: thoughtsActions.LoadAction) => action.payload) 25 | .switchMap(state => { 26 | return ( 27 | this.thoughtsService 28 | .getList() 29 | .mergeMap(res => [ 30 | new thoughtsActions.LoadSuccessAction( 31 | res.map(item => new Thought(item)) 32 | ) 33 | ]) 34 | .catch(error => of(new thoughtsActions.LoadFailAction(error))) 35 | ); 36 | }); 37 | 38 | /** 39 | * Load Thought Details effect 40 | */ 41 | @Effect() 42 | loadThoughtDetails$: Observable = this.actions$ 43 | .ofType(thoughtDetailsActions.ActionTypes.LOAD) 44 | .map((action: thoughtDetailsActions.LoadAction) => action.payload) 45 | .switchMap(state => { 46 | return ( 47 | this.thoughtsService 48 | .get(state) 49 | .mergeMap(res => [ 50 | new thoughtDetailsActions.LoadSuccessAction(new Thought(res)) 51 | ]) 52 | .catch(error => of(new thoughtDetailsActions.LoadFailAction(error))) 53 | ); 54 | }); 55 | 56 | /** 57 | * Create Thought effect 58 | */ 59 | @Effect() 60 | create$: Observable = this.actions$ 61 | .ofType(createActions.ActionTypes.LOAD) 62 | .map((action: createActions.LoadAction) => action.payload) 63 | .switchMap(state => { 64 | return ( 65 | this.thoughtsService 66 | .create(state) 67 | .mergeMap(res => [ 68 | new createActions.LoadSuccessAction(res) 69 | ]) 70 | .catch(error => of(new createActions.LoadFailAction(error))) 71 | ); 72 | }); 73 | 74 | 75 | /** 76 | * Remove Thought effect 77 | */ 78 | @Effect() 79 | remove$: Observable = this.actions$ 80 | .ofType(removeActions.ActionTypes.LOAD) 81 | .map((action: removeActions.LoadAction) => action.payload) 82 | .switchMap(state => { 83 | return ( 84 | this.thoughtsService 85 | .remove(state) 86 | .mergeMap(res => [ 87 | new removeActions.LoadSuccessAction(res) 88 | ]) 89 | .catch(error => of(new removeActions.LoadFailAction(error))) 90 | ); 91 | }); 92 | 93 | constructor( 94 | private actions$: Actions, 95 | private thoughtsService: ThoughtsService, 96 | private appState$: Store 97 | ) {} 98 | } 99 | -------------------------------------------------------------------------------- /webapp/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "eofline": true, 15 | "forin": true, 16 | "import-blacklist": [ 17 | true, 18 | "rxjs", 19 | "rxjs/Rx" 20 | ], 21 | "import-spacing": true, 22 | "indent": [ 23 | true, 24 | "spaces" 25 | ], 26 | "interface-over-type-literal": true, 27 | "label-position": true, 28 | "max-line-length": [ 29 | true, 30 | 140 31 | ], 32 | "member-access": false, 33 | "member-ordering": [ 34 | true, 35 | { 36 | "order": [ 37 | "static-field", 38 | "instance-field", 39 | "static-method", 40 | "instance-method" 41 | ] 42 | } 43 | ], 44 | "no-arg": true, 45 | "no-bitwise": true, 46 | "no-console": [ 47 | true, 48 | "debug", 49 | "info", 50 | "time", 51 | "timeEnd", 52 | "trace" 53 | ], 54 | "no-construct": true, 55 | "no-debugger": true, 56 | "no-duplicate-super": true, 57 | "no-empty": false, 58 | "no-empty-interface": true, 59 | "no-eval": true, 60 | "no-inferrable-types": [ 61 | true, 62 | "ignore-params" 63 | ], 64 | "no-misused-new": true, 65 | "no-non-null-assertion": true, 66 | "no-shadowed-variable": true, 67 | "no-string-literal": false, 68 | "no-string-throw": true, 69 | "no-switch-case-fall-through": true, 70 | "no-trailing-whitespace": true, 71 | "no-unnecessary-initializer": true, 72 | "no-unused-expression": true, 73 | "no-use-before-declare": true, 74 | "no-var-keyword": true, 75 | "object-literal-sort-keys": false, 76 | "one-line": [ 77 | true, 78 | "check-open-brace", 79 | "check-catch", 80 | "check-else", 81 | "check-whitespace" 82 | ], 83 | "prefer-const": true, 84 | "quotemark": [ 85 | true, 86 | "single" 87 | ], 88 | "radix": true, 89 | "semicolon": [ 90 | true, 91 | "always" 92 | ], 93 | "triple-equals": [ 94 | true, 95 | "allow-null-check" 96 | ], 97 | "typedef-whitespace": [ 98 | true, 99 | { 100 | "call-signature": "nospace", 101 | "index-signature": "nospace", 102 | "parameter": "nospace", 103 | "property-declaration": "nospace", 104 | "variable-declaration": "nospace" 105 | } 106 | ], 107 | "typeof-compare": true, 108 | "unified-signatures": true, 109 | "variable-name": false, 110 | "whitespace": [ 111 | true, 112 | "check-branch", 113 | "check-decl", 114 | "check-operator", 115 | "check-separator", 116 | "check-type" 117 | ], 118 | "directive-selector": [ 119 | true, 120 | "attribute", 121 | "app", 122 | "camelCase" 123 | ], 124 | "component-selector": [ 125 | true, 126 | "element", 127 | "app", 128 | "kebab-case" 129 | ], 130 | "use-input-property-decorator": true, 131 | "use-output-property-decorator": true, 132 | "use-host-property-decorator": true, 133 | "no-input-rename": true, 134 | "no-output-rename": true, 135 | "use-life-cycle-interface": true, 136 | "use-pipe-transform-interface": true, 137 | "component-class-suffix": true, 138 | "directive-class-suffix": true, 139 | "invoke-injectable": true 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![logos](http://rafaelescala.com/assets/fullstack.png) 2 | 3 | # Fullstack GraphQL Angular 4 | >Created from [fullstack graphql](https://github.com/atulmy/fullstack-graphql), implement additional support for Typescript, Angular CLI and ngrx. 5 | 6 | Simple Demo Application 7 | 8 | **API** built with Node + Express + GraphQL + Sequelize (supports MySQL, Postgres, Sqlite and MSSQL). 9 | 10 | **WebApp** built with Angular CLI + Redux + Async Middleware. 11 | 12 | Written in Typescript using Babel + Angular CLI. 13 | 14 | ## 📝 Features 15 | - [x] List thoughts 16 | - [x] Add thought 17 | - [x] Delete thought 18 | - [x] View single thought 19 | 20 | ## ▶️ Running 21 | - Clone repo `git clone git@github.com:rafaesc/fullstack-graphql-angular.git fullstack-graphql-angular` 22 | - Install NPM modules API `cd api` and `npm install` 23 | - Install NPM modules Webapp `cd webapp` and `npm install` 24 | - Modify `/api/src/config/database.json` for database credentials 25 | - Modify `/api/src/config/config.json` for API port (optional) 26 | - Modify `/webapp/.env` for webapp port (optional) 27 | - Run API `cd api`, `npm run build` and `npm start`, browse GraphQL at http://localhost:3000/ 28 | - Run Webapp `cd webapp` and `npm start`, browse webapp at http://localhost:4200/ 29 | 30 | ### Sample API logs 31 | ``` 32 | [nodemon] starting `babel-node src/index.js --presets es2015,stage-2` 33 | SETUP - Connecting database... 34 | SETUP - Loading modules... 35 | SETUP - GraphQL... 36 | SETUP - Syncing database tables... 37 | INFO - Database connected. 38 | INFO - Database sync complete. 39 | SETUP - Starting server... 40 | INFO - Server started on port 3000. 41 | ``` 42 | 43 | ## 📸 Screenshots 44 | ![screenshot](http://rafaelescala.com/assets/fullstack.gif?v=0.2) 45 | 46 | ## 🏗 Core Structure 47 | fullstack-graphql-angular 48 | ├── api (api.example.com) 49 | │ ├── src 50 | │ │ ├── config 51 | │ │ ├── models 52 | │ │ ├── schema 53 | │ │ ├── setup 54 | │ │ └── index.js 55 | │ │ 56 | │ └── package.json 57 | │ 58 | ├── webapp (example.com) 59 | │ ├── public 60 | │ ├── src 61 | │ │ └── app 62 | │ │ ├──@core 63 | │ │ ├──@shared 64 | │ │ ├──pages 65 | │ │ └──app.module.ts 66 | │ │ 67 | │ └── package.json 68 | │ 69 | ├── .gitignore 70 | └── README.md 71 | 72 | ## 📘 Guides 73 | ### API 74 | - Adding new Module (Eg: Users): 75 | - Copy `/api/src/models/thought.ts` to `/api/src/models/user.ts` and modify the file for table name and respective fields 76 | - Add an entry to the `models` object in `/api/src/models/index.ts` 77 | - Copy `/api/src/schema/thoughts` to `/api/src/schema/users` and modify `type.ts`, `resolvers.ts` and `fields/query.ts` and `fields/mutations.ts` 78 | - Import `/api/src/schema/users/fields/query.ts` in `/api/src/schema/query.ts` and add user to the fields 79 | - Import `/api/src/schema/users/fields/mutations.ts` in `/api/src/schema/mutations.ts` and add user to the fields 80 | - To activate these changes do `cd api`, `npm run build` and `npm start` 81 | 82 | ### Webapp 83 | - Adding new Module (Eg: Users): 84 | - Create folder `users` under `/webapp/src/app/pages/` 85 | - Create your Module and Component under `/webapp/src/app/pages/users` 86 | - Add `users.action.ts` where all your Redux Action Types and Actions will reside (refer `/webapp/src/app/@shared/store/actions/users.action.ts`) 87 | - Add `users.reducer.ts` where all your respective Reducers will recide (refer `/webapp/src/@shared/store/reducers/users.reducer.ts`) 88 | - Add `users.service.ts` where all your respective Services will recide (refer `/webapp/src/@shared/services/users.service.ts`) 89 | - Add `users.effect.ts` where all your respective Effects will recide (refer `/webapp/src/@shared/store/reducers/users.effect.ts`) 90 | - Import the module state in `/webapp/src/@shared/store/` to make it avaliable to the app 91 | - Import the Users Effect in `/webapp/src/@core/core.module.ts` 92 | - Encapsulate all your User related code in `/webapp/src/app/pages/users` 93 | - Adding new Route (Eg: `/users`): 94 | - Add a new entry to `PAGES_ROUTES` object in `/webapp/src/app/pages/pages.routing.ts` 95 | 96 | ## Sample GraphQL Queries 97 | These queries are generated on client side using `queryBuilder()` helper defined in `/webapp/src/app/@shared/utils/helpers.ts` 98 | 99 | 100 | 101 | 102 | 114 | 135 | 136 | 137 | 138 | 150 | 164 | 165 | 166 | 167 | 180 | 192 | 193 | 194 | 195 | 205 | 217 | 218 | 219 |
103 |

Query - Get List

104 |
105 | query {
106 |   thoughts {
107 |     id,
108 |     name,
109 |     thought
110 |   }
111 | }
112 |                 
113 |
115 |

Response

116 |
117 | {
118 |   "data": {
119 |     "thoughts": [
120 |       {
121 |         "id": 1,
122 |         "name": "Arya Stark",
123 |         "thought": "A girl has no name"
124 |       },
125 |       {
126 |         "id": 2,
127 |         "name": "Jon Snow",
128 |         "thought": "I know nothing"
129 |       }
130 |     ]
131 |   }
132 | }
133 |                 
134 |
139 |

Query - Get by Param

140 |
141 | query {
142 |   thought(id: 1) {
143 |     id,
144 |     name,
145 |     thought
146 |   }
147 | }
148 |                 
149 |
151 |

Response

152 |
153 | {
154 |   "data": {
155 |     "thought": {
156 |       "id": 1,
157 |       "name": "Arya",
158 |       "thought": "A girl has no name"
159 |     }
160 |   }
161 | }
162 |                 
163 |
168 |

Mutation - Create

169 |
170 | mutation {
171 |   thoughtCreate(
172 |     name: "Tyrion Lannister", 
173 |     thought:"I drink and I know things"
174 |   ) {
175 |     id
176 |   }
177 | }
178 |                 
179 |
181 |

Response

182 |
183 | {
184 |   "data": {
185 |     "thoughtCreate": {
186 |       "id": 3
187 |     }
188 |   }
189 | }
190 |                 
191 |
196 |

Mutation - Remove

197 |
198 | mutation {
199 |   thoughtRemove(id: 3) {
200 |     id
201 |   }
202 | }
203 |                 
204 |
206 |

Response

207 |
208 | {
209 |   "data": {
210 |     "thoughtRemove": {
211 |       "id": null
212 |     }
213 |   }
214 | }
215 |                 
216 |
220 | --------------------------------------------------------------------------------