Last active
December 14, 2020 04:04
-
-
Save eduardopc/c19f4a8183d0586815ef4bdc985f92ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Resolver, Arg, Query, Mutation } from "type-graphql"; | |
import { Animal } from "../entities/animals"; | |
import { AnimalInput } from "../types/animals"; | |
import { AnimalService } from "../service"; | |
@Resolver() | |
export class AnimalResolver { | |
private readonly service: AnimalService; | |
constructor() { | |
this.service = new AnimalService(); | |
} | |
@Query(() => [Animal], { nullable: false }) | |
async allAnimals() { | |
const animals = await this.service.find(); | |
return animals; | |
}; | |
@Query(() => Animal, { nullable: false }) | |
async whatsAnimal() { | |
const animal = await this.service.findAllAnimalsAndPickOne(); | |
return animal; | |
}; | |
@Mutation(() => Animal) | |
async createAnimal(@Arg("data") | |
{ | |
animal, | |
emoji | |
}: AnimalInput): Promise<Animal> { | |
const newAnimal = await this.service.create({ animal, emoji }); | |
return newAnimal; | |
}; | |
@Mutation(() => Boolean) | |
async deleteAnimal(@Arg("id") id: string) { | |
await this.service.removeById(id) | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment