Created
June 22, 2021 04:36
-
-
Save osha7/df7e99eecda006641fd8b95bc67502cb to your computer and use it in GitHub Desktop.
This file contains 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 { MyContext } from "src/types"; | |
import { Resolver, Query, Ctx } from "type-graphql"; | |
import { Post } from "../entities/Post"; | |
@Resolver() //decorator | |
export class PostResolver { | |
//queries or mutations: | |
@Query(() => [Post]) //this sets graphql type | |
// posts( | |
// // @Ctx() ctx: MyContext | |
// @Ctx() {em}: MyContext | |
// ) { | |
// // return ctx.em.find(...); | |
// return em.find(Post, {}); //find all the posts | |
// } | |
posts(@Ctx() { em }: MyContext): Promise<Post[]> { //explicitly set the typescript type | |
return em.find(Post, {}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment