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 ts = require('gulp-typescript');
|
||||
const del = require('delete');
|
||||
const eslint = require('gulp-eslint');
|
||||
const nodemon = require('gulp-nodemon');
|
||||
const { src, dest, watch, series, task } = require('gulp')
|
||||
const ts = require('gulp-typescript')
|
||||
const del = require('delete')
|
||||
const eslint = require('gulp-eslint')
|
||||
const nodemon = require('gulp-nodemon')
|
||||
/**
|
||||
* Clears the dist folder by deleting all files inside.
|
||||
* @param cb
|
||||
*/
|
||||
function clearDist(cb) {
|
||||
del('dist/*', cb);
|
||||
function clearDist (cb) {
|
||||
del('dist/*', cb)
|
||||
}
|
||||
|
||||
/**
|
||||
* Typescript compilation task.
|
||||
* @returns {*}
|
||||
*/
|
||||
function compileTypescript() {
|
||||
let tsProject = ts.createProject('tsconfig.json');
|
||||
let tsResult = tsProject.src().pipe(tsProject());
|
||||
function compileTypescript () {
|
||||
const tsProject = ts.createProject('tsconfig.json')
|
||||
const tsResult = tsProject.src().pipe(tsProject())
|
||||
return tsResult
|
||||
//.pipe(minify())
|
||||
.pipe(dest('dist'));
|
||||
// .pipe(minify())
|
||||
.pipe(dest('dist'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Task for moving all remaining file from source to dist that don't need procession.
|
||||
* @returns {*}
|
||||
*/
|
||||
function moveRemaining() {
|
||||
function moveRemaining () {
|
||||
return src(['src/**/*', '!src/**/*.ts'])
|
||||
.pipe(dest('dist'));
|
||||
.pipe(dest('dist'))
|
||||
}
|
||||
|
||||
function runEslint() {
|
||||
return src(['scripts/*.js'])
|
||||
function runEslint () {
|
||||
return src(['src/**/*.ts'])
|
||||
// eslint() attaches the lint output to the "eslint" property
|
||||
// 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.
|
||||
// Alternatively use eslint.formatEach() (see Docs).
|
||||
.pipe(eslint.format())
|
||||
// To have the process exit with an error code (1) on
|
||||
// lint error, return the stream and pipe to failAfterError last.
|
||||
.pipe(eslint.failAfterError());
|
||||
.pipe(eslint.failAfterError())
|
||||
}
|
||||
task('eslint', () => {
|
||||
return src(['scripts/*.js'])
|
||||
return src(['src/**/*.ts'])
|
||||
// eslint() attaches the lint output to the "eslint" property
|
||||
// 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.
|
||||
// Alternatively use eslint.formatEach() (see Docs).
|
||||
.pipe(eslint.format())
|
||||
.pipe(eslint.format())
|
||||
// To have the process exit with an error code (1) on
|
||||
// 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', () => {
|
||||
watch('**/*.ts', runEslint);
|
||||
watch('**/*.ts', compileTypescript);
|
||||
watch(['src/**/*', '!src/**/*.ts'], moveRemaining());
|
||||
runEslint()
|
||||
compileTypescript()
|
||||
watch('**/*.ts', runEslint)
|
||||
watch('**/*.ts', compileTypescript)
|
||||
// watch(['src/**/*', '!src/**/*.ts'], moveRemaining());
|
||||
nodemon({
|
||||
script: 'dist/index.js',
|
||||
watch: ['dist/**/*.js'],
|
||||
ext: 'js'
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
task('watchnolint', () => {
|
||||
watch('**/*.ts', compileTypescript);
|
||||
watch(['src/**/*', '!src/**/*.ts'], moveRemaining());
|
||||
watch('**/*.ts', compileTypescript)
|
||||
// watch(['src/**/*', '!src/**/*.ts'], moveRemaining());
|
||||
nodemon({
|
||||
script: 'dist/index.js',
|
||||
watch: ['dist/**/*.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
|
||||
*/
|
||||
export class CargoBikeAPI extends DataSource {
|
||||
constructor() {
|
||||
super();
|
||||
// this.store = store;
|
||||
}
|
||||
/**
|
||||
* Finds cargo bike by id
|
||||
*/
|
||||
async findCargoBikeById({ id }:{id: any}){
|
||||
return {
|
||||
async findCargoBikeById ({ id, token }:{id: any, token:string}) {
|
||||
return {
|
||||
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
|
||||
*/
|
||||
export class UserServerAPI extends DataSource{
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
export class UserServerAPI extends DataSource {
|
||||
/**
|
||||
* validates user token
|
||||
*/
|
||||
async validateToken(token:string){
|
||||
return true;
|
||||
async validateToken (token:string) {
|
||||
return true
|
||||
}
|
||||
}
|
@ -1,16 +1,22 @@
|
||||
import { ApolloServer } from 'apollo-server';
|
||||
import bikeresolver from './resolvers/cargobikeResolver';
|
||||
import { CargoBikeAPI } from './datasources/db/cargobikeAPI';
|
||||
import typeDefs from './schema/type-defs';
|
||||
import { ApolloServer } from 'apollo-server'
|
||||
import bikeresolver from './resolvers/cargobikeResolver'
|
||||
import { CargoBikeAPI } from './datasources/db/cargobikeAPI'
|
||||
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({
|
||||
resolvers:[bikeresolver],
|
||||
resolvers: [bikeresolver],
|
||||
typeDefs,
|
||||
dataSources: () => ({
|
||||
cargoBikeAPI: new CargoBikeAPI(),
|
||||
})
|
||||
});
|
||||
cargoBikeAPI: new CargoBikeAPI()
|
||||
})
|
||||
})
|
||||
|
||||
console.log(__dirname)
|
||||
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 {
|
||||
Query: {
|
||||
cargobike: (_: any,{ id }:{id: any},{dataSources}:{dataSources: any}) =>
|
||||
dataSources.cargoBikeAPI.findCargoBikeById( { id } )
|
||||
},
|
||||
};
|
||||
cargobike: (_: any, { id, token }:{id: any, token: string}, { dataSources }:{dataSources: any}) =>
|
||||
dataSources.cargoBikeAPI.findCargoBikeById({ id, token })
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue