RedisGraph with GraphQL (gqlgen) playground
package graph

//go:generate go run github.com/99designs/gqlgen

import (
	"fmt"

	"git.sr.ht/~voroskoi/todo-redis/graph/model"
	rg "github.com/RedisGraph/redisgraph-go"
)

// This file will not be regenerated automatically.
//
// It serves as dependency injection for your app, add any dependencies you require here.

type Resolver struct {
	graph rg.Graph
}

func TodoParse(r *rg.Record) (*model.Todo, error) {
	id, ok := r.GetByIndex(0).(string)
	if !ok {
		return nil, fmt.Errorf("TodoParse: %+v ID not found", r)
	}
	prop, ok := r.GetByIndex(1).(redisProps)
	if !ok {
		return nil, fmt.Errorf("TodoParse: %+v properties not found", r)
	}
	user, ok := r.GetByIndex(2).(string)
	if !ok {
		return nil, fmt.Errorf("TodoParse: %+v user not found", r)
	}
	return &model.Todo{
		ID:         id,
		Properties: prop,
		UserID:     user,
	}, nil
}

func UserParse(r *rg.Record) (*model.User, error) {
	id, ok := r.GetByIndex(0).(string)
	if !ok {
		return nil, fmt.Errorf("UserParse: %+v ID not found", r)
	}
	name, ok := r.GetByIndex(1).(string)
	if !ok {
		return nil, fmt.Errorf("UserParse: %+v Name not found", r)
	}
	return &model.User{
		ID:   id,
		Name: name,
	}, nil
}