diff --git a/backend/graph/post.resolvers.go b/backend/graph/post.resolvers.go index 8dc1e53..7ea119c 100644 --- a/backend/graph/post.resolvers.go +++ b/backend/graph/post.resolvers.go @@ -8,6 +8,7 @@ package graph import ( "context" "fmt" + "strings" "adam-french.co.uk/backend/graph/model" "adam-french.co.uk/backend/models" @@ -23,6 +24,12 @@ func (r *mutationResolver) CreatePost(ctx context.Context, input model.CreatePos return nil, fmt.Errorf("unauthorized") } + // The admin form submits whatever is in its fields, so an accidental click + // on an empty form would otherwise publish a blank post to the feed. + if strings.TrimSpace(input.Title) == "" { + return nil, fmt.Errorf("a post needs a title") + } + post := models.Post{Title: input.Title, Content: input.Content, AuthorID: userID} if err := r.Store.DB.Create(&post).Error; err != nil { return nil, err