type-des: first test mutation

pull/2/head
leonnicolas 4 years ago
parent 87fd338088
commit 85e1d95631
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -1,9 +1,15 @@
import { DataSource } from 'apollo-datasource'
import { getConnection, Connection } from 'typeorm'
import { CargoBike } from '../../model/CargoBike'
/**
* extended datasource to feed resolvers with data about cargoBikes
*/
export class CargoBikeAPI extends DataSource {
connection : Connection
constructor(){
super()
this.connection = getConnection()
}
/**
* Finds cargo bike by id
*/
@ -13,4 +19,20 @@ export class CargoBikeAPI extends DataSource {
name: token
}
}
async updateBike ({ id, token, name }:{id:any, token: string, name: string }) {
const bike = new CargoBike()
bike.id = id
bike.description = token
bike.name = name
this.connection.manager.save(bike)
return {
success: true,
message: token,
bike: {
id,
name
}
}
}
}

@ -2,5 +2,9 @@ export default {
Query: {
cargobike: (_: any, { id, token }:{id: any, token: string}, { dataSources }:{dataSources: any}) =>
dataSources.cargoBikeAPI.findCargoBikeById({ id, token })
},
Mutation: {
addBike: (_:any, { id, token, name }:{id: any, token: string, name:string}, { dataSources }:{dataSources: any }) =>
dataSources.cargoBikeAPI.updateBike({ id, token, name })
}
}

@ -265,9 +265,10 @@ type UpdateBikeResponse {
message: String
bike: CargoBike
}
"for testing"
type Mutation {
addBike(id: ID!):UpdateBikeResponse
addBike(id: ID!, token: String!, name: String):UpdateBikeResponse
}
`

Loading…
Cancel
Save