Commit 69732d6a authored by Max Hartmann's avatar Max Hartmann

Mutation for createPerson

parent eb562751
......@@ -44,7 +44,11 @@ export class GraphQlController {
const root = {
persons: () => this.service.findPersons()
.then((result) => result.rows),
person: (param: QueryParameter) => this.service.findPerson(param.id).then((result) => result.rows[0])
person: (param: {id: number}) => this.service.findPerson(param.id).then((result) => result.rows[0]),
createPerson: (person: Person) => this.service.save(person).then((savedId) => {
person.id = savedId;
return person;
})
};
return express_graphql({
graphiql: true,
......@@ -57,7 +61,3 @@ export class GraphQlController {
export interface Controller {
routes(): Router;
}
interface QueryParameter {
id: number;
}
......@@ -3,6 +3,9 @@ export const Schema = `
persons: [Person]
person(id: Int!): Person
}
type Mutation {
createPerson(firstname: String!, surname: String!): Person
}
type Person {
id: Int,
firstname: String,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment