storj/satellite/console/consoleweb/consoleql/projectmember.go

118 lines
2.7 KiB
Go
Raw Normal View History

2019-01-24 16:26:36 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
2018-12-10 11:38:42 +00:00
// See LICENSE for copying information.
package consoleql
2018-12-10 11:38:42 +00:00
import (
"time"
"github.com/graphql-go/graphql"
"storj.io/storj/satellite/console"
2018-12-10 11:38:42 +00:00
)
const (
2019-01-24 16:26:36 +00:00
// ProjectMemberType is a graphql type name for project member
ProjectMemberType = "projectMember"
// FieldJoinedAt is a field name for joined at timestamp
FieldJoinedAt = "joinedAt"
2018-12-10 11:38:42 +00:00
)
// graphqlProjectMember creates projectMember type.
2019-04-04 15:56:20 +01:00
func graphqlProjectMember(service *console.Service, types *TypeCreator) *graphql.Object {
2018-12-10 11:38:42 +00:00
return graphql.NewObject(graphql.ObjectConfig{
2019-01-24 16:26:36 +00:00
Name: ProjectMemberType,
2018-12-10 11:38:42 +00:00
Fields: graphql.Fields{
2019-01-24 16:26:36 +00:00
UserType: &graphql.Field{
2019-04-04 15:56:20 +01:00
Type: types.user,
2018-12-10 11:38:42 +00:00
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
member, _ := p.Source.(projectMember)
// company sub query expects pointer
return member.User, nil
},
},
2019-01-24 16:26:36 +00:00
FieldJoinedAt: &graphql.Field{
2018-12-10 11:38:42 +00:00
Type: graphql.DateTime,
},
},
})
}
func graphqlProjectMembersCursor() *graphql.InputObject {
return graphql.NewInputObject(graphql.InputObjectConfig{
Name: ProjectMembersCursorInputType,
Fields: graphql.InputObjectConfigFieldMap{
SearchArg: &graphql.InputObjectFieldConfig{
Type: graphql.NewNonNull(graphql.String),
},
LimitArg: &graphql.InputObjectFieldConfig{
Type: graphql.NewNonNull(graphql.Int),
},
PageArg: &graphql.InputObjectFieldConfig{
Type: graphql.NewNonNull(graphql.Int),
},
OrderArg: &graphql.InputObjectFieldConfig{
Type: graphql.NewNonNull(graphql.Int),
},
OrderDirectionArg: &graphql.InputObjectFieldConfig{
Type: graphql.NewNonNull(graphql.Int),
},
},
})
}
func graphqlProjectMembersPage(types *TypeCreator) *graphql.Object {
return graphql.NewObject(graphql.ObjectConfig{
Name: ProjectMembersPageType,
Fields: graphql.Fields{
FieldProjectMembers: &graphql.Field{
Type: graphql.NewList(types.projectMember),
},
SearchArg: &graphql.Field{
Type: graphql.String,
},
LimitArg: &graphql.Field{
Type: graphql.Int,
},
OrderArg: &graphql.Field{
Type: graphql.Int,
},
OrderDirectionArg: &graphql.Field{
Type: graphql.Int,
},
OffsetArg: &graphql.Field{
Type: graphql.Int,
},
FieldPageCount: &graphql.Field{
Type: graphql.Int,
},
FieldCurrentPage: &graphql.Field{
Type: graphql.Int,
},
FieldTotalCount: &graphql.Field{
Type: graphql.Int,
},
},
})
}
// projectMember encapsulates User and joinedAt.
2018-12-10 11:38:42 +00:00
type projectMember struct {
User *console.User
2018-12-10 11:38:42 +00:00
JoinedAt time.Time
}
type projectMembersPage struct {
ProjectMembers []projectMember
Search string
Limit uint
Order int
OrderDirection int
Offset uint64
PageCount uint
CurrentPage uint
TotalCount uint64
}