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 { DataSource } from 'apollo-datasource'
import { getConnection, Connection } from 'typeorm'
import { CargoBike } from '../../model/CargoBike'
/** /**
* 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 {
connection : Connection
constructor(){
super()
this.connection = getConnection()
}
/** /**
* Finds cargo bike by id * Finds cargo bike by id
*/ */
@ -13,4 +19,20 @@ export class CargoBikeAPI extends DataSource {
name: token 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: { Query: {
cargobike: (_: any, { id, token }:{id: any, token: string}, { dataSources }:{dataSources: any}) => cargobike: (_: any, { id, token }:{id: any, token: string}, { dataSources }:{dataSources: any}) =>
dataSources.cargoBikeAPI.findCargoBikeById({ id, token }) 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 message: String
bike: CargoBike bike: CargoBike
} }
"for testing" "for testing"
type Mutation { type Mutation {
addBike(id: ID!):UpdateBikeResponse addBike(id: ID!, token: String!, name: String):UpdateBikeResponse
} }
` `

Loading…
Cancel
Save