adding in resolvers and todos store

This commit is contained in:
talksik
2023-05-23 16:37:22 -07:00
parent a945d2ee54
commit eb1492f509
2 changed files with 38 additions and 13 deletions
+28 -1
View File
@@ -1,7 +1,34 @@
package graph
import "github.com/talksik/graphql-golang/graph/model"
// This file will not be regenerated automatically.
//
// It serves as dependency injection for your app, add any dependencies you require here.
type Resolver struct{}
var todos = []*model.Todo{
{
ID: "1",
Text: "laundry",
Done: false,
},
{
ID: "2",
Text: "woah",
Done: false,
},
{
ID: "3",
Text: "Hello",
Done: false,
User: &model.User{
ID: "1",
Name: "Talksik",
},
},
}
type Resolver struct{
Todos []*model.Todo
}
+10 -12
View File
@@ -13,22 +13,20 @@ import (
// CreateTodo is the resolver for the createTodo field.
func (r *mutationResolver) CreateTodo(ctx context.Context, input model.NewTodo) (*model.Todo, error) {
panic(fmt.Errorf("not implemented: CreateTodo - createTodo"))
newTodo := &model.Todo{
ID: fmt.Sprintf("T%d", len(r.Todos)+1),
Text: input.Text,
Done: false,
}
r.Resolver.Todos = append(r.Resolver.Todos, newTodo)
return newTodo, nil
}
// Todos is the resolver for the todos field.
func (r *queryResolver) Todos(ctx context.Context) ([]*model.Todo, error) {
return []*model.Todo{
{
ID: "1",
Text: "Hello",
Done: false,
User: &model.User{
ID: "1",
Name: "Talksik",
},
},
}, nil
return r.Resolver.Todos, nil
}
// Mutation returns MutationResolver implementation.