storj/satellite/console/consoleweb/consoleql/query.go
Yingrong Zhao 89529237a2 web/satellite, web/marketing: remove referral program related UI code
Change-Id: Ia815a72c0d17760bb63d9a37bb18b88952209368
2021-02-08 11:07:35 -05:00

80 lines
2.1 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package consoleql
import (
"github.com/graphql-go/graphql"
"storj.io/common/uuid"
"storj.io/storj/satellite/console"
"storj.io/storj/satellite/mailservice"
)
const (
// Query is immutable graphql request.
Query = "query"
// ProjectQuery is a query name for project.
ProjectQuery = "project"
// OwnedProjectsQuery is a query name for projects owned by an account.
OwnedProjectsQuery = "ownedProjects"
// MyProjectsQuery is a query name for projects related to account.
MyProjectsQuery = "myProjects"
)
// rootQuery creates query for graphql populated by AccountsClient.
func rootQuery(service *console.Service, mailService *mailservice.Service, types *TypeCreator) *graphql.Object {
return graphql.NewObject(graphql.ObjectConfig{
Name: Query,
Fields: graphql.Fields{
ProjectQuery: &graphql.Field{
Type: types.project,
Args: graphql.FieldConfigArgument{
FieldID: &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.String),
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
inputID, _ := p.Args[FieldID].(string)
id, err := uuid.FromString(inputID)
if err != nil {
return nil, err
}
project, err := service.GetProject(p.Context, id)
if err != nil {
return nil, err
}
return project, nil
},
},
OwnedProjectsQuery: &graphql.Field{
Type: types.projectsPage,
Args: graphql.FieldConfigArgument{
CursorArg: &graphql.ArgumentConfig{
Type: graphql.NewNonNull(types.projectsCursor),
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
cursor := fromMapProjectsCursor(p.Args[CursorArg].(map[string]interface{}))
page, err := service.GetUsersOwnedProjectsPage(p.Context, cursor)
return page, err
},
},
MyProjectsQuery: &graphql.Field{
Type: graphql.NewList(types.project),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
projects, err := service.GetUsersProjects(p.Context)
if err != nil {
return nil, err
}
return projects, nil
},
},
},
})
}