mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: add hook.FixedError helper (#895)
This commit is contained in:
@@ -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