Add album path resolver
This commit is contained in:
parent
ebe1220520
commit
fc4639a293
|
@ -52,6 +52,7 @@ type DirectiveRoot struct {
|
||||||
|
|
||||||
type ComplexityRoot struct {
|
type ComplexityRoot struct {
|
||||||
Album struct {
|
Album struct {
|
||||||
|
FilePath func(childComplexity int) int
|
||||||
ID func(childComplexity int) int
|
ID func(childComplexity int) int
|
||||||
Owner func(childComplexity int) int
|
Owner func(childComplexity int) int
|
||||||
ParentAlbum func(childComplexity int) int
|
ParentAlbum func(childComplexity int) int
|
||||||
|
@ -191,6 +192,7 @@ type AlbumResolver interface {
|
||||||
Owner(ctx context.Context, obj *models.Album) (*models.User, error)
|
Owner(ctx context.Context, obj *models.Album) (*models.User, error)
|
||||||
|
|
||||||
Thumbnail(ctx context.Context, obj *models.Album) (*models.Photo, error)
|
Thumbnail(ctx context.Context, obj *models.Album) (*models.Photo, error)
|
||||||
|
Path(ctx context.Context, obj *models.Album) ([]*models.Album, error)
|
||||||
Shares(ctx context.Context, obj *models.Album) ([]*models.ShareToken, error)
|
Shares(ctx context.Context, obj *models.Album) ([]*models.ShareToken, error)
|
||||||
}
|
}
|
||||||
type MutationResolver interface {
|
type MutationResolver interface {
|
||||||
|
@ -250,6 +252,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||||
_ = ec
|
_ = ec
|
||||||
switch typeName + "." + field {
|
switch typeName + "." + field {
|
||||||
|
|
||||||
|
case "Album.filePath":
|
||||||
|
if e.complexity.Album.FilePath == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.complexity.Album.FilePath(childComplexity), true
|
||||||
|
|
||||||
case "Album.id":
|
case "Album.id":
|
||||||
if e.complexity.Album.ID == nil {
|
if e.complexity.Album.ID == nil {
|
||||||
break
|
break
|
||||||
|
@ -1213,9 +1222,10 @@ type Album {
|
||||||
"The user who owns this album"
|
"The user who owns this album"
|
||||||
owner: User!
|
owner: User!
|
||||||
"The path on the filesystem of the server, where this album is located"
|
"The path on the filesystem of the server, where this album is located"
|
||||||
path: String!
|
filePath: String!
|
||||||
"An image in this album used for previewing this album"
|
"An image in this album used for previewing this album"
|
||||||
thumbnail: Photo
|
thumbnail: Photo
|
||||||
|
path: [Album!]!
|
||||||
|
|
||||||
shares: [ShareToken]
|
shares: [ShareToken]
|
||||||
}
|
}
|
||||||
|
@ -2007,7 +2017,7 @@ func (ec *executionContext) _Album_owner(ctx context.Context, field graphql.Coll
|
||||||
return ec.marshalNUser2ᚖgithubᚗcomᚋviktorstrateᚋphotoviewᚋapiᚋgraphqlᚋmodelsᚐUser(ctx, field.Selections, res)
|
return ec.marshalNUser2ᚖgithubᚗcomᚋviktorstrateᚋphotoviewᚋapiᚋgraphqlᚋmodelsᚐUser(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _Album_path(ctx context.Context, field graphql.CollectedField, obj *models.Album) (ret graphql.Marshaler) {
|
func (ec *executionContext) _Album_filePath(ctx context.Context, field graphql.CollectedField, obj *models.Album) (ret graphql.Marshaler) {
|
||||||
ctx = ec.Tracer.StartFieldExecution(ctx, field)
|
ctx = ec.Tracer.StartFieldExecution(ctx, field)
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
|
@ -2020,13 +2030,13 @@ func (ec *executionContext) _Album_path(ctx context.Context, field graphql.Colle
|
||||||
Object: "Album",
|
Object: "Album",
|
||||||
Field: field,
|
Field: field,
|
||||||
Args: nil,
|
Args: nil,
|
||||||
IsMethod: false,
|
IsMethod: true,
|
||||||
}
|
}
|
||||||
ctx = graphql.WithResolverContext(ctx, rctx)
|
ctx = graphql.WithResolverContext(ctx, rctx)
|
||||||
ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx)
|
ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx)
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||||
ctx = rctx // use context from middleware stack in children
|
ctx = rctx // use context from middleware stack in children
|
||||||
return obj.Path, nil
|
return obj.FilePath(), nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ec.Error(ctx, err)
|
ec.Error(ctx, err)
|
||||||
|
@ -2078,6 +2088,43 @@ func (ec *executionContext) _Album_thumbnail(ctx context.Context, field graphql.
|
||||||
return ec.marshalOPhoto2ᚖgithubᚗcomᚋviktorstrateᚋphotoviewᚋapiᚋgraphqlᚋmodelsᚐPhoto(ctx, field.Selections, res)
|
return ec.marshalOPhoto2ᚖgithubᚗcomᚋviktorstrateᚋphotoviewᚋapiᚋgraphqlᚋmodelsᚐPhoto(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ec *executionContext) _Album_path(ctx context.Context, field graphql.CollectedField, obj *models.Album) (ret graphql.Marshaler) {
|
||||||
|
ctx = ec.Tracer.StartFieldExecution(ctx, field)
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
ec.Error(ctx, ec.Recover(ctx, r))
|
||||||
|
ret = graphql.Null
|
||||||
|
}
|
||||||
|
ec.Tracer.EndFieldExecution(ctx)
|
||||||
|
}()
|
||||||
|
rctx := &graphql.ResolverContext{
|
||||||
|
Object: "Album",
|
||||||
|
Field: field,
|
||||||
|
Args: nil,
|
||||||
|
IsMethod: true,
|
||||||
|
}
|
||||||
|
ctx = graphql.WithResolverContext(ctx, rctx)
|
||||||
|
ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx)
|
||||||
|
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||||
|
ctx = rctx // use context from middleware stack in children
|
||||||
|
return ec.resolvers.Album().Path(rctx, obj)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
ec.Error(ctx, err)
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
if resTmp == nil {
|
||||||
|
if !ec.HasError(rctx) {
|
||||||
|
ec.Errorf(ctx, "must not be null")
|
||||||
|
}
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
res := resTmp.([]*models.Album)
|
||||||
|
rctx.Result = res
|
||||||
|
ctx = ec.Tracer.StartFieldChildExecution(ctx)
|
||||||
|
return ec.marshalNAlbum2ᚕᚖgithubᚗcomᚋviktorstrateᚋphotoviewᚋapiᚋgraphqlᚋmodelsᚐAlbumᚄ(ctx, field.Selections, res)
|
||||||
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _Album_shares(ctx context.Context, field graphql.CollectedField, obj *models.Album) (ret graphql.Marshaler) {
|
func (ec *executionContext) _Album_shares(ctx context.Context, field graphql.CollectedField, obj *models.Album) (ret graphql.Marshaler) {
|
||||||
ctx = ec.Tracer.StartFieldExecution(ctx, field)
|
ctx = ec.Tracer.StartFieldExecution(ctx, field)
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -6509,8 +6556,8 @@ func (ec *executionContext) _Album(ctx context.Context, sel ast.SelectionSet, ob
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
})
|
})
|
||||||
case "path":
|
case "filePath":
|
||||||
out.Values[i] = ec._Album_path(ctx, field, obj)
|
out.Values[i] = ec._Album_filePath(ctx, field, obj)
|
||||||
if out.Values[i] == graphql.Null {
|
if out.Values[i] == graphql.Null {
|
||||||
atomic.AddUint32(&invalids, 1)
|
atomic.AddUint32(&invalids, 1)
|
||||||
}
|
}
|
||||||
|
@ -6525,6 +6572,20 @@ func (ec *executionContext) _Album(ctx context.Context, sel ast.SelectionSet, ob
|
||||||
res = ec._Album_thumbnail(ctx, field, obj)
|
res = ec._Album_thumbnail(ctx, field, obj)
|
||||||
return res
|
return res
|
||||||
})
|
})
|
||||||
|
case "path":
|
||||||
|
field := field
|
||||||
|
out.Concurrently(i, func() (res graphql.Marshaler) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
ec.Error(ctx, ec.Recover(ctx, r))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
res = ec._Album_path(ctx, field, obj)
|
||||||
|
if res == graphql.Null {
|
||||||
|
atomic.AddUint32(&invalids, 1)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
})
|
||||||
case "shares":
|
case "shares":
|
||||||
field := field
|
field := field
|
||||||
out.Concurrently(i, func() (res graphql.Marshaler) {
|
out.Concurrently(i, func() (res graphql.Marshaler) {
|
||||||
|
|
|
@ -16,6 +16,10 @@ func (a *Album) ID() int {
|
||||||
return a.AlbumID
|
return a.AlbumID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Album) FilePath() string {
|
||||||
|
return a.Path
|
||||||
|
}
|
||||||
|
|
||||||
func NewAlbumFromRow(row *sql.Row) (*Album, error) {
|
func NewAlbumFromRow(row *sql.Row) (*Album, error) {
|
||||||
album := Album{}
|
album := Album{}
|
||||||
|
|
||||||
|
|
|
@ -163,3 +163,19 @@ func (r *albumResolver) Shares(ctx context.Context, obj *models.Album) ([]*model
|
||||||
|
|
||||||
return models.NewShareTokensFromRows(rows)
|
return models.NewShareTokensFromRows(rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *albumResolver) Path(ctx context.Context, obj *models.Album) ([]*models.Album, error) {
|
||||||
|
rows, err := r.Database.Query(`
|
||||||
|
WITH recursive path_albums AS (
|
||||||
|
SELECT * FROM album anchor WHERE anchor.album_id = ?
|
||||||
|
UNION
|
||||||
|
SELECT parent.* FROM path_albums child JOIN album parent ON parent.album_id = child.parent_album
|
||||||
|
)
|
||||||
|
SELECT * FROM path_albums WHERE album_id != ?
|
||||||
|
`, obj.AlbumID, obj.AlbumID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return models.NewAlbumsFromRows(rows)
|
||||||
|
}
|
||||||
|
|
|
@ -166,9 +166,10 @@ type Album {
|
||||||
"The user who owns this album"
|
"The user who owns this album"
|
||||||
owner: User!
|
owner: User!
|
||||||
"The path on the filesystem of the server, where this album is located"
|
"The path on the filesystem of the server, where this album is located"
|
||||||
path: String!
|
filePath: String!
|
||||||
"An image in this album used for previewing this album"
|
"An image in this album used for previewing this album"
|
||||||
thumbnail: Photo
|
thumbnail: Photo
|
||||||
|
path: [Album!]!
|
||||||
|
|
||||||
shares: [ShareToken]
|
shares: [ShareToken]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue