example to use @Mutation from type-graphql
- User
example to use @Mutation from type-graphql
- Assistant
Here is an example usage of @Mutation decorator from type-graphql:
import { Resolver, Mutation, Arg } from "type-graphql"; import { CreateBookInput } from "../inputs/create-book.input"; import { Book } from "../models/book.model"; @Resolver() export class BookResolver { @Mutation(() => Book) async createBook(@Arg("data") data: CreateBookInput): Promise<Book> { const newBook = await Book.create(data).save(); return newBook; } }In this example, we have created a resolver for a
createBookmutation. The@Mutationdecorator is applied to thecreateBookmethod to specify that this is a mutation resolver. The method takes aCreateBookInputobject as an argument and returns aBookobject.The
@Argdecorator is used to specify that thedataparameter is an input argument for the mutation. TheCreateBookInputinterface is defined elsewhere and represents the shape of the input data expected by this mutation.Inside the resolver, a new
Bookobject is created using thecreatemethod of theBookmodel. The new book is saved to the database using thesavemethod and the newly createdBookobject is returned.This is just a simple example of how to use the
@Mutationdecorator from type-graphql. In your own code, you can customize the resolver to handle mutations specific to your use case.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.