Resolver Component Creation for GraphQL
Explore how to build resolver components in Go to handle GraphQL CRUD operations. Learn to implement mutation and query functions for creating, editing, deleting, and retrieving blog data. This lesson guides you through connecting service logic to resolvers and executing GraphQL queries for backend development.
Implement the resolver
We start by registering the service component in the resolver so the resolver can implement the functionalities with the component. We implement the functionalities inside the schema.resolvers.go file.
Create a new blog
Inside the NewBlog() function, we create an implementation to add new blog data.
func (r *mutationResolver) NewBlog(ctx context.Context, input model.NewBlog) (*model.Blog, error) {
var blog *model.Blog = r.blogService.CreateBlog(input)
return blog, nil
}
In the code above, the new blog is created with the CreateBlog() function from the service component.
Edit a blog
Inside the EditBlog() function, we create an implementation to edit or update the blog data.
func (r *mutationResolver) EditBlog(ctx context.Context, input model.EditBlog) (*model.Blog, error) {
blog, err := r.blogService.EditBlog(input)
...