src: added skeleton

pull/1/head
leonnicolas 4 years ago
parent 706f11ac41
commit 9aa94a33ce
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -64,4 +64,9 @@ task('watch', () => {
task('watchnolint', () => { task('watchnolint', () => {
watch('**/*.ts', compileTypescript); watch('**/*.ts', compileTypescript);
watch(['src/**/*', '!src/**/*.ts'], moveRemaining()); watch(['src/**/*', '!src/**/*.ts'], moveRemaining());
nodemon({
script: 'dist/index.js',
watch: ['dist/**/*.js'],
ext: 'js'
});
}); });

@ -0,0 +1,20 @@
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 {
id,
name: "hello world"
};
}
}

@ -0,0 +1,17 @@
import { DataSource} from 'apollo-datasource';
/**
* fetches datafrom user server, especially validates user tokens
*/
export class UserServerAPI extends DataSource{
constructor() {
super();
}
/**
* validates user token
*/
async validateToken(token:string){
return true;
}
}

@ -1,12 +1,15 @@
// tslint:disable: no-console // tslint:disable: no-console
import { ApolloServer } from 'apollo-server'; import { ApolloServer } from 'apollo-server';
import bikeresolver from './resolvers/cargobike'; import bikeresolver from './resolvers/cargobikeResolver';
import { CargoBikeAPI } from './datasources/db/cargobikeAPI';
import typeDefs from './schema/type-defs'; import typeDefs from './schema/type-defs';
const server = new ApolloServer({ const server = new ApolloServer({
resolvers:[bikeresolver], resolvers:[bikeresolver],
typeDefs typeDefs,
dataSources: () => ({
cargoBikeAPI: new CargoBikeAPI(),
})
}); });
server.listen() server.listen()

@ -1,10 +0,0 @@
export default {
Query: {
cargobike: () => {
return {
id:1,
name: "hello!"
};
}
}
};

@ -0,0 +1,6 @@
export default {
Query: {
cargobike: (_: any,{ id }:{id: any},{dataSources}:{dataSources: any}) =>
dataSources.cargoBikeAPI.findCargoBikeById( { id } )
},
};

@ -234,7 +234,7 @@ type Organisation{
vereinsregisternr: Int vereinsregisternr: Int
} }
type Query { type Query {
cargobike: CargoBike cargobike(id:ID!): CargoBike
} }
`; `;
Loading…
Cancel
Save