Commit eb562751 authored by Max Hartmann's avatar Max Hartmann

person by id query

parent 46d88b0f
......@@ -43,7 +43,8 @@ export class GraphQlController {
// Root resolver
const root = {
persons: () => this.service.findPersons()
.then((result) => result.rows)
.then((result) => result.rows),
person: (param: QueryParameter) => this.service.findPerson(param.id).then((result) => result.rows[0])
};
return express_graphql({
graphiql: true,
......@@ -56,3 +57,7 @@ export class GraphQlController {
export interface Controller {
routes(): Router;
}
interface QueryParameter {
id: number;
}
export const Schema = `
type Query {
persons: [Person]
person(id: Int!): Person
}
type Person {
id: ID,
id: Int,
firstname: String,
surname: String
}
......
......@@ -12,6 +12,7 @@ export class PersonService {
password: 'keule',
});
}
public async save(person: Person): Promise<number> {
const client = await this.pool.connect();
try {
......@@ -31,4 +32,8 @@ export class PersonService {
public async findPersons(): Promise<QueryResult> {
return await this.pool.query('SELECT * FROM person order BY id ASC');
}
public async findPerson(id: number) {
return await this.pool.query('SELECT * FROM person WHERE id = $1', [id]);
}
}
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