├── .gitignore ├── README.md ├── frontend ├── .editorconfig ├── .gitignore ├── .npmrc ├── README.md ├── angular.json ├── codegen.yml ├── e2e │ ├── app.e2e-spec.ts │ ├── app.po.ts │ └── tsconfig.e2e.json ├── karma.conf.js ├── package.json ├── protractor.conf.js ├── proxy.conf.json ├── src │ ├── app │ │ ├── api │ │ │ └── index.ts │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── cars │ │ │ ├── car-edit │ │ │ │ ├── car-edit.component.css │ │ │ │ ├── car-edit.component.html │ │ │ │ ├── car-edit.component.spec.ts │ │ │ │ └── car-edit.component.ts │ │ │ ├── car-list │ │ │ │ ├── car-list.component.css │ │ │ │ ├── car-list.component.html │ │ │ │ ├── car-list.component.spec.ts │ │ │ │ └── car-list.component.ts │ │ │ └── cars.module.ts │ │ ├── graphql.module.ts │ │ ├── graphql │ │ │ ├── delete-car.graphql │ │ │ ├── get-car.graphql │ │ │ ├── list-cars.graphql │ │ │ └── save-car.graphql │ │ └── material.module.ts │ ├── assets │ │ └── .gitkeep │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ ├── test.ts │ ├── tsconfig.app.json │ ├── tsconfig.spec.json │ └── typings.d.ts ├── tsconfig.json └── tslint.json ├── renovate.json └── server ├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── graphql.config.json ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── igu │ │ └── developer │ │ └── demo │ │ ├── Car.java │ │ ├── CarRepository.java │ │ ├── CarService.java │ │ ├── DemoApplication.java │ │ └── GiphyService.java └── resources │ └── application.properties └── test └── java └── com └── igu └── developer └── demo └── DemoApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Basic CRUD App with Angular 7.0 and Spring Boot 2.0 2 | This example app shows how to build a basic CRUD app with Spring Boot 2.0, GraphQL, SPQR, Apollo Client and Angular 7.0. 3 | 4 | **Prerequisites:** [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) and [Node.js](https://nodejs.org/). 5 | 6 | * [Getting Started](#getting-started) 7 | * [Resources](#resources) 8 | 9 | ## Getting Started 10 | 11 | To install this example application, run the following commands: 12 | 13 | ```bash 14 | git clone https://github.com/iguissouma/spring-graphql-apollo-angular.git 15 | cd spring-graphql-apollo-angular 16 | ``` 17 | 18 | This will get a copy of the project installed locally. To install all of its dependencies and start each app, follow the instructions below. 19 | 20 | To run the server, cd into the `server` folder and run: 21 | 22 | ```bash 23 | ./mvnw spring-boot:run 24 | ``` 25 | 26 | To run the client, cd into the `frontend` folder and run: 27 | 28 | ```bash 29 | npm install && npm start 30 | ``` 31 | 32 | ## Resources 33 | * Matt Raible (@mraible) Blog posts and Repo 34 | * [Build a Basic CRUD App with Angular 5.0 and Spring Boot 2.0 Blog post](https://developer.okta.com/blog/2017/12/04/basic-crud-angular-and-spring-boot) 35 | * [CRUD App with Angular 5.0 and Spring Boot 2.0 GitHub Repo](https://github.com/oktadeveloper/okta-spring-boot-2-angular-5-example) 36 | * Kamil Kisiela Blog posts and Repo 37 | * [Apollo-Angular 1.2 — using GraphQL in your apps just got a whole lot easier! Blog post](https://medium.com/the-guild/apollo-angular-code-generation-7903da1f8559) 38 | * [Use GraphQL in Angular - step by step - includes code generation](https://github.com/kamilkisiela/apollo-angular-introduction) 39 | * [Query and Mutation as a service GitHub Repo](https://github.com/kamilkisiela/apollo-angular-services) 40 | * Uri Goldshtein from Apollo Team conference @ng-conf 41 | * [Angular and GraphQL – A modern API for a modern Platform](https://www.youtube.com/watch?v=rb5i8Bs7-k0) 42 | * Bojan Tomić conference @Devoxx and Samples Repo 43 | * [GraphQL SPQR: The fastest route to GraphQL](https://www.youtube.com/watch?v=iyt7PwkUWQA) 44 | * [GraphQL SPQR Samples](https://github.com/leangen/graphql-spqr-samples) -------------------------------------------------------------------------------- /frontend/.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 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /dist-server 6 | /tmp 7 | /out-tsc 8 | 9 | # dependencies 10 | /node_modules 11 | 12 | # IDEs and editors 13 | /.idea 14 | .project 15 | .classpath 16 | .c9/ 17 | *.launch 18 | .settings/ 19 | *.sublime-workspace 20 | 21 | # IDE - VSCode 22 | .vscode/* 23 | !.vscode/settings.json 24 | !.vscode/tasks.json 25 | !.vscode/launch.json 26 | !.vscode/extensions.json 27 | 28 | # misc 29 | /.sass-cache 30 | /connect.lock 31 | /coverage 32 | /libpeerconnection.log 33 | npm-debug.log 34 | yarn-error.log 35 | testem.log 36 | /typings 37 | 38 | # e2e 39 | /e2e/*.js 40 | /e2e/*.map 41 | 42 | # System Files 43 | .DS_Store 44 | Thumbs.db 45 | -------------------------------------------------------------------------------- /frontend/.npmrc: -------------------------------------------------------------------------------- 1 | PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true 2 | 3 | depth=0 4 | loglevel=warn 5 | package-lock=false 6 | progress=false 7 | -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # Frontend 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.7.3. 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 | -------------------------------------------------------------------------------- /frontend/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "frontend": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "architect": { 11 | "build": { 12 | "builder": "@angular-devkit/build-angular:browser", 13 | "options": { 14 | "outputPath": "dist", 15 | "index": "src/index.html", 16 | "main": "src/main.ts", 17 | "tsConfig": "src/tsconfig.app.json", 18 | "polyfills": "src/polyfills.ts", 19 | "assets": [ 20 | "src/assets", 21 | "src/favicon.ico" 22 | ], 23 | "styles": [ 24 | "src/styles.css" 25 | ], 26 | "scripts": [] 27 | }, 28 | "configurations": { 29 | "production": { 30 | "optimization": true, 31 | "outputHashing": "all", 32 | "sourceMap": false, 33 | "extractCss": true, 34 | "namedChunks": false, 35 | "aot": true, 36 | "extractLicenses": true, 37 | "vendorChunk": false, 38 | "buildOptimizer": true, 39 | "fileReplacements": [ 40 | { 41 | "replace": "src/environments/environment.ts", 42 | "with": "src/environments/environment.prod.ts" 43 | } 44 | ] 45 | } 46 | } 47 | }, 48 | "serve": { 49 | "builder": "@angular-devkit/build-angular:dev-server", 50 | "options": { 51 | "browserTarget": "frontend:build" 52 | }, 53 | "configurations": { 54 | "production": { 55 | "browserTarget": "frontend:build:production" 56 | } 57 | } 58 | }, 59 | "extract-i18n": { 60 | "builder": "@angular-devkit/build-angular:extract-i18n", 61 | "options": { 62 | "browserTarget": "frontend:build" 63 | } 64 | }, 65 | "test": { 66 | "builder": "@angular-devkit/build-angular:karma", 67 | "options": { 68 | "main": "src/test.ts", 69 | "karmaConfig": "./karma.conf.js", 70 | "polyfills": "src/polyfills.ts", 71 | "tsConfig": "src/tsconfig.spec.json", 72 | "scripts": [], 73 | "styles": [ 74 | "src/styles.css" 75 | ], 76 | "assets": [ 77 | "src/assets", 78 | "src/favicon.ico" 79 | ] 80 | } 81 | }, 82 | "lint": { 83 | "builder": "@angular-devkit/build-angular:tslint", 84 | "options": { 85 | "tsConfig": [ 86 | "src/tsconfig.app.json", 87 | "src/tsconfig.spec.json" 88 | ], 89 | "exclude": [ 90 | "src/app/api/index.ts", 91 | "**/node_modules/**" 92 | ] 93 | } 94 | } 95 | } 96 | }, 97 | "frontend-e2e": { 98 | "root": "", 99 | "sourceRoot": "e2e", 100 | "projectType": "application", 101 | "architect": { 102 | "e2e": { 103 | "builder": "@angular-devkit/build-angular:protractor", 104 | "options": { 105 | "protractorConfig": "./protractor.conf.js", 106 | "devServerTarget": "frontend:serve" 107 | } 108 | }, 109 | "lint": { 110 | "builder": "@angular-devkit/build-angular:tslint", 111 | "options": { 112 | "tsConfig": [ 113 | "e2e/tsconfig.e2e.json" 114 | ], 115 | "exclude": [ 116 | "**/node_modules/**" 117 | ] 118 | } 119 | } 120 | } 121 | } 122 | }, 123 | "defaultProject": "frontend", 124 | "schematics": { 125 | "@schematics/angular:component": { 126 | "prefix": "app", 127 | "styleext": "css" 128 | }, 129 | "@schematics/angular:directive": { 130 | "prefix": "app" 131 | } 132 | }, 133 | "cli": { 134 | "warnings": { 135 | "typescriptMismatch": false 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /frontend/codegen.yml: -------------------------------------------------------------------------------- 1 | schema: 2 | - http://localhost:8080/graphql 3 | documents: 4 | - src/app/graphql/delete-car.graphql 5 | - src/app/graphql/get-car.graphql 6 | - src/app/graphql/list-cars.graphql 7 | - src/app/graphql/save-car.graphql 8 | config: 9 | resolvers: false 10 | overwrite: true 11 | generates: 12 | src/app/api/index.ts: 13 | config: 14 | noNamespaces: true 15 | resolvers: false 16 | enumsAsTypes: true 17 | avoidOptionals: true 18 | immutableTypes: true 19 | scalars: 20 | Long: number 21 | plugins: 22 | - typescript 23 | - typescript-operations 24 | - typescript-apollo-angular 25 | require: [] 26 | -------------------------------------------------------------------------------- /frontend/e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('frontend 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 | -------------------------------------------------------------------------------- /frontend/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 | -------------------------------------------------------------------------------- /frontend/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 | -------------------------------------------------------------------------------- /frontend/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-devkit/build-angular'], 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-devkit/build-angular/plugins/karma') 14 | ], 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ], 20 | fixWebpackSourcePaths: true 21 | }, 22 | 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; 32 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve --host 0.0.0.0 --proxy-config proxy.conf.json", 8 | "build": "ng build --prod", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e", 12 | "graphql": "graphql-codegen --config codegen.yml" 13 | }, 14 | "private": true, 15 | "config": { 16 | "graphql": "http://localhost:8080/graphql" 17 | }, 18 | "dependencies": { 19 | "@angular/animations": "8.1.2", 20 | "@angular/cdk": "8.1.1", 21 | "@angular/common": "8.1.2", 22 | "@angular/compiler": "8.1.2", 23 | "@angular/core": "8.1.2", 24 | "@angular/flex-layout": "7.0.0-beta.24", 25 | "@angular/forms": "8.1.2", 26 | "@angular/http": "7.2.15", 27 | "@angular/material": "8.1.1", 28 | "@angular/platform-browser": "8.1.2", 29 | "@angular/platform-browser-dynamic": "8.1.2", 30 | "@angular/router": "8.1.2", 31 | "@covalent/core": "2.1.0", 32 | "apollo-angular": "1.6.0", 33 | "apollo-angular-link-http": "1.8.0", 34 | "apollo-cache-inmemory": "1.6.2", 35 | "apollo-client": "2.6.3", 36 | "core-js": "3.1.4", 37 | "graphql": "14.4.2", 38 | "graphql-tag": "2.10.1", 39 | "hammerjs": "2.0.8", 40 | "rxjs": "6.5.2", 41 | "tslib": "1.10.0", 42 | "zone.js": "0.9.1" 43 | }, 44 | "devDependencies": { 45 | "@angular-devkit/build-angular": "0.801.2", 46 | "@angular/cli": "8.1.2", 47 | "@angular/compiler-cli": "8.1.2", 48 | "@angular/language-service": "8.1.2", 49 | "@graphql-codegen/cli": "1.4.0", 50 | "@graphql-codegen/typescript": "1.4.0", 51 | "@graphql-codegen/typescript-apollo-angular": "1.4.0", 52 | "@graphql-codegen/typescript-operations": "1.4.0", 53 | "@types/jasmine": "3.3.15", 54 | "@types/jasminewd2": "2.0.6", 55 | "@types/node": "12.6.8", 56 | "codelyzer": "5.1.0", 57 | "jasmine-core": "3.4.0", 58 | "jasmine-spec-reporter": "4.2.1", 59 | "karma": "4.2.0", 60 | "karma-chrome-launcher": "3.0.0", 61 | "karma-coverage-istanbul-reporter": "2.0.6", 62 | "karma-jasmine": "2.0.1", 63 | "karma-jasmine-html-reporter": "1.4.2", 64 | "protractor": "5.4.2", 65 | "ts-node": "8.3.0", 66 | "tslint": "5.18.0", 67 | "typescript": "3.4.5" 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /frontend/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 | -------------------------------------------------------------------------------- /frontend/proxy.conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "/graphql": { 3 | "target": "http://localhost:8080", 4 | "secure": false 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /frontend/src/app/api/index.ts: -------------------------------------------------------------------------------- 1 | import gql from "graphql-tag"; 2 | import { Injectable } from "@angular/core"; 3 | import * as Apollo from "apollo-angular"; 4 | export type Maybe = T | null; 5 | /** All built-in and custom scalars, mapped to their actual values */ 6 | export type Scalars = { 7 | ID: string; 8 | String: string; 9 | Boolean: boolean; 10 | Int: number; 11 | Float: number; 12 | /** Long type */ 13 | Long: number; 14 | /** Unrepresentable type */ 15 | UNREPRESENTABLE: any; 16 | }; 17 | 18 | export type Car = { 19 | __typename?: "Car"; 20 | readonly giphyUrl: Maybe; 21 | readonly id: Maybe; 22 | readonly isCool: Scalars["Boolean"]; 23 | readonly name: Maybe; 24 | }; 25 | 26 | export type CarInput = { 27 | /** A car's id */ 28 | readonly id: Maybe; 29 | /** A car's name */ 30 | readonly name: Maybe; 31 | }; 32 | 33 | /** Mutation root */ 34 | export type Mutation = { 35 | __typename?: "Mutation"; 36 | readonly deleteCar: Maybe; 37 | readonly saveCar: Maybe; 38 | }; 39 | 40 | /** Mutation root */ 41 | export type MutationDeleteCarArgs = { 42 | id: Maybe; 43 | }; 44 | 45 | /** Mutation root */ 46 | export type MutationSaveCarArgs = { 47 | car: Maybe; 48 | }; 49 | 50 | /** Query root */ 51 | export type Query = { 52 | __typename?: "Query"; 53 | readonly cars: Maybe>>; 54 | readonly car: Maybe; 55 | }; 56 | 57 | /** Query root */ 58 | export type QueryCarArgs = { 59 | id: Maybe; 60 | }; 61 | 62 | export type DeleteCarMutationVariables = { 63 | id: Scalars["Long"]; 64 | }; 65 | 66 | export type DeleteCarMutation = { readonly __typename?: "Mutation" } & Pick< 67 | Mutation, 68 | "deleteCar" 69 | >; 70 | 71 | export type GetCarQueryVariables = { 72 | id: Scalars["Long"]; 73 | }; 74 | 75 | export type GetCarQuery = { readonly __typename?: "Query" } & { 76 | readonly car: Maybe< 77 | { readonly __typename?: "Car" } & Pick 78 | >; 79 | }; 80 | 81 | export type ListCarsQueryVariables = {}; 82 | 83 | export type ListCarsQuery = { readonly __typename?: "Query" } & { 84 | readonly cars: Maybe< 85 | ReadonlyArray< 86 | Maybe< 87 | { readonly __typename?: "Car" } & Pick 88 | > 89 | > 90 | >; 91 | }; 92 | 93 | export type SaveCarMutationVariables = { 94 | car: CarInput; 95 | }; 96 | 97 | export type SaveCarMutation = { readonly __typename?: "Mutation" } & { 98 | readonly saveCar: Maybe< 99 | { readonly __typename?: "Car" } & Pick 100 | >; 101 | }; 102 | 103 | export const DeleteCarDocument = gql` 104 | mutation DeleteCar($id: Long!) { 105 | deleteCar(id: $id) 106 | } 107 | `; 108 | 109 | @Injectable({ 110 | providedIn: "root" 111 | }) 112 | export class DeleteCarGQL extends Apollo.Mutation< 113 | DeleteCarMutation, 114 | DeleteCarMutationVariables 115 | > { 116 | document = DeleteCarDocument; 117 | } 118 | export const GetCarDocument = gql` 119 | query GetCar($id: Long!) { 120 | car(id: $id) { 121 | id 122 | name 123 | giphyUrl 124 | } 125 | } 126 | `; 127 | 128 | @Injectable({ 129 | providedIn: "root" 130 | }) 131 | export class GetCarGQL extends Apollo.Query { 132 | document = GetCarDocument; 133 | } 134 | export const ListCarsDocument = gql` 135 | query ListCars { 136 | cars { 137 | id 138 | name 139 | giphyUrl 140 | } 141 | } 142 | `; 143 | 144 | @Injectable({ 145 | providedIn: "root" 146 | }) 147 | export class ListCarsGQL extends Apollo.Query< 148 | ListCarsQuery, 149 | ListCarsQueryVariables 150 | > { 151 | document = ListCarsDocument; 152 | } 153 | export const SaveCarDocument = gql` 154 | mutation SaveCar($car: CarInput!) { 155 | saveCar(car: $car) { 156 | id 157 | name 158 | giphyUrl 159 | } 160 | } 161 | `; 162 | 163 | @Injectable({ 164 | providedIn: "root" 165 | }) 166 | export class SaveCarGQL extends Apollo.Mutation< 167 | SaveCarMutation, 168 | SaveCarMutationVariables 169 | > { 170 | document = SaveCarDocument; 171 | } 172 | -------------------------------------------------------------------------------- /frontend/src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iguissouma/spring-graphql-apollo-angular/2cc1260e3dc0d5cb1f4f0a82968266db516943f7/frontend/src/app/app.component.css -------------------------------------------------------------------------------- /frontend/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | Welcome to {{title}}! 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /frontend/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, TestBed } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | 4 | import { GraphQLModule } from './graphql.module'; 5 | import { MaterialModule } from './material.module'; 6 | 7 | import { AppComponent } from './app.component'; 8 | 9 | describe('AppComponent', () => { 10 | beforeEach(async(() => { 11 | TestBed.configureTestingModule({ 12 | declarations: [AppComponent], 13 | imports: [RouterTestingModule, GraphQLModule, MaterialModule] 14 | }).compileComponents(); 15 | })); 16 | 17 | it('should create the app', async(() => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.debugElement.componentInstance; 20 | expect(app).toBeTruthy(); 21 | })); 22 | 23 | it(`should have as title 'app'`, async(() => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.debugElement.componentInstance; 26 | expect(app.title).toEqual('CRUD app'); 27 | })); 28 | 29 | it('should render title in a h1 tag', async(() => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.debugElement.nativeElement; 33 | expect(compiled.querySelector('span').textContent).toContain('Welcome to CRUD app!'); 34 | })); 35 | }); 36 | -------------------------------------------------------------------------------- /frontend/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'CRUD app'; 10 | } 11 | -------------------------------------------------------------------------------- /frontend/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { RouterModule, Routes } from '@angular/router'; 4 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 5 | import { FlexLayoutModule } from '@angular/flex-layout'; 6 | import { FormsModule } from '@angular/forms'; 7 | 8 | import { CovalentDialogsModule } from '@covalent/core'; 9 | 10 | import { AppComponent } from '@app/app.component'; 11 | import { GraphQLModule } from '@app/graphql.module'; 12 | import { MaterialModule } from '@app/material.module'; 13 | import { CarsModule } from '@app/cars/cars.module'; 14 | import 'hammerjs'; 15 | 16 | const routes: Routes = [ 17 | {path: '', redirectTo: '/cars', pathMatch: 'full'}, 18 | ]; 19 | 20 | 21 | @NgModule({ 22 | declarations: [ 23 | AppComponent 24 | ], 25 | imports: [ 26 | BrowserModule, 27 | BrowserAnimationsModule, 28 | FlexLayoutModule, 29 | FormsModule, 30 | RouterModule.forRoot(routes), 31 | 32 | CovalentDialogsModule, 33 | GraphQLModule, 34 | MaterialModule, 35 | 36 | CarsModule 37 | ], 38 | providers: [], 39 | bootstrap: [AppComponent] 40 | }) 41 | export class AppModule { 42 | } 43 | -------------------------------------------------------------------------------- /frontend/src/app/cars/car-edit/car-edit.component.css: -------------------------------------------------------------------------------- 1 | .giphy { 2 | margin: 10px; 3 | } 4 | -------------------------------------------------------------------------------- /frontend/src/app/cars/car-edit/car-edit.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |

{{car.name ? 'Edit' : 'Add'}} Car

5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Cancel 16 | 17 | 18 |
19 | {{car.name}} 20 |
21 |
22 |
23 |
24 | -------------------------------------------------------------------------------- /frontend/src/app/cars/car-edit/car-edit.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { FormsModule } from '@angular/forms'; 2 | 3 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 4 | import { RouterTestingModule } from '@angular/router/testing'; 5 | 6 | import { CovalentDialogsModule } from '@covalent/core'; 7 | 8 | import { GraphQLModule } from '../../graphql.module'; 9 | import { MaterialModule } from '../../material.module'; 10 | 11 | import { CarEditComponent } from './car-edit.component'; 12 | 13 | describe('CarEditComponent', () => { 14 | let component: CarEditComponent; 15 | let fixture: ComponentFixture; 16 | 17 | beforeEach(async(() => { 18 | TestBed.configureTestingModule({ 19 | declarations: [CarEditComponent], 20 | imports: [ 21 | FormsModule, 22 | RouterTestingModule, 23 | 24 | CovalentDialogsModule, 25 | GraphQLModule, 26 | MaterialModule, 27 | ], 28 | }) 29 | .compileComponents(); 30 | })); 31 | 32 | beforeEach(() => { 33 | fixture = TestBed.createComponent(CarEditComponent); 34 | component = fixture.componentInstance; 35 | fixture.detectChanges(); 36 | }); 37 | 38 | it('should create', () => { 39 | expect(component).toBeTruthy(); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /frontend/src/app/cars/car-edit/car-edit.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Location } from '@angular/common'; 3 | import { ActivatedRoute, Router } from '@angular/router'; 4 | 5 | import { TdDialogService } from '@covalent/core'; 6 | import { pluck } from 'rxjs/operators'; 7 | 8 | import { Car, DeleteCarGQL, GetCarGQL, ListCarsGQL, Long, SaveCarGQL } from '../../api'; 9 | 10 | @Component({ 11 | selector: 'app-car-edit', 12 | templateUrl: './car-edit.component.html', 13 | styleUrls: ['./car-edit.component.css'] 14 | }) 15 | export class CarEditComponent implements OnInit { 16 | car: Car; 17 | 18 | constructor( 19 | private location: Location, 20 | private router: Router, 21 | private activatedRoute: ActivatedRoute, 22 | private dialogService: TdDialogService, 23 | private getCarGQL: GetCarGQL, 24 | private listCarsGQL: ListCarsGQL, 25 | private saveCarGQL: SaveCarGQL, 26 | private deleteCarGQL: DeleteCarGQL 27 | ) {} 28 | 29 | ngOnInit(): void { 30 | const id = this.activatedRoute.snapshot.params['id']; 31 | 32 | if ('new' !== id) { 33 | this.getCarGQL 34 | .fetch({ id }) 35 | .pipe(pluck('data', 'car')) 36 | .subscribe((car: Car) => { 37 | console.log('Car', car); 38 | if (car) { 39 | this.car = car; 40 | } else { 41 | console.log(`Car with id '${id}' not found, returning to list`); 42 | this.goBack(); 43 | } 44 | }); 45 | } else { 46 | this.car = { 47 | giphyUrl: null, 48 | id: null, 49 | isCool: false, 50 | name: null 51 | }; 52 | } 53 | } 54 | 55 | save(car: Car): void { 56 | this.saveCarGQL 57 | .mutate( 58 | { car }, 59 | { 60 | update: (proxy, { data: { saveCar } }) => { 61 | // Read the data from our cache for this query. 62 | const data: { cars: Car[] } = proxy.readQuery({ query: this.listCarsGQL.document }); 63 | const cars: Car[] = data.cars; 64 | 65 | if (car.id) { 66 | const index = cars.map(x => x.id).indexOf(car.id); 67 | cars[index] = saveCar; 68 | } else { 69 | cars.push(saveCar); 70 | } 71 | // Write our data back to the cache. 72 | proxy.writeQuery({ query: this.listCarsGQL.document, data }); 73 | } 74 | } 75 | ) 76 | .subscribe( 77 | (newCar: Car) => { 78 | console.log('Car added', newCar); 79 | this.router.navigate(['/cars']); 80 | }, 81 | error => { 82 | console.log('there was an error sending the query', error); 83 | } 84 | ); 85 | } 86 | 87 | remove(id: Long): void { 88 | this.dialogService 89 | .openConfirm({ 90 | title: 'Confirm', 91 | message: 'Are you sure you want to perform this action?' 92 | }) 93 | .afterClosed() 94 | .subscribe((accept: boolean) => { 95 | if (accept) { 96 | this.deleteCarGQL 97 | .mutate( 98 | { id }, 99 | { 100 | update: (proxy, { data: { deleteCar } }) => { 101 | // Read the data from our cache for this query. 102 | const data: any = proxy.readQuery({ query: this.listCarsGQL.document }); 103 | const index = data.cars.map(x => x.id).indexOf(id); 104 | data.cars.splice(index, 1); 105 | // Write our data back to the cache. 106 | proxy.writeQuery({ query: this.listCarsGQL.document, data }); 107 | } 108 | } 109 | ) 110 | .subscribe( 111 | (data: Car) => { 112 | console.log(`Car with ID ${data.id} deleted.`); 113 | this.router.navigate(['/cars']); 114 | }, 115 | error => { 116 | console.log('there was an error sending the query', error); 117 | } 118 | ); 119 | } else { 120 | // DO SOMETHING ELSE 121 | } 122 | }); 123 | } 124 | 125 | goBack(): void { 126 | this.location.back(); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /frontend/src/app/cars/car-list/car-list.component.css: -------------------------------------------------------------------------------- 1 | .cars-table .car { 2 | position: relative; 3 | cursor: pointer; 4 | height: 84px; 5 | } 6 | 7 | .img-circular { 8 | width: 50px; 9 | height: 50px; 10 | background-size: cover; 11 | display: block; 12 | border-radius: 25px; 13 | -webkit-border-radius: 25px; 14 | -moz-border-radius: 25px; 15 | } 16 | -------------------------------------------------------------------------------- /frontend/src/app/cars/car-list/car-list.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | List 5 | 6 | 7 |
8 | 9 | 10 | ID 11 | {{row.id}} 12 | 13 | 14 | Image 15 | 16 |
17 | {{row.name}} 18 |
19 |
20 |
21 | 22 | Name 23 | {{row.name}} 24 | 25 | 26 | 27 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 40 |
41 | 43 |
44 |
45 |
46 |
47 | 48 | -------------------------------------------------------------------------------- /frontend/src/app/cars/car-list/car-list.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { NoopAnimationsModule } from '@angular/platform-browser/animations'; 2 | 3 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 4 | import { RouterTestingModule } from '@angular/router/testing'; 5 | 6 | import { CovalentDialogsModule } from '@covalent/core'; 7 | import { GraphQLModule } from '../../graphql.module'; 8 | import { MaterialModule } from '../../material.module'; 9 | 10 | import { CarListComponent } from './car-list.component'; 11 | 12 | describe('CarListComponent', () => { 13 | let component: CarListComponent; 14 | let fixture: ComponentFixture; 15 | 16 | beforeEach(async(() => { 17 | TestBed.configureTestingModule({ 18 | declarations: [CarListComponent], 19 | imports: [ 20 | CovalentDialogsModule, 21 | GraphQLModule, 22 | MaterialModule, 23 | NoopAnimationsModule, 24 | RouterTestingModule 25 | ] 26 | }) 27 | .compileComponents(); 28 | })); 29 | 30 | beforeEach(() => { 31 | fixture = TestBed.createComponent(CarListComponent); 32 | component = fixture.componentInstance; 33 | fixture.detectChanges(); 34 | }); 35 | 36 | it('should create', () => { 37 | expect(component).toBeTruthy(); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /frontend/src/app/cars/car-list/car-list.component.ts: -------------------------------------------------------------------------------- 1 | import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core'; 2 | import {ActivatedRoute, Router} from '@angular/router'; 3 | import {MatPaginator, MatSort} from '@angular/material'; 4 | import {MatTableDataSource} from '@angular/material/table'; 5 | import {TdDialogService} from '@covalent/core'; 6 | import {pluck} from 'rxjs/operators'; 7 | 8 | import {Car, DeleteCarGQL, ListCarsGQL, Long} from '../../api'; 9 | 10 | @Component({ 11 | selector: 'app-car-list', 12 | templateUrl: './car-list.component.html', 13 | styleUrls: ['./car-list.component.css'] 14 | }) 15 | export class CarListComponent implements OnInit, AfterViewInit { 16 | @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator; 17 | @ViewChild(MatSort, {static: true}) sort: MatSort; 18 | cars$: any; 19 | dataSource: MatTableDataSource = new MatTableDataSource(); 20 | displayedColumns = ['id', 'image', 'name', 'buttons']; 21 | 22 | constructor( 23 | private router: Router, 24 | private activatedRoute: ActivatedRoute, 25 | private listCarsGQL: ListCarsGQL, 26 | private deleteCarGQL: DeleteCarGQL, 27 | private dialogService: TdDialogService 28 | ) { 29 | } 30 | 31 | ngOnInit(): void { 32 | this.cars$ = this.listCarsGQL.watch().valueChanges.pipe(pluck('data', 'cars')); 33 | this.cars$.subscribe(data => { 34 | this.dataSource.data = data; 35 | this.dataSource.paginator = this.paginator; 36 | this.dataSource.sort = this.sort; 37 | }); 38 | } 39 | 40 | editCar(id: Long): void { 41 | this.router.navigate([id], {relativeTo: this.activatedRoute}); 42 | } 43 | 44 | removeCar(id: Long): void { 45 | this.dialogService 46 | .openConfirm({ 47 | title: 'Confirm', 48 | message: 'Are you sure you want to perform this action?' 49 | }) 50 | .afterClosed() 51 | .subscribe((accept: boolean) => { 52 | if (accept) { 53 | this.deleteCarGQL 54 | .mutate( 55 | { 56 | id: id 57 | }, 58 | { 59 | update: (proxy, {data: {deleteCar}}) => { 60 | // Read the data from our cache for this query. 61 | const data: any = proxy.readQuery({query: this.listCarsGQL.document}); 62 | const index = data.cars.map(x => x.id).indexOf(id); 63 | data.cars.splice(index, 1); 64 | // Write our data back to the cache. 65 | proxy.writeQuery({query: this.listCarsGQL.document, data}); 66 | } 67 | } 68 | ) 69 | .subscribe( 70 | (car: Car) => { 71 | console.log(`Car with ID ${car.id} deleted.`); 72 | }, 73 | error => { 74 | console.log('there was an error sending the query', error); 75 | } 76 | ); 77 | } else { 78 | // DO SOMETHING ELSE 79 | } 80 | }); 81 | } 82 | 83 | ngAfterViewInit(): void { 84 | this.dataSource.paginator = this.paginator; 85 | this.dataSource.sort = this.sort; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /frontend/src/app/cars/cars.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { RouterModule, Routes } from '@angular/router'; 4 | import { CarListComponent } from './car-list/car-list.component'; 5 | import { CarEditComponent } from './car-edit/car-edit.component'; 6 | import { MaterialModule } from '../material.module'; 7 | import { FormsModule } from '@angular/forms'; 8 | import { FlexLayoutModule } from '@angular/flex-layout'; 9 | 10 | const routes: Routes = [ 11 | {path: 'cars', component: CarListComponent}, 12 | {path: 'cars/:id', component: CarEditComponent} 13 | ]; 14 | 15 | @NgModule({ 16 | imports: [ 17 | CommonModule, 18 | FormsModule, 19 | MaterialModule, 20 | FlexLayoutModule, 21 | RouterModule.forChild(routes) 22 | ], 23 | declarations: [CarListComponent, CarEditComponent], 24 | providers: [] 25 | }) 26 | export class CarsModule { 27 | } 28 | -------------------------------------------------------------------------------- /frontend/src/app/graphql.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { HttpClientModule } from '@angular/common/http'; 3 | 4 | import { Apollo, ApolloModule } from 'apollo-angular'; 5 | import { HttpLink, HttpLinkModule } from 'apollo-angular-link-http'; 6 | import { InMemoryCache } from 'apollo-cache-inmemory'; 7 | import { ApolloLink } from 'apollo-link'; 8 | 9 | @NgModule({ 10 | exports: [HttpClientModule, ApolloModule, HttpLinkModule] 11 | }) 12 | export class GraphQLModule { 13 | constructor(apollo: Apollo, httpLink: HttpLink) { 14 | const cache = new InMemoryCache(); 15 | const myAppLink: ApolloLink = httpLink.create({ uri: '/graphql' }); 16 | apollo.create({ 17 | link: myAppLink, 18 | cache: cache 19 | }); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /frontend/src/app/graphql/delete-car.graphql: -------------------------------------------------------------------------------- 1 | mutation DeleteCar($id: Long!) { 2 | deleteCar(id: $id) 3 | } 4 | -------------------------------------------------------------------------------- /frontend/src/app/graphql/get-car.graphql: -------------------------------------------------------------------------------- 1 | query GetCar($id: Long!) { 2 | car(id: $id) { 3 | id 4 | name 5 | giphyUrl 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /frontend/src/app/graphql/list-cars.graphql: -------------------------------------------------------------------------------- 1 | query ListCars { 2 | cars { 3 | id 4 | name 5 | giphyUrl 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /frontend/src/app/graphql/save-car.graphql: -------------------------------------------------------------------------------- 1 | mutation SaveCar($car: CarInput!) { 2 | saveCar(car: $car) { 3 | id 4 | name 5 | giphyUrl 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /frontend/src/app/material.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CdkTableModule } from '@angular/cdk/table'; 3 | import { 4 | MatAutocompleteModule, 5 | MatButtonModule, 6 | MatButtonToggleModule, 7 | MatCardModule, 8 | MatCheckboxModule, 9 | MatChipsModule, 10 | MatDatepickerModule, 11 | MatDialogModule, 12 | MatDividerModule, 13 | MatExpansionModule, 14 | MatFormFieldModule, 15 | MatGridListModule, 16 | MatIconModule, 17 | MatInputModule, 18 | MatListModule, 19 | MatMenuModule, 20 | MatPaginatorModule, 21 | MatProgressBarModule, 22 | MatProgressSpinnerModule, 23 | MatRadioModule, 24 | MatSelectModule, 25 | MatSidenavModule, 26 | MatSliderModule, 27 | MatSlideToggleModule, 28 | MatSnackBarModule, 29 | MatSortModule, 30 | MatStepperModule, 31 | MatTableModule, 32 | MatTabsModule, 33 | MatToolbarModule, 34 | MatTooltipModule 35 | } from '@angular/material'; 36 | import { MatRippleModule } from '@angular/material/core'; 37 | 38 | @NgModule({ 39 | exports: [ 40 | // cdk 41 | CdkTableModule, 42 | // material 43 | MatAutocompleteModule, 44 | MatButtonModule, 45 | MatButtonToggleModule, 46 | MatCardModule, 47 | MatCheckboxModule, 48 | MatChipsModule, 49 | MatDatepickerModule, 50 | MatDialogModule, 51 | MatDividerModule, 52 | MatExpansionModule, 53 | MatFormFieldModule, 54 | MatGridListModule, 55 | MatIconModule, 56 | MatInputModule, 57 | MatListModule, 58 | MatMenuModule, 59 | MatPaginatorModule, 60 | MatProgressBarModule, 61 | MatProgressSpinnerModule, 62 | MatRadioModule, 63 | MatSelectModule, 64 | MatSidenavModule, 65 | MatSlideToggleModule, 66 | MatSliderModule, 67 | MatSnackBarModule, 68 | MatSortModule, 69 | MatStepperModule, 70 | MatTableModule, 71 | MatTabsModule, 72 | MatRippleModule, 73 | MatToolbarModule, 74 | MatTooltipModule, 75 | ] 76 | }) 77 | export class MaterialModule { 78 | } 79 | -------------------------------------------------------------------------------- /frontend/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iguissouma/spring-graphql-apollo-angular/2cc1260e3dc0d5cb1f4f0a82968266db516943f7/frontend/src/assets/.gitkeep -------------------------------------------------------------------------------- /frontend/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /frontend/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 | -------------------------------------------------------------------------------- /frontend/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iguissouma/spring-graphql-apollo-angular/2cc1260e3dc0d5cb1f4f0a82968266db516943f7/frontend/src/favicon.ico -------------------------------------------------------------------------------- /frontend/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Frontend 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /frontend/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 | -------------------------------------------------------------------------------- /frontend/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/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | // Add global to window, assigning the value of window itself. 65 | (window as any).global = window; 66 | -------------------------------------------------------------------------------- /frontend/src/styles.css: -------------------------------------------------------------------------------- 1 | @import "~@angular/material/prebuilt-themes/pink-bluegrey.css"; 2 | @import 'https://fonts.googleapis.com/icon?family=Material+Icons'; 3 | 4 | html, body { 5 | display: flex; 6 | flex-direction: column; 7 | font-family: Roboto, Arial, sans-serif; 8 | margin: 0; 9 | height: 100%; 10 | } 11 | -------------------------------------------------------------------------------- /frontend/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/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /frontend/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 | -------------------------------------------------------------------------------- /frontend/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "types": [ 8 | "jasmine", 9 | "node" 10 | ] 11 | }, 12 | "files": [ 13 | "test.ts", 14 | "polyfills.ts" 15 | ], 16 | "include": [ 17 | "**/*.spec.ts", 18 | "**/*.d.ts" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /frontend/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | 4 | interface NodeModule { 5 | id: string; 6 | } 7 | -------------------------------------------------------------------------------- /frontend/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 | "esnext.asynciterable" 18 | ], 19 | "paths": { 20 | "@app/*": ["app/*"] 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /frontend/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 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-shadowed-variable": true, 69 | "no-string-literal": false, 70 | "no-string-throw": true, 71 | "no-switch-case-fall-through": true, 72 | "no-trailing-whitespace": true, 73 | "no-unnecessary-initializer": true, 74 | "no-unused-expression": true, 75 | "no-use-before-declare": true, 76 | "no-var-keyword": true, 77 | "object-literal-sort-keys": false, 78 | "one-line": [ 79 | true, 80 | "check-open-brace", 81 | "check-catch", 82 | "check-else", 83 | "check-whitespace" 84 | ], 85 | "prefer-const": true, 86 | "quotemark": [ 87 | true, 88 | "single" 89 | ], 90 | "radix": true, 91 | "semicolon": [ 92 | true, 93 | "always" 94 | ], 95 | "triple-equals": [ 96 | true, 97 | "allow-null-check" 98 | ], 99 | "typedef-whitespace": [ 100 | true, 101 | { 102 | "call-signature": "nospace", 103 | "index-signature": "nospace", 104 | "parameter": "nospace", 105 | "property-declaration": "nospace", 106 | "variable-declaration": "nospace" 107 | } 108 | ], 109 | "unified-signatures": true, 110 | "variable-name": false, 111 | "whitespace": [ 112 | true, 113 | "check-branch", 114 | "check-decl", 115 | "check-operator", 116 | "check-separator", 117 | "check-type" 118 | ], 119 | "directive-selector": [ 120 | true, 121 | "attribute", 122 | "app", 123 | "camelCase" 124 | ], 125 | "component-selector": [ 126 | true, 127 | "element", 128 | "app", 129 | "kebab-case" 130 | ], 131 | "no-output-on-prefix": true, 132 | "use-input-property-decorator": true, 133 | "use-output-property-decorator": true, 134 | "use-host-property-decorator": true, 135 | "no-input-rename": true, 136 | "no-output-rename": true, 137 | "use-life-cycle-interface": true, 138 | "use-pipe-transform-interface": true, 139 | "component-class-suffix": true, 140 | "directive-class-suffix": true 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /server/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ -------------------------------------------------------------------------------- /server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iguissouma/spring-graphql-apollo-angular/2cc1260e3dc0d5cb1f4f0a82968266db516943f7/server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /server/graphql.config.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "README_schema" : "Specifies how to load the GraphQL schema that completion, error highlighting, and documentation is based on in the IDE", 4 | "schema": { 5 | "README_request" : "To request the schema from a url instead, remove the 'file' JSON property above (and optionally delete the default graphql.schema.json file).", 6 | "request": { 7 | "url" : "http://localhost:8080/graphql", 8 | "method" : "POST", 9 | "README_postIntrospectionQuery" : "Whether to POST an introspectionQuery to the url. If the url always returns the schema JSON, set to false and consider using GET", 10 | "postIntrospectionQuery" : true, 11 | "README_options" : "See the 'Options' section at https://github.com/then/then-request", 12 | "options" : { 13 | "headers": { 14 | "user-agent" : "JS GraphQL" 15 | } 16 | } 17 | } 18 | 19 | }, 20 | 21 | "README_endpoints": "A list of GraphQL endpoints that can be queried from '.graphql' files in the IDE", 22 | "endpoints" : [ 23 | { 24 | "name": "Default (http://localhost:8080/graphql)", 25 | "url": "http://localhost:8080/graphql", 26 | "options" : { 27 | "headers": { 28 | "user-agent" : "JS GraphQL" 29 | } 30 | } 31 | } 32 | ] 33 | 34 | } -------------------------------------------------------------------------------- /server/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /server/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.igu.developer 7 | demo 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | demo 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 0.10.0 26 | 0.0.4 27 | 2.8.5 28 | 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-data-jpa 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-web 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-websocket 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-actuator 46 | 47 | 48 | 49 | com.h2database 50 | h2 51 | runtime 52 | 53 | 54 | org.projectlombok 55 | lombok 56 | true 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-starter-test 61 | test 62 | 63 | 64 | io.leangen.graphql 65 | graphql-spqr-spring-boot-starter 66 | ${spqr-starter.version} 67 | 68 | 69 | com.google.code.gson 70 | gson 71 | ${gson.version} 72 | 73 | 74 | 75 | 76 | 77 | 78 | org.springframework.boot 79 | spring-boot-maven-plugin 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /server/src/main/java/com/igu/developer/demo/Car.java: -------------------------------------------------------------------------------- 1 | package com.igu.developer.demo; 2 | 3 | import io.leangen.graphql.annotations.GraphQLQuery; 4 | import lombok.*; 5 | 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | 10 | @Entity 11 | @Getter @Setter 12 | @NoArgsConstructor 13 | @ToString @EqualsAndHashCode 14 | public class Car { 15 | @Id @GeneratedValue 16 | @GraphQLQuery(name = "id", description = "A car's id") 17 | private Long id; 18 | @GraphQLQuery(name = "name", description = "A car's name") 19 | private @NonNull String name; 20 | } -------------------------------------------------------------------------------- /server/src/main/java/com/igu/developer/demo/CarRepository.java: -------------------------------------------------------------------------------- 1 | package com.igu.developer.demo; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | @Repository 7 | interface CarRepository extends JpaRepository { 8 | } -------------------------------------------------------------------------------- /server/src/main/java/com/igu/developer/demo/CarService.java: -------------------------------------------------------------------------------- 1 | package com.igu.developer.demo; 2 | 3 | import io.leangen.graphql.annotations.GraphQLArgument; 4 | import io.leangen.graphql.annotations.GraphQLContext; 5 | import io.leangen.graphql.annotations.GraphQLMutation; 6 | import io.leangen.graphql.annotations.GraphQLQuery; 7 | import io.leangen.graphql.spqr.spring.annotations.GraphQLApi; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | import java.util.Optional; 12 | 13 | @Service 14 | @GraphQLApi 15 | public class CarService { 16 | 17 | private final CarRepository carRepository; 18 | private final GiphyService giphyService; 19 | 20 | public CarService(CarRepository carRepository, GiphyService giphyService) { 21 | this.carRepository = carRepository; 22 | this.giphyService = giphyService; 23 | } 24 | 25 | @GraphQLQuery(name = "cars") 26 | public List getCars() { 27 | return carRepository.findAll(); 28 | } 29 | 30 | @GraphQLQuery(name = "car") 31 | public Optional getCarById(@GraphQLArgument(name = "id") Long id) { 32 | return carRepository.findById(id); 33 | } 34 | 35 | @GraphQLMutation(name = "saveCar") 36 | public Car saveCar(@GraphQLArgument(name = "car") Car car) { 37 | return carRepository.save(car); 38 | } 39 | 40 | @GraphQLMutation(name = "deleteCar") 41 | public Boolean deleteCar(@GraphQLArgument(name = "id") Long id) { 42 | carRepository.deleteById(id); 43 | return Boolean.TRUE; 44 | } 45 | 46 | @GraphQLQuery(name = "isCool") 47 | public boolean isCool(@GraphQLContext Car car) { 48 | return !car.getName().equals("AMC Gremlin") && 49 | !car.getName().equals("Triumph Stag") && 50 | !car.getName().equals("Ford Pinto") && 51 | !car.getName().equals("Yugo GV"); 52 | } 53 | 54 | @GraphQLQuery(name = "giphyUrl") 55 | public String getGiphyUrl(@GraphQLContext Car car) { 56 | return giphyService.getGiphyUrl(car.getName()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /server/src/main/java/com/igu/developer/demo/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.igu.developer.demo; 2 | 3 | import org.springframework.boot.ApplicationRunner; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.Bean; 7 | 8 | import java.util.stream.Stream; 9 | 10 | @SpringBootApplication 11 | public class DemoApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(DemoApplication.class, args); 15 | } 16 | 17 | @Bean 18 | ApplicationRunner init(CarService carService) { 19 | return args -> { 20 | Stream.of("Ferrari", "Jaguar", "Porsche", "Lamborghini", "Bugatti", 21 | "AMC Gremlin", "Triumph Stag", "Ford Pinto", "Yugo GV").forEach(name -> { 22 | Car car = new Car(); 23 | car.setName(name); 24 | carService.saveCar(car); 25 | }); 26 | carService.getCars().forEach(System.out::println); 27 | }; 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /server/src/main/java/com/igu/developer/demo/GiphyService.java: -------------------------------------------------------------------------------- 1 | package com.igu.developer.demo; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.JsonArray; 5 | import com.google.gson.JsonObject; 6 | import org.springframework.http.HttpEntity; 7 | import org.springframework.http.HttpMethod; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.util.LinkedMultiValueMap; 11 | import org.springframework.util.MultiValueMap; 12 | import org.springframework.web.client.RestTemplate; 13 | import org.springframework.web.util.UriComponentsBuilder; 14 | 15 | import java.net.URI; 16 | 17 | @Service 18 | public class GiphyService { 19 | 20 | private RestTemplate rest = new RestTemplate(); 21 | public static final String GIPHY_BASE = "http://api.giphy.com/v1/gifs/search?q="; 22 | public static final String KEY = "&api_key=dc6zaTOxFJmzC"; 23 | 24 | public String getGiphyUrl(String searchTerm) { 25 | Gson gson = new Gson(); 26 | String giphy = GIPHY_BASE + searchTerm + KEY; 27 | try { 28 | URI uri = UriComponentsBuilder.fromUriString(giphy).build().encode().toUri(); 29 | MultiValueMap mvm = new LinkedMultiValueMap(); 30 | ResponseEntity res = rest.exchange(uri, HttpMethod.GET, new HttpEntity(mvm, null), String.class); 31 | 32 | JsonObject json = gson.fromJson(res.getBody(), JsonObject.class); 33 | JsonArray data = json.getAsJsonArray("data"); 34 | if (data == null || data.size() == 0) { 35 | return "https://media.giphy.com/media/EFXGvbDPhLoWs/giphy.gif"; 36 | } 37 | JsonObject images = ((JsonObject) data.get(0)).getAsJsonObject("images"); 38 | JsonObject original = images.getAsJsonObject("original"); 39 | return original.getAsJsonPrimitive("url").getAsString(); 40 | 41 | } catch (Throwable e) { 42 | return "https://media.giphy.com/media/EFXGvbDPhLoWs/giphy.gif"; 43 | } 44 | 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | graphql.spqr.gui.enabled=true 2 | -------------------------------------------------------------------------------- /server/src/test/java/com/igu/developer/demo/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.igu.developer.demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------