From 3e8e0173f88b42e8e8b4ec94aceb113263231c99 Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Tue, 1 Mar 2022 11:10:35 -0500 Subject: [PATCH] valid: Add Error function Add an Error function which is similar to Errorf except that it does not take a format specifier. --- valid/valid.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/valid/valid.go b/valid/valid.go index 89f81e1299f550aaff8f748fdf1c9bb753af2b56..e352ef5585d789c435e8fc478a354739cddbf0ef 100644 --- a/valid/valid.go +++ b/valid/valid.go @@ -18,6 +18,17 @@ type ValidationError struct { err *gqlerror.Error } +// Returns a new GraphQL error attached to the given field. +func Error(ctx context.Context, field string, msg string) error { + return &gqlerror.Error{ + Message: msg, + Path: graphql.GetPath(ctx), + Extensions: map[string]interface{}{ + "field": field, + }, + } +} + // 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{