-
-
Notifications
You must be signed in to change notification settings - Fork 676
/
Copy pathrecipe.resolver.ts
28 lines (24 loc) · 943 Bytes
/
recipe.resolver.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { Arg, Args, Mutation, Query, Resolver } from "type-graphql";
import { generateRecipes } from "./helpers";
import { RecipeInput } from "./recipe.input";
import { Recipe } from "./recipe.type";
import { RecipesArguments } from "./recipes.arguments";
@Resolver(_of => Recipe)
export class RecipeResolver {
private readonly items: Recipe[] = generateRecipes(100);
@Query(_returns => [Recipe])
async recipes(@Args() options: RecipesArguments): Promise<Recipe[]> {
const start: number = options.skip;
const end: number = options.skip + options.take;
return this.items.slice(start, end);
}
@Mutation(_returns => Recipe)
async addRecipe(@Arg("input") recipeInput: RecipeInput): Promise<Recipe> {
const recipe = new Recipe();
recipe.description = recipeInput.description;
recipe.title = recipeInput.title;
recipe.creationDate = new Date();
await this.items.push(recipe);
return recipe;
}
}