Merge pull request #1 from flotte-goes-smart/dev
typeorm: connected to postgres with typeormpull/4/head
commit
7ce786d3d9
@ -1,81 +1,83 @@
|
|||||||
const {src, dest, watch, series, task} = require('gulp');
|
const { src, dest, watch, series, task } = require('gulp')
|
||||||
const ts = require('gulp-typescript');
|
const ts = require('gulp-typescript')
|
||||||
const del = require('delete');
|
const del = require('delete')
|
||||||
const eslint = require('gulp-eslint');
|
const eslint = require('gulp-eslint')
|
||||||
const nodemon = require('gulp-nodemon');
|
const nodemon = require('gulp-nodemon')
|
||||||
/**
|
/**
|
||||||
* Clears the dist folder by deleting all files inside.
|
* Clears the dist folder by deleting all files inside.
|
||||||
* @param cb
|
* @param cb
|
||||||
*/
|
*/
|
||||||
function clearDist(cb) {
|
function clearDist (cb) {
|
||||||
del('dist/*', cb);
|
del('dist/*', cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Typescript compilation task.
|
* Typescript compilation task.
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
function compileTypescript() {
|
function compileTypescript () {
|
||||||
let tsProject = ts.createProject('tsconfig.json');
|
const tsProject = ts.createProject('tsconfig.json')
|
||||||
let tsResult = tsProject.src().pipe(tsProject());
|
const tsResult = tsProject.src().pipe(tsProject())
|
||||||
return tsResult
|
return tsResult
|
||||||
//.pipe(minify())
|
// .pipe(minify())
|
||||||
.pipe(dest('dist'));
|
.pipe(dest('dist'))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task for moving all remaining file from source to dist that don't need procession.
|
* Task for moving all remaining file from source to dist that don't need procession.
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
function moveRemaining() {
|
function moveRemaining () {
|
||||||
return src(['src/**/*', '!src/**/*.ts'])
|
return src(['src/**/*', '!src/**/*.ts'])
|
||||||
.pipe(dest('dist'));
|
.pipe(dest('dist'))
|
||||||
}
|
}
|
||||||
|
|
||||||
function runEslint() {
|
function runEslint () {
|
||||||
return src(['scripts/*.js'])
|
return src(['src/**/*.ts'])
|
||||||
// eslint() attaches the lint output to the "eslint" property
|
// eslint() attaches the lint output to the "eslint" property
|
||||||
// of the file object so it can be used by other modules.
|
// of the file object so it can be used by other modules.
|
||||||
.pipe(eslint())
|
.pipe(eslint({ fix: true }))
|
||||||
// eslint.format() outputs the lint results to the console.
|
// eslint.format() outputs the lint results to the console.
|
||||||
// Alternatively use eslint.formatEach() (see Docs).
|
// Alternatively use eslint.formatEach() (see Docs).
|
||||||
.pipe(eslint.format())
|
.pipe(eslint.format())
|
||||||
// To have the process exit with an error code (1) on
|
// To have the process exit with an error code (1) on
|
||||||
// lint error, return the stream and pipe to failAfterError last.
|
// lint error, return the stream and pipe to failAfterError last.
|
||||||
.pipe(eslint.failAfterError());
|
.pipe(eslint.failAfterError())
|
||||||
}
|
}
|
||||||
task('eslint', () => {
|
task('eslint', () => {
|
||||||
return src(['scripts/*.js'])
|
return src(['src/**/*.ts'])
|
||||||
// eslint() attaches the lint output to the "eslint" property
|
// eslint() attaches the lint output to the "eslint" property
|
||||||
// of the file object so it can be used by other modules.
|
// of the file object so it can be used by other modules.
|
||||||
.pipe(eslint())
|
.pipe(eslint({ fix: true }))
|
||||||
// eslint.format() outputs the lint results to the console.
|
// eslint.format() outputs the lint results to the console.
|
||||||
// Alternatively use eslint.formatEach() (see Docs).
|
// Alternatively use eslint.formatEach() (see Docs).
|
||||||
.pipe(eslint.format())
|
.pipe(eslint.format())
|
||||||
// To have the process exit with an error code (1) on
|
// To have the process exit with an error code (1) on
|
||||||
// lint error, return the stream and pipe to failAfterError last.
|
// lint error, return the stream and pipe to failAfterError last.
|
||||||
.pipe(eslint.failAfterError());
|
.pipe(eslint.failAfterError())
|
||||||
});
|
})
|
||||||
|
|
||||||
task('default', series(clearDist, compileTypescript, moveRemaining));
|
task('default', series(clearDist, compileTypescript, moveRemaining))
|
||||||
|
|
||||||
task('watch', () => {
|
task('watch', () => {
|
||||||
watch('**/*.ts', runEslint);
|
runEslint()
|
||||||
watch('**/*.ts', compileTypescript);
|
compileTypescript()
|
||||||
watch(['src/**/*', '!src/**/*.ts'], moveRemaining());
|
watch('**/*.ts', runEslint)
|
||||||
|
watch('**/*.ts', compileTypescript)
|
||||||
|
// watch(['src/**/*', '!src/**/*.ts'], moveRemaining());
|
||||||
nodemon({
|
nodemon({
|
||||||
script: 'dist/index.js',
|
script: 'dist/index.js',
|
||||||
watch: ['dist/**/*.js'],
|
watch: ['dist/**/*.js'],
|
||||||
ext: 'js'
|
ext: 'js'
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
task('watchnolint', () => {
|
task('watchnolint', () => {
|
||||||
watch('**/*.ts', compileTypescript);
|
watch('**/*.ts', compileTypescript)
|
||||||
watch(['src/**/*', '!src/**/*.ts'], moveRemaining());
|
// watch(['src/**/*', '!src/**/*.ts'], moveRemaining());
|
||||||
nodemon({
|
nodemon({
|
||||||
script: 'dist/index.js',
|
script: 'dist/index.js',
|
||||||
watch: ['dist/**/*.js'],
|
watch: ['dist/**/*.js'],
|
||||||
ext: 'js'
|
ext: 'js'
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"type": "postgres",
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 5432,
|
||||||
|
"username": "apollo",
|
||||||
|
"database": "apollo_test",
|
||||||
|
"synchronize": true,
|
||||||
|
"logging": false,
|
||||||
|
"entities": [
|
||||||
|
"dist/model/**/*.js"
|
||||||
|
]
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -1,20 +1,16 @@
|
|||||||
import { DataSource } from 'apollo-datasource';
|
import { DataSource } from 'apollo-datasource'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* extended datasource to feed resolvers with data about cargoBikes
|
* extended datasource to feed resolvers with data about cargoBikes
|
||||||
*/
|
*/
|
||||||
export class CargoBikeAPI extends DataSource {
|
export class CargoBikeAPI extends DataSource {
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
// this.store = store;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Finds cargo bike by id
|
* Finds cargo bike by id
|
||||||
*/
|
*/
|
||||||
async findCargoBikeById({ id }:{id: any}){
|
async findCargoBikeById ({ id, token }:{id: any, token:string}) {
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
name: "hello world"
|
name: token
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
import {Sequelize} from 'sequelize-typescript';
|
||||||
|
|
||||||
|
export class DButils {
|
||||||
|
dbclient: any;
|
||||||
|
constructor(){
|
||||||
|
this.dbclient = new Sequelize({
|
||||||
|
database: 'apollo',
|
||||||
|
dialect: 'postgres',
|
||||||
|
username: 'postgres',
|
||||||
|
password: 'apollo',
|
||||||
|
storage: ':memory:',
|
||||||
|
models: [__dirname + '/models'], // or [Player, Team],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
@ -1,17 +1,13 @@
|
|||||||
import { DataSource} from 'apollo-datasource';
|
import { DataSource } from 'apollo-datasource'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetches datafrom user server, especially validates user tokens
|
* fetches datafrom user server, especially validates user tokens
|
||||||
*/
|
*/
|
||||||
export class UserServerAPI extends DataSource{
|
export class UserServerAPI extends DataSource {
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* validates user token
|
* validates user token
|
||||||
*/
|
*/
|
||||||
async validateToken(token:string){
|
async validateToken (token:string) {
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,16 +1,22 @@
|
|||||||
import { ApolloServer } from 'apollo-server';
|
import { ApolloServer } from 'apollo-server'
|
||||||
import bikeresolver from './resolvers/cargobikeResolver';
|
import bikeresolver from './resolvers/cargobikeResolver'
|
||||||
import { CargoBikeAPI } from './datasources/db/cargobikeAPI';
|
import { CargoBikeAPI } from './datasources/db/cargobikeAPI'
|
||||||
import typeDefs from './schema/type-defs';
|
import typeDefs from './schema/type-defs'
|
||||||
|
import 'reflect-metadata'
|
||||||
|
import { createConnection } from 'typeorm'
|
||||||
|
|
||||||
|
createConnection().then(async () => {
|
||||||
|
console.log('connected to db')
|
||||||
|
}).catch(error => console.log(error))
|
||||||
|
|
||||||
const server = new ApolloServer({
|
const server = new ApolloServer({
|
||||||
resolvers:[bikeresolver],
|
resolvers: [bikeresolver],
|
||||||
typeDefs,
|
typeDefs,
|
||||||
dataSources: () => ({
|
dataSources: () => ({
|
||||||
cargoBikeAPI: new CargoBikeAPI(),
|
cargoBikeAPI: new CargoBikeAPI()
|
||||||
})
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
|
console.log(__dirname)
|
||||||
server.listen()
|
server.listen()
|
||||||
.then(({ url }) => console.log(`Server ready at ${url} `));
|
.then(({ url }) => console.log(`Server ready at ${url} `))
|
||||||
|
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class CargoBike {
|
||||||
|
@PrimaryGeneratedColumn()
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
description: string;
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
export default {
|
export default {
|
||||||
Query: {
|
Query: {
|
||||||
cargobike: (_: any,{ id }:{id: any},{dataSources}:{dataSources: any}) =>
|
cargobike: (_: any, { id, token }:{id: any, token: string}, { dataSources }:{dataSources: any}) =>
|
||||||
dataSources.cargoBikeAPI.findCargoBikeById( { id } )
|
dataSources.cargoBikeAPI.findCargoBikeById({ id, token })
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
|
Loading…
Reference in New Issue