diff --git a/gulpfile.js b/gulpfile.js index 96a3e73..13bde17 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -64,4 +64,9 @@ task('watch', () => { task('watchnolint', () => { watch('**/*.ts', compileTypescript); watch(['src/**/*', '!src/**/*.ts'], moveRemaining()); + nodemon({ + script: 'dist/index.js', + watch: ['dist/**/*.js'], + ext: 'js' + }); }); \ No newline at end of file diff --git a/src/datasources/db/cargobikeAPI.ts b/src/datasources/db/cargobikeAPI.ts new file mode 100644 index 0000000..e9f3a07 --- /dev/null +++ b/src/datasources/db/cargobikeAPI.ts @@ -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" + }; + } +} \ No newline at end of file diff --git a/src/datasources/userserver/userserviceAPI.ts b/src/datasources/userserver/userserviceAPI.ts new file mode 100644 index 0000000..9b4b95a --- /dev/null +++ b/src/datasources/userserver/userserviceAPI.ts @@ -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; + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index d608660..99c9c05 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,15 @@ // tslint:disable: no-console 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'; const server = new ApolloServer({ resolvers:[bikeresolver], - typeDefs + typeDefs, + dataSources: () => ({ + cargoBikeAPI: new CargoBikeAPI(), + }) }); server.listen() diff --git a/src/resolvers/cargobike.ts b/src/resolvers/cargobike.ts deleted file mode 100644 index 2829022..0000000 --- a/src/resolvers/cargobike.ts +++ /dev/null @@ -1,10 +0,0 @@ -export default { - Query: { - cargobike: () => { - return { - id:1, - name: "hello!" - }; - } - } -}; \ No newline at end of file diff --git a/src/resolvers/cargobikeResolver.ts b/src/resolvers/cargobikeResolver.ts new file mode 100644 index 0000000..b6dab85 --- /dev/null +++ b/src/resolvers/cargobikeResolver.ts @@ -0,0 +1,6 @@ +export default { + Query: { + cargobike: (_: any,{ id }:{id: any},{dataSources}:{dataSources: any}) => + dataSources.cargoBikeAPI.findCargoBikeById( { id } ) + }, +}; diff --git a/src/schema/type-defs.ts b/src/schema/type-defs.ts index 277a779..6c1779c 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -234,7 +234,7 @@ type Organisation{ vereinsregisternr: Int } type Query { - cargobike: CargoBike + cargobike(id:ID!): CargoBike } `; \ No newline at end of file