1// Copyright (C) 2019 Storj Labs, Inc. 2// See LICENSE for copying information. 3 4package consoleql 5 6import ( 7 "time" 8 9 "github.com/graphql-go/graphql" 10 11 "storj.io/storj/satellite/console" 12) 13 14const ( 15 // ProjectMemberType is a graphql type name for project member. 16 ProjectMemberType = "projectMember" 17 // FieldJoinedAt is a field name for joined at timestamp. 18 FieldJoinedAt = "joinedAt" 19) 20 21// graphqlProjectMember creates projectMember type. 22func graphqlProjectMember(service *console.Service, types *TypeCreator) *graphql.Object { 23 return graphql.NewObject(graphql.ObjectConfig{ 24 Name: ProjectMemberType, 25 Fields: graphql.Fields{ 26 UserType: &graphql.Field{ 27 Type: types.user, 28 Resolve: func(p graphql.ResolveParams) (interface{}, error) { 29 member, _ := p.Source.(projectMember) 30 // company sub query expects pointer 31 return member.User, nil 32 }, 33 }, 34 FieldJoinedAt: &graphql.Field{ 35 Type: graphql.DateTime, 36 }, 37 }, 38 }) 39} 40 41func graphqlProjectMembersCursor() *graphql.InputObject { 42 return graphql.NewInputObject(graphql.InputObjectConfig{ 43 Name: ProjectMembersCursorInputType, 44 Fields: graphql.InputObjectConfigFieldMap{ 45 SearchArg: &graphql.InputObjectFieldConfig{ 46 Type: graphql.NewNonNull(graphql.String), 47 }, 48 LimitArg: &graphql.InputObjectFieldConfig{ 49 Type: graphql.NewNonNull(graphql.Int), 50 }, 51 PageArg: &graphql.InputObjectFieldConfig{ 52 Type: graphql.NewNonNull(graphql.Int), 53 }, 54 OrderArg: &graphql.InputObjectFieldConfig{ 55 Type: graphql.NewNonNull(graphql.Int), 56 }, 57 OrderDirectionArg: &graphql.InputObjectFieldConfig{ 58 Type: graphql.NewNonNull(graphql.Int), 59 }, 60 }, 61 }) 62} 63 64func graphqlProjectMembersPage(types *TypeCreator) *graphql.Object { 65 return graphql.NewObject(graphql.ObjectConfig{ 66 Name: ProjectMembersPageType, 67 Fields: graphql.Fields{ 68 FieldProjectMembers: &graphql.Field{ 69 Type: graphql.NewList(types.projectMember), 70 }, 71 SearchArg: &graphql.Field{ 72 Type: graphql.String, 73 }, 74 LimitArg: &graphql.Field{ 75 Type: graphql.Int, 76 }, 77 OrderArg: &graphql.Field{ 78 Type: graphql.Int, 79 }, 80 OrderDirectionArg: &graphql.Field{ 81 Type: graphql.Int, 82 }, 83 OffsetArg: &graphql.Field{ 84 Type: graphql.Int, 85 }, 86 FieldPageCount: &graphql.Field{ 87 Type: graphql.Int, 88 }, 89 FieldCurrentPage: &graphql.Field{ 90 Type: graphql.Int, 91 }, 92 FieldTotalCount: &graphql.Field{ 93 Type: graphql.Int, 94 }, 95 }, 96 }) 97} 98 99// projectMember encapsulates User and joinedAt. 100type projectMember struct { 101 User *console.User 102 JoinedAt time.Time 103} 104 105type projectMembersPage struct { 106 ProjectMembers []projectMember 107 108 Search string 109 Limit uint 110 Order int 111 OrderDirection int 112 Offset uint64 113 114 PageCount uint 115 CurrentPage uint 116 TotalCount uint64 117} 118