-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathblog.resolvers.go
148 lines (115 loc) · 3.66 KB
/
blog.resolvers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package graphql
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.41
import (
"context"
"fmt"
)
// AddComment is the resolver for the addComment field.
func (r *mutationResolver) AddComment(ctx context.Context, input AddComment) (*Comment, error) {
c := &Comment{}
c.Content = input.Content
c.User = GetUserFromContext(ctx)
post, err := GetPostString(ctx, input.PostID)
if err != nil {
return nil, err
}
c.Post = post
err = c.Save(ctx)
if err != nil {
return nil, err
}
return GetComment(ctx, c.ID)
}
// CreatePost is the resolver for the createPost field.
func (r *mutationResolver) CreatePost(ctx context.Context, input EditPost) (*Post, error) {
return r.EditPost(ctx, input)
}
// EditPost is the resolver for the editPost field.
func (r *mutationResolver) EditPost(ctx context.Context, input EditPost) (*Post, error) {
var err error
p := &Post{}
// We do this so the defaults in save don't overwrite stuff on upsert.
if input.ID != nil {
p, err = GetPostString(ctx, *input.ID)
if err != nil {
return nil, err
}
if p == nil {
return nil, fmt.Errorf("cannot edit post that does not exist")
}
}
if input.Title != nil {
p.Title = *input.Title
}
if input.Content != nil {
p.Content = *input.Content
}
if input.Datetime != nil {
p.Datetime = *input.Datetime
}
if input.Draft != nil {
p.Draft = *input.Draft
} else {
p.Draft = true
}
err = p.Save(ctx)
if err != nil {
return nil, err
}
return GetPostString(ctx, p.ID)
}
// Drafts is the resolver for the drafts field.
func (r *queryResolver) Drafts(ctx context.Context, input *Limit) ([]*Post, error) {
limit, offset := ParseLimit(input, 10, 0)
return Drafts(ctx, limit, offset)
}
// FuturePosts is the resolver for the futurePosts field.
func (r *queryResolver) FuturePosts(ctx context.Context, input *Limit) ([]*Post, error) {
limit, offset := ParseLimit(input, 10, 0)
return FuturePosts(ctx, limit, offset)
}
// Posts is the resolver for the posts field.
func (r *queryResolver) Posts(ctx context.Context, input *Limit) ([]*Post, error) {
limit, offset := ParseLimit(input, 10, 0)
return Posts(ctx, limit, offset)
}
// Comments is the resolver for the comments field.
func (r *queryResolver) Comments(ctx context.Context, input *Limit) ([]*Comment, error) {
limit, offset := ParseLimit(input, 10, 0)
return AllComments(ctx, limit, offset)
}
// Search is the resolver for the search field.
func (r *queryResolver) Search(ctx context.Context, query string, input *Limit) ([]*Post, error) {
limit, offset := ParseLimit(input, 10, 0)
return Search(ctx, query, limit, offset)
}
// Post is the resolver for the post field.
func (r *queryResolver) Post(ctx context.Context, id string) (*Post, error) {
return GetPostString(ctx, id)
}
// NextPost is the resolver for the nextPost field.
func (r *queryResolver) NextPost(ctx context.Context, id string) (*Post, error) {
p, err := GetPostString(ctx, id)
if err != nil {
return nil, err
}
return p.Next(ctx)
}
// PrevPost is the resolver for the prevPost field.
func (r *queryResolver) PrevPost(ctx context.Context, id string) (*Post, error) {
p, err := GetPostString(ctx, id)
if err != nil {
return nil, err
}
return p.Prev(ctx)
}
// PostsByTag is the resolver for the postsByTag field.
func (r *queryResolver) PostsByTag(ctx context.Context, id string) ([]*Post, error) {
return PostsByTag(ctx, id)
}
// Tags is the resolver for the tags field.
func (r *queryResolver) Tags(ctx context.Context) ([]string, error) {
return AllTags(ctx)
}