diff --git a/valid/valid.go b/valid/valid.go index dba77aeb4cb60f34e092c42eb41430945195c984..13466b80f22fbb583022e84e088ca50f1e0e358c 100644 --- a/valid/valid.go +++ b/valid/valid.go @@ -18,6 +18,17 @@ valid *Validation err *gqlerror.Error } +// Returns a new GraphQL error attached to the given field. +func Errorf(ctx context.Context, field string, msg string, items ...interface{}) error { + return &gqlerror.Error{ + Message: fmt.Sprintf(msg, items...), + Path: graphql.GetPath(ctx), + Extensions: map[string]interface{}{ + "field": field, + }, + } +} + // Creates a new validation context. func New(ctx context.Context) *Validation { return &Validation{