| 1 |
|
package graph |
| 2 |
|
|
| 3 |
|
// This file will be automatically regenerated based on the schema, any resolver |
| 4 |
|
// implementations |
| 5 |
|
// will be copied through when generating and any unknown code will be moved to the end. |
| 6 |
|
// Code generated by github.com/99designs/gqlgen version v0.17.94 |
| 7 |
|
|
| 8 |
|
import ( |
| 9 |
|
"context" |
| 10 |
|
|
| 11 |
|
model1 "sourcecraft.dev/bigbes/sr-ht-core/model" |
| 12 |
|
"sourcecraft.dev/bigbes/sr-ht-dolt/browse" |
| 13 |
|
"sourcecraft.dev/bigbes/sr-ht-dolt/graph/api" |
| 14 |
|
"sourcecraft.dev/bigbes/sr-ht-dolt/graph/model" |
| 15 |
|
) |
| 16 |
|
|
| 17 |
|
// DefaultBranch is the resolver for the defaultBranch field. |
| 18 |
2 |
func (r *databaseResolver) DefaultBranch(ctx context.Context, obj *model.Database) (*string, error) { |
| 19 |
2 |
sess, err := r.openStore(ctx, "defaultBranch", obj.Repo) |
| 20 |
2 |
if err != nil { |
| 21 |
0 |
return nil, err |
| 22 |
0 |
} |
| 23 |
2 |
defer sess.Close() |
| 24 |
2 |
|
| 25 |
2 |
branches, err := sess.Branches(ctx) |
| 26 |
2 |
if err != nil { |
| 27 |
0 |
return nil, internalError("Database.defaultBranch", err) |
| 28 |
0 |
} |
| 29 |
|
// A store nothing has been pushed to has no branches, and that is a state |
| 30 |
|
// rather than a failure: null, not an error. |
| 31 |
2 |
if len(branches) == 0 { |
| 32 |
1 |
return nil, nil |
| 33 |
1 |
} |
| 34 |
1 |
name := browse.DefaultBranch(branches) |
| 35 |
1 |
return &name, nil |
| 36 |
|
} |
| 37 |
|
|
| 38 |
|
// Branches is the resolver for the branches field. |
| 39 |
3 |
func (r *databaseResolver) Branches(ctx context.Context, obj *model.Database) ([]*model.Branch, error) { |
| 40 |
3 |
sess, err := r.openStore(ctx, "branches", obj.Repo) |
| 41 |
3 |
if err != nil { |
| 42 |
1 |
return nil, err |
| 43 |
1 |
} |
| 44 |
2 |
defer sess.Close() |
| 45 |
2 |
|
| 46 |
2 |
branches, err := sess.Branches(ctx) |
| 47 |
2 |
if err != nil { |
| 48 |
0 |
return nil, internalError("Database.branches", err) |
| 49 |
0 |
} |
| 50 |
2 |
out := make([]*model.Branch, 0, len(branches)) |
| 51 |
2 |
for _, b := range branches { |
| 52 |
2 |
out = append(out, &model.Branch{Name: b.Name, Head: b.Head}) |
| 53 |
2 |
} |
| 54 |
2 |
return out, nil |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
// Log is the resolver for the log field. |
| 58 |
2 |
func (r *databaseResolver) Log(ctx context.Context, obj *model.Database, ref *string, from *model1.Cursor, limit *int) (*model.CommitCursor, error) { |
| 59 |
2 |
sess, err := r.openStore(ctx, "log", obj.Repo) |
| 60 |
2 |
if err != nil { |
| 61 |
0 |
return nil, err |
| 62 |
0 |
} |
| 63 |
2 |
defer sess.Close() |
| 64 |
2 |
|
| 65 |
2 |
refStr, err := resolveRef(ctx, sess, ref) |
| 66 |
2 |
if err != nil { |
| 67 |
0 |
return nil, err |
| 68 |
0 |
} |
| 69 |
|
// No branches at all: an empty log, not an error, for the same reason |
| 70 |
|
// defaultBranch answers null. |
| 71 |
2 |
if refStr == "" { |
| 72 |
1 |
return &model.CommitCursor{Results: []*model.Commit{}}, nil |
| 73 |
1 |
} |
| 74 |
|
|
| 75 |
1 |
commits, next, err := sess.Log(ctx, refStr, cursorNext(from), logLimit(limit)) |
| 76 |
1 |
if err != nil { |
| 77 |
0 |
return nil, internalError("Database.log", err) |
| 78 |
0 |
} |
| 79 |
|
|
| 80 |
1 |
out := make([]*model.Commit, 0, len(commits)) |
| 81 |
1 |
for _, c := range commits { |
| 82 |
1 |
out = append(out, &model.Commit{ |
| 83 |
1 |
Hash: c.Hash, |
| 84 |
1 |
Author: c.Author, |
| 85 |
1 |
Email: c.Email, |
| 86 |
1 |
Date: c.Date, |
| 87 |
1 |
Message: c.Message, |
| 88 |
1 |
Parents: c.ParentHashes, |
| 89 |
1 |
}) |
| 90 |
1 |
} |
| 91 |
1 |
return &model.CommitCursor{Results: out, Cursor: nextCursor(next)}, nil |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
// Tables is the resolver for the tables field. |
| 95 |
2 |
func (r *databaseResolver) Tables(ctx context.Context, obj *model.Database, ref *string) ([]*model.Table, error) { |
| 96 |
2 |
sess, err := r.openStore(ctx, "tables", obj.Repo) |
| 97 |
2 |
if err != nil { |
| 98 |
0 |
return nil, err |
| 99 |
0 |
} |
| 100 |
2 |
defer sess.Close() |
| 101 |
2 |
|
| 102 |
2 |
refStr, err := resolveRef(ctx, sess, ref) |
| 103 |
2 |
if err != nil { |
| 104 |
0 |
return nil, err |
| 105 |
0 |
} |
| 106 |
2 |
if refStr == "" { |
| 107 |
1 |
return []*model.Table{}, nil |
| 108 |
1 |
} |
| 109 |
|
|
| 110 |
1 |
tables, err := sess.Tables(ctx, refStr) |
| 111 |
1 |
if err != nil { |
| 112 |
0 |
return nil, internalError("Database.tables", err) |
| 113 |
0 |
} |
| 114 |
1 |
out := make([]*model.Table, 0, len(tables)) |
| 115 |
1 |
for _, t := range tables { |
| 116 |
1 |
columns := make([]*model.Column, 0, len(t.Columns)) |
| 117 |
1 |
for _, c := range t.Columns { |
| 118 |
1 |
columns = append(columns, &model.Column{ |
| 119 |
1 |
Name: c.Name, |
| 120 |
1 |
Type: c.Type, |
| 121 |
1 |
PrimaryKey: c.PrimaryKey, |
| 122 |
1 |
Nullable: c.Nullable, |
| 123 |
1 |
}) |
| 124 |
1 |
} |
| 125 |
1 |
out = append(out, &model.Table{ |
| 126 |
1 |
Name: t.Name, |
| 127 |
1 |
Columns: columns, |
| 128 |
1 |
RowCount: int(t.RowCount), |
| 129 |
1 |
}) |
| 130 |
|
} |
| 131 |
1 |
return out, nil |
| 132 |
|
} |
| 133 |
|
|
| 134 |
|
// ACL is the resolver for the acl field. |
| 135 |
2 |
func (r *databaseResolver) ACL(ctx context.Context, obj *model.Database) ([]*model.ACLEntry, error) { |
| 136 |
2 |
// Owner-only, and the empty list rather than an error for everybody else: |
| 137 |
2 |
// who collaborates on a database you do not own is not yours to enumerate, |
| 138 |
2 |
// and a refusal here would answer a question the caller may not ask. |
| 139 |
2 |
caller := callerOf(ctx) |
| 140 |
2 |
if caller == nil || caller.UserID != obj.Repo.OwnerID { |
| 141 |
1 |
return []*model.ACLEntry{}, nil |
| 142 |
1 |
} |
| 143 |
|
|
| 144 |
1 |
entries, err := r.repos.ListACL(ctx, obj.Repo.ID) |
| 145 |
1 |
if err != nil { |
| 146 |
0 |
return nil, internalError("Database.acl", err) |
| 147 |
0 |
} |
| 148 |
1 |
out := make([]*model.ACLEntry, 0, len(entries)) |
| 149 |
1 |
for _, e := range entries { |
| 150 |
1 |
out = append(out, &model.ACLEntry{ |
| 151 |
1 |
User: model.NewUser(e.Username), |
| 152 |
1 |
Mode: model.AccessMode(e.Mode), |
| 153 |
1 |
}) |
| 154 |
1 |
} |
| 155 |
1 |
return out, nil |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
// Me is the resolver for the me field. |
| 159 |
2 |
func (r *queryResolver) Me(ctx context.Context) (*model.User, error) { |
| 160 |
2 |
caller := callerOf(ctx) |
| 161 |
2 |
if caller == nil { |
| 162 |
1 |
return nil, nil |
| 163 |
1 |
} |
| 164 |
1 |
return model.NewUser(caller.Username), nil |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
// Databases is the resolver for the databases field. |
| 168 |
13 |
func (r *queryResolver) Databases(ctx context.Context, cursor *model1.Cursor, filter *model1.Filter) (*model.DatabaseCursor, error) { |
| 169 |
13 |
repos, err := r.repos.ListReposForViewer(ctx, callerOf(ctx)) |
| 170 |
13 |
if err != nil { |
| 171 |
1 |
return nil, internalError("databases", err) |
| 172 |
1 |
} |
| 173 |
12 |
return page(repos, cursor, filter), nil |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
// DatabasesByOwner is the resolver for the databasesByOwner field. |
| 177 |
1 |
func (r *queryResolver) DatabasesByOwner(ctx context.Context, owner string, cursor *model1.Cursor, filter *model1.Filter) (*model.DatabaseCursor, error) { |
| 178 |
1 |
repos, err := r.repos.ListReposByOwner(ctx, owner, callerOf(ctx)) |
| 179 |
1 |
if err != nil { |
| 180 |
0 |
return nil, internalError("databasesByOwner", err) |
| 181 |
0 |
} |
| 182 |
1 |
return page(repos, cursor, filter), nil |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
// Database is the resolver for the database field. |
| 186 |
12 |
func (r *queryResolver) Database(ctx context.Context, owner string, name string) (*model.Database, error) { |
| 187 |
12 |
repo, err := r.resolveDatabase(ctx, owner, name) |
| 188 |
12 |
if err != nil || repo == nil { |
| 189 |
4 |
return nil, err |
| 190 |
4 |
} |
| 191 |
8 |
return model.NewDatabase(repo), nil |
| 192 |
|
} |
| 193 |
|
|
| 194 |
|
// Database returns api.DatabaseResolver implementation. |
| 195 |
11 |
func (r *Resolver) Database() api.DatabaseResolver { return &databaseResolver{r} } |
| 196 |
|
|
| 197 |
|
// Query returns api.QueryResolver implementation. |
| 198 |
28 |
func (r *Resolver) Query() api.QueryResolver { return &queryResolver{r} } |
| 199 |
|
|
| 200 |
|
type ( |
| 201 |
|
databaseResolver struct{ *Resolver } |
| 202 |
|
queryResolver struct{ *Resolver } |
| 203 |
|
) |