entdataloader

package module
v0.0.0-...-8da1c7e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2021 License: MIT Imports: 7 Imported by: 0

README

Ent Dataloader

Introduction

Ent dataloader generates datalodaers for edges.

Only O2M (with edge field) and M2O edges are currently supported.

package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"github.com/cliedeman/entdataloader"
)

type User struct {
	ent.Schema
}

func (User) Fields() []ent.Field {
	return []ent.Field{
		field.String("username").Unique(),
	}
}

func (User) Edges() []ent.Edge {
	return []ent.Edge{
		edge.To("posts", Post.Type).
			Annotations(entdataloader.Annotation{}),
	}
}

type Post struct {
    ent.Schema
}

func (Post) Fields() []ent.Field {
    return []ent.Field{
        field.Int("author_id").
            Optional(),
    }
}

func (Post) Edges() []ent.Edge {
    return []ent.Edge{
        edge.From("author", User.Type).
            Ref("posts").
            Field("author_id").
            Unique().
            Annotations(entdataloader.Annotation{}),
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DataLoaderTemplate = parse("template/entdataloader.tmpl")

	// AllTemplates holds all templates for extending ent to support GraphQL.
	AllTemplates = []*gen.Template{
		DataLoaderTemplate,
	}
)

Functions

This section is empty.

Types

type Annotation

type Annotation struct {
}

func (*Annotation) Decode

func (a *Annotation) Decode(annotation interface{}) error

func (Annotation) Name

func (Annotation) Name() string

type Extension

type Extension struct {
	entc.DefaultExtension
}

Extension implements the entc.Extension for providing GraphQL integration.

func (Extension) Templates

func (e Extension) Templates() []*gen.Template

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL