~bigbes/core-go

3e8e0173f88b42e8e8b4ec94aceb113263231c99 — Adnan Maolood 4 years ago 33bc768
valid: Add Error function

Add an Error function which is similar to Errorf except that it does not
take a format specifier.
1 files changed, 11 insertions(+), 0 deletions(-)

M valid/valid.go
M valid/valid.go => valid/valid.go +11 -0
@@ 19,6 19,17 @@ type ValidationError struct {
}

// 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{
		Message: fmt.Sprintf(msg, items...),