Skip to content

Instantly share code, notes, and snippets.

@osha7
Created June 22, 2021 04:36
Show Gist options
  • Save osha7/df7e99eecda006641fd8b95bc67502cb to your computer and use it in GitHub Desktop.
Save osha7/df7e99eecda006641fd8b95bc67502cb to your computer and use it in GitHub Desktop.
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