type-graphql#Info TypeScript Examples
The following examples show how to use
type-graphql#Info.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: author.resolver.ts From mikro-orm-graphql-example with MIT License | 6 votes |
@Query(() => Author, { nullable: true })
public async getAuthor(
@Arg('id') id: string,
@Ctx() ctx: MyContext,
@Info() info: GraphQLResolveInfo,
): Promise<Author | null> {
const relationPaths = fieldsToRelations(info);
return ctx.em.getRepository(Author).findOne({ id }, relationPaths);
}
Example #2
Source File: author.resolver.ts From mikro-orm-graphql-example with MIT License | 6 votes |
@Mutation(() => Author)
public async updateAuthor(
@Arg('input') input: AuthorValidator,
@Arg('id') id: string,
@Ctx() ctx: MyContext,
@Info() info: GraphQLResolveInfo,
): Promise<Author> {
const relationPaths = fieldsToRelations(info);
const author = await ctx.em.getRepository(Author).findOneOrFail({ id }, relationPaths);
author.assign(input);
await ctx.em.persist(author).flush();
return author;
}
Example #3
Source File: book.resolver.ts From mikro-orm-graphql-example with MIT License | 6 votes |
@Query(() => Book, { nullable: true })
public async getBook(
@Arg('id') id: string,
@Ctx() ctx: MyContext,
@Info() info: GraphQLResolveInfo,
): Promise<Book | null> {
const relationPaths = fieldsToRelations(info);
return ctx.em.getRepository(Book).findOne({ id }, relationPaths);
}
Example #4
Source File: book.resolver.ts From mikro-orm-graphql-example with MIT License | 6 votes |
@Mutation(() => Book)
public async addBook(
@Arg('input') input: BookValidator,
@Arg('authorId') authorId: string,
@Arg('publisherId', { nullable: true }) publisherId: string,
@Ctx() ctx: MyContext,
@Info() info: GraphQLResolveInfo,
): Promise<Book> {
const book = new Book(input);
book.author = await ctx.em
.getRepository(Author)
.findOneOrFail({ id: authorId }, fieldsToRelations(info, { root: 'author' }));
if (publisherId) {
book.publisher = await ctx.em.getRepository(Publisher).findOneOrFail(
{ id: publisherId },
fieldsToRelations(info, {
root: 'publisher',
}),
);
}
await ctx.em.persist(book).flush();
return book;
}
Example #5
Source File: book.resolver.ts From mikro-orm-graphql-example with MIT License | 6 votes |
@Mutation(() => Book)
public async updateBook(
@Arg('input') input: BookValidator,
@Arg('id') id: string,
@Ctx() ctx: MyContext,
@Info() info: GraphQLResolveInfo,
): Promise<Book> {
const relationPaths = fieldsToRelations(info);
const book = await ctx.em.getRepository(Book).findOneOrFail({ id }, relationPaths);
book.assign(input);
await ctx.em.persist(book).flush();
return book;
}
Example #6
Source File: author.resolver.ts From mikro-orm-graphql-example with MIT License | 5 votes |
@Query(() => [Author])
public async getAuthors(@Ctx() ctx: MyContext, @Info() info: GraphQLResolveInfo): Promise<Author[]> {
const relationPaths = fieldsToRelations(info);
return ctx.em.getRepository(Author).findAll(relationPaths);
}
Example #7
Source File: book.resolver.ts From mikro-orm-graphql-example with MIT License | 5 votes |
@Query(() => [Book])
public async getBooks(@Ctx() ctx: MyContext, @Info() info: GraphQLResolveInfo): Promise<Book[]> {
const relationPaths = fieldsToRelations(info);
return ctx.em.getRepository(Book).findAll(relationPaths);
}