mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
entc/gen: add hook.FixedError helper (#895)
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -129,6 +129,16 @@ func Unless(hk {{ $pkg }}.Hook, op {{ $pkg }}.Op) {{ $pkg }}.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) {{ $pkg }}.Hook {
|
||||
return func({{ $pkg }}.Mutator) {{ $pkg }}.Mutator {
|
||||
return {{ $pkg }}.MutateFunc(func(context.Context, {{ $pkg }}.Mutation) ({{ $pkg }}.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []{{ $pkg }}.Hook {
|
||||
@@ -138,11 +148,7 @@ func Unless(hk {{ $pkg }}.Hook, op {{ $pkg }}.Op) {{ $pkg }}.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op {{ $pkg }}.Op) {{ $pkg }}.Hook {
|
||||
hk := func({{ $pkg }}.Mutator) {{ $pkg }}.Mutator {
|
||||
return {{ $pkg }}.MutateFunc(func(_ context.Context, m {{ $pkg }}.Mutation) ({{ $pkg }}.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -201,6 +201,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -210,11 +219,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -318,6 +318,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -327,11 +336,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -318,6 +318,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -327,11 +336,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -171,11 +180,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,15 @@ func Unless(hk entv1.Hook, op entv1.Op) entv1.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) entv1.Hook {
|
||||
return func(entv1.Mutator) entv1.Mutator {
|
||||
return entv1.MutateFunc(func(context.Context, entv1.Mutation) (entv1.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []entv1.Hook {
|
||||
@@ -171,11 +180,7 @@ func Unless(hk entv1.Hook, op entv1.Op) entv1.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op entv1.Op) entv1.Hook {
|
||||
hk := func(entv1.Mutator) entv1.Mutator {
|
||||
return entv1.MutateFunc(func(_ context.Context, m entv1.Mutation) (entv1.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -201,6 +201,15 @@ func Unless(hk entv2.Hook, op entv2.Op) entv2.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) entv2.Hook {
|
||||
return func(entv2.Mutator) entv2.Mutator {
|
||||
return entv2.MutateFunc(func(context.Context, entv2.Mutation) (entv2.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []entv2.Hook {
|
||||
@@ -210,11 +219,7 @@ func Unless(hk entv2.Hook, op entv2.Op) entv2.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op entv2.Op) entv2.Hook {
|
||||
hk := func(entv2.Mutator) entv2.Mutator {
|
||||
return entv2.MutateFunc(func(_ context.Context, m entv2.Mutation) (entv2.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -175,6 +175,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -184,11 +193,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -175,6 +175,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -184,11 +193,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -171,11 +180,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -171,11 +180,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -171,11 +180,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -171,11 +180,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -175,6 +175,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -184,11 +193,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -175,6 +175,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -184,11 +193,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
@@ -175,6 +175,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
@@ -184,11 +193,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user