├── apollo-client ├── src │ ├── assets │ │ ├── .gitkeep │ │ └── .npmignore │ ├── app │ │ ├── shared │ │ │ └── index.ts │ │ ├── app.component.css │ │ ├── dog │ │ │ ├── dog.component.css │ │ │ ├── dog.component.html │ │ │ ├── dog.component.ts │ │ │ └── dog.component.spec.ts │ │ ├── index.ts │ │ ├── app.component.html │ │ ├── app.module.ts │ │ ├── app.component.ts │ │ └── app.component.spec.ts │ ├── styles.css │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── typings.d.ts │ ├── index.html │ ├── main.ts │ ├── tsconfig.json │ ├── polyfills.ts │ └── test.ts ├── typings.json ├── Dockerfile ├── e2e │ ├── app.po.ts │ ├── app.e2e-spec.ts │ └── tsconfig.json ├── .editorconfig ├── .gitignore ├── protractor.conf.js ├── angular-cli.json ├── karma.conf.js ├── README.md ├── package.json └── tslint.json ├── .gitignore ├── dogs-api ├── Dockerfile ├── package.json └── index.js ├── apollo-server ├── Dockerfile ├── connectors.js ├── resolvers.js ├── .eslintrc.json ├── package.json ├── index.koa.js ├── index.js └── schema.js └── docker-compose.yml /apollo-client/src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /apollo-client/src/app/shared/index.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /apollo-client/src/assets/.npmignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | log 3 | .vscode -------------------------------------------------------------------------------- /apollo-client/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /apollo-client/src/app/dog/dog.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /apollo-client/src/app/index.ts: -------------------------------------------------------------------------------- 1 | export * from './app.component'; 2 | export * from './app.module'; 3 | -------------------------------------------------------------------------------- /apollo-client/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ -------------------------------------------------------------------------------- /apollo-client/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /apollo-client/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codegram/apollo-example/master/apollo-client/src/favicon.ico -------------------------------------------------------------------------------- /apollo-client/typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "graphql": "registry:npm/graphql#0.5.0+20160602041655" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /dogs-api/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:6.6.0 2 | MAINTAINER david.morcillo@codegram.com 3 | 4 | WORKDIR /code 5 | 6 | RUN npm install -g nodemon 7 | 8 | CMD npm start 9 | -------------------------------------------------------------------------------- /apollo-server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:6.6.0 2 | MAINTAINER david.morcillo@codegram.com 3 | 4 | WORKDIR /code 5 | 6 | RUN npm install -g nodemon 7 | 8 | CMD npm start 9 | -------------------------------------------------------------------------------- /apollo-client/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |

2 | {{title}} 3 |

4 | 5 | 10 | -------------------------------------------------------------------------------- /apollo-client/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:6.6.0 2 | MAINTAINER david.morcillo@codegram.com 3 | 4 | WORKDIR /code 5 | 6 | RUN npm install -g angular-cli 7 | 8 | CMD ng serve --host 0.0.0.0 --port 8080 9 | -------------------------------------------------------------------------------- /apollo-server/connectors.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | Dog: { 3 | find() { 4 | // TODO: buscar a la bd 5 | return { 6 | name: "Boira", 7 | age: 6 8 | } 9 | } 10 | } 11 | }; -------------------------------------------------------------------------------- /apollo-server/resolvers.js: -------------------------------------------------------------------------------- 1 | const { Dog } = require('./connectors'); 2 | 3 | const resolveFunctions = { 4 | RootQuery: { 5 | dog() { 6 | return Dog.find(); 7 | } 8 | } 9 | }; 10 | 11 | module.exports = resolveFunctions; -------------------------------------------------------------------------------- /apollo-client/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | // Typings reference file, see links for more information 2 | // https://github.com/typings/typings 3 | // https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html 4 | 5 | declare var System: any; 6 | -------------------------------------------------------------------------------- /apollo-client/e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, element, by } from 'protractor/globals'; 2 | 3 | export class ApolloClientPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /apollo-client/src/app/dog/dog.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /apollo-client/.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 | end_of_line = lf 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [*.md] 13 | max_line_length = 0 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /apollo-client/src/app/dog/dog.component.ts: -------------------------------------------------------------------------------- 1 | import { Input, Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-dog', 5 | templateUrl: './dog.component.html', 6 | styleUrls: ['./dog.component.css'] 7 | }) 8 | export class DogComponent implements OnInit { 9 | @Input() dog: any; 10 | 11 | constructor() { } 12 | 13 | ngOnInit() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /apollo-client/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ApolloClient 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Loading... 14 | 15 | 16 | -------------------------------------------------------------------------------- /apollo-client/src/app/dog/dog.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | 3 | import { TestBed, async } from '@angular/core/testing'; 4 | import { DogComponent } from './dog.component'; 5 | 6 | describe('Component: Dog', () => { 7 | it('should create an instance', () => { 8 | let component = new DogComponent(); 9 | expect(component).toBeTruthy(); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /apollo-client/e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { ApolloClientPage } from './app.po'; 2 | 3 | describe('apollo-client App', function() { 4 | let page: ApolloClientPage; 5 | 6 | beforeEach(() => { 7 | page = new ApolloClientPage(); 8 | }); 9 | 10 | it('should display message saying app works', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('app works!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /apollo-client/src/main.ts: -------------------------------------------------------------------------------- 1 | import './polyfills.ts'; 2 | 3 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 4 | import { enableProdMode } from '@angular/core'; 5 | import { environment } from './environments/environment'; 6 | import { AppModule } from './app/'; 7 | 8 | if (environment.production) { 9 | enableProdMode(); 10 | } 11 | 12 | platformBrowserDynamic().bootstrapModule(AppModule); 13 | -------------------------------------------------------------------------------- /dogs-api/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "code", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "express": "^4.14.0", 8 | "express-json": "^1.0.0" 9 | }, 10 | "devDependencies": {}, 11 | "scripts": { 12 | "start": "nodemon index.js", 13 | "test": "echo \"Error: no test specified\" && exit 1" 14 | }, 15 | "author": "", 16 | "license": "ISC" 17 | } 18 | -------------------------------------------------------------------------------- /apollo-client/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "declaration": false, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "module": "commonjs", 8 | "moduleResolution": "node", 9 | "outDir": "../dist/out-tsc-e2e", 10 | "sourceMap": true, 11 | "target": "es5", 12 | "typeRoots": [ 13 | "../node_modules/@types" 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /apollo-client/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 | -------------------------------------------------------------------------------- /apollo-client/src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": false, 4 | "emitDecoratorMetadata": true, 5 | "experimentalDecorators": true, 6 | "lib": ["es6", "dom"], 7 | "mapRoot": "./", 8 | "module": "es6", 9 | "moduleResolution": "node", 10 | "outDir": "../dist/out-tsc", 11 | "sourceMap": true, 12 | "target": "es5", 13 | "typeRoots": [ 14 | "../node_modules/@types" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | server: 4 | build: apollo-server 5 | ports: 6 | - 3000:3000 7 | volumes: 8 | - ./apollo-server:/code 9 | links: 10 | - dogs-api 11 | client: 12 | build: apollo-client 13 | ports: 14 | - 8080:8080 15 | volumes: 16 | - ./apollo-client:/code 17 | dogs-api: 18 | build: dogs-api 19 | ports: 20 | - 4000:4000 21 | volumes: 22 | - ./dogs-api:/code -------------------------------------------------------------------------------- /apollo-client/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | 7 | # dependencies 8 | /node_modules 9 | /bower_components 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | *.launch 16 | .settings/ 17 | 18 | # misc 19 | /.sass-cache 20 | /connect.lock 21 | /coverage/* 22 | /libpeerconnection.log 23 | npm-debug.log 24 | testem.log 25 | /typings 26 | 27 | # e2e 28 | /e2e/*.js 29 | /e2e/*.map 30 | 31 | #System Files 32 | .DS_Store 33 | Thumbs.db 34 | -------------------------------------------------------------------------------- /apollo-server/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "commonjs": true, 5 | "es6": true, 6 | "node": true 7 | }, 8 | "parserOptions": { 9 | "ecmaFeatures": { 10 | "jsx": true 11 | }, 12 | "sourceType": "module" 13 | }, 14 | "rules": { 15 | "no-const-assign": "warn", 16 | "no-this-before-super": "warn", 17 | "no-undef": "warn", 18 | "no-unreachable": "warn", 19 | "no-unused-vars": "warn", 20 | "constructor-super": "warn", 21 | "valid-typeof": "warn" 22 | } 23 | } -------------------------------------------------------------------------------- /apollo-client/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | // This file includes polyfills needed by Angular 2 and is loaded before 2 | // the app. You can add your own extra polyfills to this file. 3 | import 'core-js/es6/symbol'; 4 | import 'core-js/es6/object'; 5 | import 'core-js/es6/function'; 6 | import 'core-js/es6/parse-int'; 7 | import 'core-js/es6/parse-float'; 8 | import 'core-js/es6/number'; 9 | import 'core-js/es6/math'; 10 | import 'core-js/es6/string'; 11 | import 'core-js/es6/date'; 12 | import 'core-js/es6/array'; 13 | import 'core-js/es6/regexp'; 14 | import 'core-js/es6/map'; 15 | import 'core-js/es6/set'; 16 | import 'core-js/es6/reflect'; 17 | 18 | import 'core-js/es7/reflect'; 19 | import 'zone.js/dist/zone'; 20 | -------------------------------------------------------------------------------- /apollo-server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-server", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "apollo-server": "^0.3.2", 8 | "body-parser": "^1.15.2", 9 | "express": "^4.14.0", 10 | "express-cors": "0.0.3", 11 | "graphql": "^0.7.0", 12 | "graphql-tools": "^0.7.2", 13 | "koa": "^1.2.4", 14 | "koa-bodyparser": "^2.2.0", 15 | "koa-router": "^5.4.0", 16 | "superagent": "^2.3.0" 17 | }, 18 | "devDependencies": {}, 19 | "scripts": { 20 | "start": "nodemon index.js", 21 | "test": "echo \"Error: no test specified\" && exit 1" 22 | }, 23 | "author": "", 24 | "license": "ISC" 25 | } 26 | -------------------------------------------------------------------------------- /apollo-server/index.koa.js: -------------------------------------------------------------------------------- 1 | const koa = require('koa'); 2 | const koaRouter = require('koa-router'); 3 | const koaBody = require('koa-bodyparser'); 4 | 5 | const { apolloKoa, graphiqlKoa } = require('apollo-server'); 6 | 7 | const app = new koa(); 8 | const router = new koaRouter(); 9 | const PORT = 3000; 10 | 11 | const myGraphQLSchema = require('./schema'); 12 | const myGraphQLResolvers = require('./resolvers'); 13 | 14 | app.use(koaBody()); 15 | 16 | router.post('/graphql', apolloKoa({ 17 | pretty: true, 18 | schema: myGraphQLSchema, 19 | resolvers: myGraphQLResolvers 20 | })); 21 | router.get('/graphiql', graphiqlKoa({ 22 | endpointURL: '/graphql' 23 | })); 24 | 25 | app.use(router.routes()); 26 | app.use(router.allowedMethods()); 27 | app.listen(PORT); 28 | 29 | console.log(`Listening on port ${PORT}...`); -------------------------------------------------------------------------------- /apollo-server/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const bodyParser = require('body-parser'); 3 | 4 | const { apolloExpress, graphiqlExpress } = require('apollo-server'); 5 | const Schema = require('./schema'); 6 | const Resolvers = require('./resolvers'); 7 | 8 | const GRAPHQL_PORT = 3000; 9 | 10 | const cors = require('express-cors'); 11 | 12 | var graphQLServer = express(); 13 | 14 | graphQLServer.use(cors({ 15 | allowedOrigins: [ 16 | 'localhost:8080' 17 | ] 18 | })); 19 | 20 | graphQLServer.use('/graphql', bodyParser.json(), apolloExpress({ 21 | schema: Schema 22 | })); 23 | 24 | graphQLServer.use('/graphiql', bodyParser.json(), graphiqlExpress({ 25 | endpointURL: '/graphql', 26 | })); 27 | 28 | graphQLServer.listen(GRAPHQL_PORT, () => console.log( 29 | `GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}/graphql` 30 | )); -------------------------------------------------------------------------------- /apollo-client/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/docs/referenceConf.js 3 | 4 | /*global jasmine */ 5 | var SpecReporter = require('jasmine-spec-reporter'); 6 | 7 | exports.config = { 8 | allScriptsTimeout: 11000, 9 | specs: [ 10 | './e2e/**/*.e2e-spec.ts' 11 | ], 12 | capabilities: { 13 | 'browserName': 'chrome' 14 | }, 15 | directConnect: true, 16 | baseUrl: 'http://localhost:4200/', 17 | framework: 'jasmine', 18 | jasmineNodeOpts: { 19 | showColors: true, 20 | defaultTimeoutInterval: 30000, 21 | print: function() {} 22 | }, 23 | useAllAngular2AppRoots: true, 24 | beforeLaunch: function() { 25 | require('ts-node').register({ 26 | project: 'e2e' 27 | }); 28 | }, 29 | onPrepare: function() { 30 | jasmine.getEnv().addReporter(new SpecReporter()); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /apollo-client/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { HttpModule } from '@angular/http'; 5 | 6 | import ApolloClient, { createNetworkInterface } from 'apollo-client'; 7 | const client = new ApolloClient({ 8 | networkInterface: createNetworkInterface('http://localhost:3000/graphql'), 9 | }); 10 | import { ApolloModule } from 'angular2-apollo'; 11 | 12 | import { AppComponent } from './app.component'; 13 | import { DogComponent } from './dog/dog.component'; 14 | 15 | @NgModule({ 16 | declarations: [ 17 | AppComponent, 18 | DogComponent 19 | ], 20 | imports: [ 21 | BrowserModule, 22 | FormsModule, 23 | HttpModule, 24 | ApolloModule.withClient(client) 25 | ], 26 | providers: [], 27 | bootstrap: [AppComponent] 28 | }) 29 | export class AppModule { } 30 | -------------------------------------------------------------------------------- /apollo-client/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Angular2Apollo } from 'angular2-apollo'; 3 | import gql from 'graphql-tag'; 4 | 5 | const DogAndFriends = gql` 6 | query { 7 | dogs { 8 | name, 9 | age, 10 | friends { 11 | age, 12 | name, 13 | friends { 14 | age, 15 | name 16 | } 17 | } 18 | } 19 | } 20 | ` 21 | 22 | @Component({ 23 | selector: 'app-root', 24 | templateUrl: './app.component.html', 25 | styleUrls: ['./app.component.css'] 26 | }) 27 | export class AppComponent implements OnInit { 28 | title = 'Dogsbook'; 29 | dogs: any[]; 30 | 31 | constructor(private apollo: Angular2Apollo) {} 32 | 33 | ngOnInit() { 34 | this.apollo.watchQuery({ 35 | query: DogAndFriends 36 | }).subscribe(({ data }) => { 37 | this.dogs = data.dogs; 38 | }) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /apollo-client/angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": { 3 | "version": "1.0.0-beta.15", 4 | "name": "apollo-client" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": "assets", 11 | "index": "index.html", 12 | "main": "main.ts", 13 | "test": "test.ts", 14 | "tsconfig": "tsconfig.json", 15 | "prefix": "app", 16 | "mobile": false, 17 | "styles": [ 18 | "styles.css" 19 | ], 20 | "scripts": [], 21 | "environments": { 22 | "source": "environments/environment.ts", 23 | "dev": "environments/environment.ts", 24 | "prod": "environments/environment.prod.ts" 25 | } 26 | } 27 | ], 28 | "addons": [], 29 | "packages": [], 30 | "e2e": { 31 | "protractor": { 32 | "config": "./protractor.conf.js" 33 | } 34 | }, 35 | "test": { 36 | "karma": { 37 | "config": "./karma.conf.js" 38 | } 39 | }, 40 | "defaults": { 41 | "styleExt": "css", 42 | "prefixInterfaces": false 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /dogs-api/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var app = express(); 3 | var json = require('express-json'); 4 | 5 | const DOGS = [ 6 | { 7 | id: 1, 8 | name: "Boira", 9 | age: 6, 10 | friends: [2] 11 | }, 12 | { 13 | id: 2, 14 | name: "Nona", 15 | age: 10, 16 | friends: [] 17 | }, 18 | { 19 | id: 3, 20 | name: "Sot", 21 | age: 7, 22 | friends: [1,2] 23 | } 24 | ]; 25 | 26 | app.use(json()); 27 | 28 | app.get('/dogs', function (req, res) { 29 | let ids = req.query.ids; 30 | let dogs = DOGS; 31 | 32 | if (ids !== 'undefined') { 33 | idgs = ids.split(',').map(i => parseInt(i, 10)); 34 | dogs = dogs.filter(dog => ids.includes(dog.id)); 35 | } 36 | 37 | res.send({ dogs }); 38 | }); 39 | 40 | app.get('/dogs/:id/friends', function (req, res) { 41 | let dog = DOGS.find(dog => dog.id === parseInt(req.params.id, 10)); 42 | let { friends } = dog; 43 | 44 | res.send({ dogs: DOGS.filter(dog => friends.includes(dog.id)) }); 45 | }); 46 | 47 | app.listen(4000, function () { 48 | console.log('Example app listening on port 4000!'); 49 | }); -------------------------------------------------------------------------------- /apollo-client/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/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-remap-istanbul'), 12 | require('angular-cli/plugins/karma') 13 | ], 14 | files: [ 15 | { pattern: './src/test.ts', watched: false } 16 | ], 17 | preprocessors: { 18 | './src/test.ts': ['angular-cli'] 19 | }, 20 | remapIstanbulReporter: { 21 | reports: { 22 | html: 'coverage', 23 | lcovonly: './coverage/coverage.lcov' 24 | } 25 | }, 26 | angularCli: { 27 | config: './angular-cli.json', 28 | environment: 'dev' 29 | }, 30 | reporters: ['progress', 'karma-remap-istanbul'], 31 | port: 9876, 32 | colors: true, 33 | logLevel: config.LOG_INFO, 34 | autoWatch: true, 35 | browsers: ['Chrome'], 36 | singleRun: false 37 | }); 38 | }; 39 | -------------------------------------------------------------------------------- /apollo-client/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | 3 | import { TestBed, async } from '@angular/core/testing'; 4 | import { AppComponent } from './app.component'; 5 | 6 | describe('App: ApolloClient', () => { 7 | beforeEach(() => { 8 | TestBed.configureTestingModule({ 9 | declarations: [ 10 | AppComponent 11 | ], 12 | }); 13 | }); 14 | 15 | it('should create the app', async(() => { 16 | let fixture = TestBed.createComponent(AppComponent); 17 | let app = fixture.debugElement.componentInstance; 18 | expect(app).toBeTruthy(); 19 | })); 20 | 21 | it(`should have as title 'app works!'`, async(() => { 22 | let fixture = TestBed.createComponent(AppComponent); 23 | let app = fixture.debugElement.componentInstance; 24 | expect(app.title).toEqual('app works!'); 25 | })); 26 | 27 | it('should render title in a h1 tag', async(() => { 28 | let fixture = TestBed.createComponent(AppComponent); 29 | fixture.detectChanges(); 30 | let compiled = fixture.debugElement.nativeElement; 31 | expect(compiled.querySelector('h1').textContent).toContain('app works!'); 32 | })); 33 | }); 34 | -------------------------------------------------------------------------------- /apollo-client/src/test.ts: -------------------------------------------------------------------------------- 1 | import './polyfills.ts'; 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 | 10 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 11 | declare var __karma__: any; 12 | declare var require: any; 13 | 14 | // Prevent Karma from running prematurely. 15 | __karma__.loaded = function () {}; 16 | 17 | 18 | Promise.all([ 19 | System.import('@angular/core/testing'), 20 | System.import('@angular/platform-browser-dynamic/testing') 21 | ]) 22 | // First, initialize the Angular testing environment. 23 | .then(([testing, testingBrowser]) => { 24 | testing.getTestBed().initTestEnvironment( 25 | testingBrowser.BrowserDynamicTestingModule, 26 | testingBrowser.platformBrowserDynamicTesting() 27 | ); 28 | }) 29 | // Then we find all the tests. 30 | .then(() => require.context('./', true, /\.spec\.ts/)) 31 | // And load the modules. 32 | .then(context => context.keys().map(context)) 33 | // Finally, start Karma to run the tests. 34 | .then(__karma__.start, __karma__.error); 35 | -------------------------------------------------------------------------------- /apollo-client/README.md: -------------------------------------------------------------------------------- 1 | # ApolloClient 2 | 3 | This project was generated with [angular-cli](https://github.com/angular/angular-cli) version 1.0.0-beta.15. 4 | 5 | ## Development server 6 | 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. 7 | 8 | ## Code scaffolding 9 | 10 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive/pipe/service/class`. 11 | 12 | ## Build 13 | 14 | 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. 15 | 16 | ## Running unit tests 17 | 18 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 19 | 20 | ## Running end-to-end tests 21 | 22 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 23 | Before running the tests make sure you are serving the app via `ng serve`. 24 | 25 | ## Deploying to Github Pages 26 | 27 | Run `ng github-pages:deploy` to deploy to Github Pages. 28 | 29 | ## Further help 30 | 31 | 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). 32 | -------------------------------------------------------------------------------- /apollo-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dogsbook", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "angular-cli": {}, 6 | "scripts": { 7 | "start": "ng serve", 8 | "lint": "tslint \"src/**/*.ts\"", 9 | "test": "ng test", 10 | "pree2e": "webdriver-manager update", 11 | "e2e": "protractor" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/common": "2.0.0", 16 | "@angular/compiler": "2.0.0", 17 | "@angular/core": "2.0.0", 18 | "@angular/forms": "2.0.0", 19 | "@angular/http": "2.0.0", 20 | "@angular/platform-browser": "2.0.0", 21 | "@angular/platform-browser-dynamic": "2.0.0", 22 | "@angular/router": "3.0.0", 23 | "angular2-apollo": "^0.4.6", 24 | "apollo-client": "^0.4.19", 25 | "core-js": "^2.4.1", 26 | "graphql-tag": "^0.1.14", 27 | "rxjs": "5.0.0-beta.12", 28 | "ts-helpers": "^1.1.1", 29 | "zone.js": "^0.6.23" 30 | }, 31 | "devDependencies": { 32 | "@types/jasmine": "^2.2.30", 33 | "angular-cli": "1.0.0-beta.15", 34 | "codelyzer": "~0.0.26", 35 | "jasmine-core": "2.4.1", 36 | "jasmine-spec-reporter": "2.5.0", 37 | "karma": "1.2.0", 38 | "karma-chrome-launcher": "^2.0.0", 39 | "karma-cli": "^1.0.1", 40 | "karma-jasmine": "^1.0.2", 41 | "karma-remap-istanbul": "^0.2.1", 42 | "protractor": "4.0.5", 43 | "ts-node": "1.2.1", 44 | "tslint": "3.13.0", 45 | "typescript": "2.0.2" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /apollo-server/schema.js: -------------------------------------------------------------------------------- 1 | const superagent = require('superagent'); 2 | 3 | const { makeExecutableSchema } = require('graphql-tools'); 4 | const { addResolveFunctionsToSchema } = require('graphql-tools'); 5 | 6 | const logger = { log: (e) => console.log(e) }; 7 | 8 | const typeDefs = [` 9 | schema { 10 | query: RootQuery 11 | } 12 | 13 | type RootQuery { 14 | dogs(ids: [Int]): [Dog] 15 | } 16 | 17 | type Dog { 18 | id: Int, 19 | name: String 20 | age: Int, 21 | friends: [Dog] 22 | } 23 | `]; 24 | 25 | const connectors = { 26 | Dog: { 27 | findAll({ ids }) { 28 | return new Promise ((resolve, reject) => { 29 | superagent 30 | .get(`http://dogs-api:4000/dogs?ids=${ids}`) 31 | .end(function (err, res) { 32 | resolve(JSON.parse(res.text).dogs); 33 | }); 34 | }); 35 | }, 36 | findFriends({ id }) { 37 | return new Promise ((resolve, reject) => { 38 | superagent 39 | .get(`http://dogs-api:4000/dogs/${id}/friends`) 40 | .end(function (err, res) { 41 | resolve(JSON.parse(res.text).dogs); 42 | }); 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | const resolvers = { 49 | RootQuery: { 50 | dogs(root, { ids }) { 51 | return connectors.Dog.findAll({ ids }); 52 | } 53 | }, 54 | Dog: { 55 | friends(dog) { 56 | return connectors.Dog.findFriends(dog); 57 | } 58 | } 59 | }; 60 | 61 | 62 | 63 | const jsSchema = makeExecutableSchema({ 64 | typeDefs, 65 | resolvers, 66 | logger 67 | }); 68 | 69 | module.exports = jsSchema; -------------------------------------------------------------------------------- /apollo-client/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "class-name": true, 7 | "comment-format": [ 8 | true, 9 | "check-space" 10 | ], 11 | "curly": true, 12 | "eofline": true, 13 | "forin": true, 14 | "indent": [ 15 | true, 16 | "spaces" 17 | ], 18 | "label-position": true, 19 | "label-undefined": true, 20 | "max-line-length": [ 21 | true, 22 | 140 23 | ], 24 | "member-access": false, 25 | "member-ordering": [ 26 | true, 27 | "static-before-instance", 28 | "variables-before-functions" 29 | ], 30 | "no-arg": true, 31 | "no-bitwise": true, 32 | "no-console": [ 33 | true, 34 | "debug", 35 | "info", 36 | "time", 37 | "timeEnd", 38 | "trace" 39 | ], 40 | "no-construct": true, 41 | "no-debugger": true, 42 | "no-duplicate-key": true, 43 | "no-duplicate-variable": true, 44 | "no-empty": false, 45 | "no-eval": true, 46 | "no-inferrable-types": true, 47 | "no-shadowed-variable": true, 48 | "no-string-literal": false, 49 | "no-switch-case-fall-through": true, 50 | "no-trailing-whitespace": true, 51 | "no-unused-expression": true, 52 | "no-unused-variable": true, 53 | "no-unreachable": true, 54 | "no-use-before-declare": true, 55 | "no-var-keyword": true, 56 | "object-literal-sort-keys": false, 57 | "one-line": [ 58 | true, 59 | "check-open-brace", 60 | "check-catch", 61 | "check-else", 62 | "check-whitespace" 63 | ], 64 | "quotemark": [ 65 | true, 66 | "single" 67 | ], 68 | "radix": true, 69 | "semicolon": [ 70 | "always" 71 | ], 72 | "triple-equals": [ 73 | true, 74 | "allow-null-check" 75 | ], 76 | "typedef-whitespace": [ 77 | true, 78 | { 79 | "call-signature": "nospace", 80 | "index-signature": "nospace", 81 | "parameter": "nospace", 82 | "property-declaration": "nospace", 83 | "variable-declaration": "nospace" 84 | } 85 | ], 86 | "variable-name": false, 87 | "whitespace": [ 88 | true, 89 | "check-branch", 90 | "check-decl", 91 | "check-operator", 92 | "check-separator", 93 | "check-type" 94 | ], 95 | 96 | "directive-selector-prefix": [true, "app"], 97 | "component-selector-prefix": [true, "app"], 98 | "directive-selector-name": [true, "camelCase"], 99 | "component-selector-name": [true, "kebab-case"], 100 | "directive-selector-type": [true, "attribute"], 101 | "component-selector-type": [true, "element"], 102 | "use-input-property-decorator": true, 103 | "use-output-property-decorator": true, 104 | "use-host-property-decorator": true, 105 | "no-input-rename": true, 106 | "no-output-rename": true, 107 | "use-life-cycle-interface": true, 108 | "use-pipe-transform-interface": true, 109 | "component-class-suffix": true, 110 | "directive-class-suffix": true 111 | } 112 | } 113 | --------------------------------------------------------------------------------