entx

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeRelayNodeType

func ChangeRelayNodeType() entgql.SchemaHook

ChangeRelayNodeType is a schema hook for a change relay node type to GID. Use with GlobalID().

add it to entgql.WithSchemaHook()

func DecimalHook

func DecimalHook() gen.Hook

DecimalHook 修正Decimal类型, 将类型修改为float64,以便将decimal.Decimal类型当成数值类型.

func DecimalScalar added in v0.3.0

func DecimalScalar() entgql.SchemaHook

DecimalScalar 注册decimal.Decimal类型为GraphQL Scalar类型.

func GlobalID

func GlobalID() entc.Option

GlobalID is a global id template for Noder Query. Use with ChangeRelayNodeType().

if you use GlobalID, you must use GID as a scalar type. and use ChangeRelayNodeType() in entgql.WithSchemaHook()

func SimplePagination

func SimplePagination() entc.Option

func SkipTablesDiffHook

func SkipTablesDiffHook(tables ...string) schema.MigrateOption

SkipTablesDiffHook is a schema migration hook for skip tables diff thus skip migration. the table name is database name,not the ent schema struct name.

err = client.Schema.Create(ctx,SkipTablesDiffHook("table1","table2"))

func WithGqlWithTemplates

func WithGqlWithTemplates() entgql.ExtensionOption

WithGqlWithTemplates is a schema hook for replace entgql default template. Note: this option must put before WithWhereInputs or which changed entgql templates option.

extensions:

  1. NodeTemplate: Noder: add entcache context

Types

type DecimalExtension

type DecimalExtension struct {
	entc.DefaultExtension
}

DecimalExtension 修正声明为fieldx.Decimal时, 验证器因此外部类型,无法识别,需要进行修正.

如 对于Decimal类型,默认生成为:

if v, ok := oc.mutation.OrderQty(); ok {
	if err := order.OrderQtyValidator(v.String()); err != nil {
		return &ValidationError{Name: "order_qty", err: fmt.Errorf(`ent: validator failed for field "Order.order_qty": %w`, err)}
	}
}

验证器函数应修改为类型参数为decimal.Decimal:

if v, ok := oc.mutation.OrderQty(); ok {
	if err := decimal.OrderQtyValidator(v); err != nil {
		return &ValidationError{Name: "order_qty", err: fmt.Errorf(`ent: validator failed for field "Order.order_qty": %w`, err)}
	}
}

func (DecimalExtension) Func

func (DecimalExtension) Hooks

func (DecimalExtension) Hooks() []gen.Hook

func (DecimalExtension) Templates

func (d DecimalExtension) Templates() []*gen.Template

Jump to

Keyboard shortcuts

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