Expose new cursor over GraphQL API
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -118,6 +118,7 @@ type Organization implements Node {
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: UserOrder
|
||||
): UserConnection! @goField(forceResolver: true)
|
||||
|
||||
frameworks(
|
||||
@@ -125,6 +126,7 @@ type Organization implements Node {
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: FrameworkOrder
|
||||
): FrameworkConnection! @goField(forceResolver: true)
|
||||
|
||||
vendors(
|
||||
@@ -132,6 +134,7 @@ type Organization implements Node {
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: VendorOrder
|
||||
): VendorConnection! @goField(forceResolver: true)
|
||||
|
||||
peoples(
|
||||
@@ -139,6 +142,7 @@ type Organization implements Node {
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: PeopleOrder
|
||||
): PeopleConnection! @goField(forceResolver: true)
|
||||
|
||||
policies(
|
||||
@@ -146,12 +150,119 @@ type Organization implements Node {
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: PolicyOrder
|
||||
): PolicyConnection! @goField(forceResolver: true)
|
||||
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
enum OrderDirection
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/page.OrderDirection") {
|
||||
ASC @goEnum(value: "github.com/getprobo/probo/pkg/page.OrderDirectionAsc")
|
||||
DESC @goEnum(value: "github.com/getprobo/probo/pkg/page.OrderDirectionDesc")
|
||||
}
|
||||
|
||||
enum PeopleOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.PeopleOrderField") {
|
||||
FULL_NAME
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.PeopleOrderFieldFullName"
|
||||
)
|
||||
CREATED_AT
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.PeopleOrderFieldCreatedAt"
|
||||
)
|
||||
}
|
||||
|
||||
enum VendorOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.VendorOrderField") {
|
||||
NAME
|
||||
}
|
||||
|
||||
enum FrameworkOrderField
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/coredata.FrameworkOrderField"
|
||||
) {
|
||||
NAME
|
||||
}
|
||||
|
||||
enum ControlOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.ControlOrderField") {
|
||||
NAME
|
||||
}
|
||||
|
||||
enum TaskOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.TaskOrderField") {
|
||||
CREATED_AT
|
||||
}
|
||||
|
||||
enum PolicyOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.PolicyOrderField") {
|
||||
NAME
|
||||
}
|
||||
|
||||
enum EvidenceOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.EvidenceOrderField") {
|
||||
CREATED_AT
|
||||
}
|
||||
|
||||
input PeopleOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.PeopleOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: PeopleOrderField!
|
||||
}
|
||||
|
||||
input VendorOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.VendorOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: VendorOrderField!
|
||||
}
|
||||
|
||||
input FrameworkOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.FrameworkOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: FrameworkOrderField!
|
||||
}
|
||||
|
||||
input ControlOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.ControlOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: ControlOrderField!
|
||||
}
|
||||
|
||||
input TaskOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.TaskOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: TaskOrderField!
|
||||
}
|
||||
|
||||
input PolicyOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.PolicyOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: PolicyOrderField!
|
||||
}
|
||||
|
||||
input EvidenceOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.EvidenceOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: EvidenceOrderField!
|
||||
}
|
||||
|
||||
type PeopleConnection {
|
||||
edges: [PeopleEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
@@ -221,6 +332,7 @@ type Framework implements Node {
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: ControlOrder
|
||||
): ControlConnection! @goField(forceResolver: true)
|
||||
|
||||
createdAt: Datetime!
|
||||
@@ -251,6 +363,7 @@ type Control implements Node {
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: TaskOrder
|
||||
): TaskConnection! @goField(forceResolver: true)
|
||||
|
||||
createdAt: Datetime!
|
||||
@@ -281,6 +394,7 @@ type Task implements Node {
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: EvidenceOrder
|
||||
): EvidenceConnection! @goField(forceResolver: true)
|
||||
|
||||
createdAt: Datetime!
|
||||
@@ -347,6 +461,7 @@ type Viewer {
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: OrganizationOrder
|
||||
): OrganizationConnection! @goField(forceResolver: true)
|
||||
}
|
||||
|
||||
@@ -737,3 +852,30 @@ input RemoveUserInput {
|
||||
type RemoveUserPayload {
|
||||
success: Boolean!
|
||||
}
|
||||
|
||||
enum OrganizationOrderField {
|
||||
NAME
|
||||
CREATED_AT
|
||||
UPDATED_AT
|
||||
}
|
||||
|
||||
input OrganizationOrder {
|
||||
direction: OrderDirection!
|
||||
field: OrganizationOrderField!
|
||||
}
|
||||
|
||||
enum UserOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.UserOrderField") {
|
||||
CREATED_AT
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.UserOrderFieldCreatedAt"
|
||||
)
|
||||
}
|
||||
|
||||
input UserOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.UserOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: UserOrderField!
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,11 @@ import (
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewControlConnection(p *page.Page[*coredata.Control]) *ControlConnection {
|
||||
type (
|
||||
ControlOrderBy OrderBy[coredata.ControlOrderField]
|
||||
)
|
||||
|
||||
func NewControlConnection(p *page.Page[*coredata.Control, coredata.ControlOrderField]) *ControlConnection {
|
||||
var edges = make([]*ControlEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
@@ -32,7 +36,7 @@ func NewControlConnection(p *page.Page[*coredata.Control]) *ControlConnection {
|
||||
}
|
||||
}
|
||||
|
||||
func NewControlEdge(c *coredata.Control, orderBy page.OrderField) *ControlEdge {
|
||||
func NewControlEdge(c *coredata.Control, orderBy coredata.ControlOrderField) *ControlEdge {
|
||||
return &ControlEdge{
|
||||
Cursor: c.CursorKey(orderBy),
|
||||
Node: NewControl(c),
|
||||
|
||||
@@ -23,38 +23,13 @@ import (
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewCursor(
|
||||
func NewCursor[O page.OrderField](
|
||||
first *int,
|
||||
after *page.CursorKey,
|
||||
last *int,
|
||||
before *page.CursorKey,
|
||||
) *page.Cursor {
|
||||
var (
|
||||
size int
|
||||
from *page.CursorKey
|
||||
direction = page.Head
|
||||
)
|
||||
|
||||
if first != nil {
|
||||
size = *first
|
||||
direction = page.Head
|
||||
from = after
|
||||
} else if last != nil {
|
||||
size = *last
|
||||
direction = page.Tail
|
||||
from = before
|
||||
}
|
||||
|
||||
return page.NewCursor(size, from, direction, nil)
|
||||
}
|
||||
|
||||
func NewCursorWithOrder(
|
||||
first *int,
|
||||
after *page.CursorKey,
|
||||
last *int,
|
||||
before *page.CursorKey,
|
||||
orderBy *page.OrderBy,
|
||||
) *page.Cursor {
|
||||
orderBy page.OrderBy[O],
|
||||
) *page.Cursor[O] {
|
||||
var (
|
||||
size int
|
||||
from *page.CursorKey
|
||||
|
||||
@@ -19,7 +19,11 @@ import (
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewEvidenceConnection(p *page.Page[*coredata.Evidence]) *EvidenceConnection {
|
||||
type (
|
||||
EvidenceOrderBy OrderBy[coredata.EvidenceOrderField]
|
||||
)
|
||||
|
||||
func NewEvidenceConnection(p *page.Page[*coredata.Evidence, coredata.EvidenceOrderField]) *EvidenceConnection {
|
||||
var edges = make([]*EvidenceEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
@@ -32,7 +36,7 @@ func NewEvidenceConnection(p *page.Page[*coredata.Evidence]) *EvidenceConnection
|
||||
}
|
||||
}
|
||||
|
||||
func NewEvidenceEdge(e *coredata.Evidence, orderBy page.OrderField) *EvidenceEdge {
|
||||
func NewEvidenceEdge(e *coredata.Evidence, orderBy coredata.EvidenceOrderField) *EvidenceEdge {
|
||||
return &EvidenceEdge{
|
||||
Cursor: e.CursorKey(orderBy),
|
||||
Node: NewEvidence(e),
|
||||
|
||||
@@ -19,7 +19,11 @@ import (
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewFrameworkConnection(p *page.Page[*coredata.Framework]) *FrameworkConnection {
|
||||
type (
|
||||
FrameworkOrderBy OrderBy[coredata.FrameworkOrderField]
|
||||
)
|
||||
|
||||
func NewFrameworkConnection(p *page.Page[*coredata.Framework, coredata.FrameworkOrderField]) *FrameworkConnection {
|
||||
var edges = make([]*FrameworkEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
@@ -32,7 +36,7 @@ func NewFrameworkConnection(p *page.Page[*coredata.Framework]) *FrameworkConnect
|
||||
}
|
||||
}
|
||||
|
||||
func NewFrameworkEdge(f *coredata.Framework, orderBy page.OrderField) *FrameworkEdge {
|
||||
func NewFrameworkEdge(f *coredata.Framework, orderBy coredata.FrameworkOrderField) *FrameworkEdge {
|
||||
return &FrameworkEdge{
|
||||
Cursor: f.CursorKey(orderBy),
|
||||
Node: NewFramework(f),
|
||||
|
||||
24
pkg/server/api/console/v1/types/order_by.go
Normal file
24
pkg/server/api/console/v1/types/order_by.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package types
|
||||
|
||||
import "github.com/getprobo/probo/pkg/page"
|
||||
|
||||
type (
|
||||
OrderBy[T page.OrderField] struct {
|
||||
Field T
|
||||
Direction page.OrderDirection
|
||||
}
|
||||
)
|
||||
@@ -19,7 +19,11 @@ import (
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewOrganizationConnection(page *page.Page[*coredata.Organization]) *OrganizationConnection {
|
||||
type (
|
||||
OrganizationOrderBy OrderBy[coredata.OrganizationOrderField]
|
||||
)
|
||||
|
||||
func NewOrganizationConnection(page *page.Page[*coredata.Organization, coredata.OrganizationOrderField]) *OrganizationConnection {
|
||||
var edges = make([]*OrganizationEdge, len(page.Data))
|
||||
|
||||
for i := range edges {
|
||||
@@ -32,7 +36,7 @@ func NewOrganizationConnection(page *page.Page[*coredata.Organization]) *Organiz
|
||||
}
|
||||
}
|
||||
|
||||
func NewOrganizationEdge(o *coredata.Organization, orderBy page.OrderField) *OrganizationEdge {
|
||||
func NewOrganizationEdge(o *coredata.Organization, orderBy coredata.OrganizationOrderField) *OrganizationEdge {
|
||||
return &OrganizationEdge{
|
||||
Cursor: o.CursorKey(orderBy),
|
||||
Node: NewOrganization(o),
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewPageInfo[T page.Paginable](p *page.Page[T]) *PageInfo {
|
||||
func NewPageInfo[T page.Paginable[O], O page.OrderField](p *page.Page[T, O]) *PageInfo {
|
||||
var (
|
||||
startCursor *page.CursorKey
|
||||
endCursor *page.CursorKey
|
||||
|
||||
@@ -19,7 +19,11 @@ import (
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewPeopleConnection(p *page.Page[*coredata.People]) *PeopleConnection {
|
||||
type (
|
||||
PeopleOrderBy OrderBy[coredata.PeopleOrderField]
|
||||
)
|
||||
|
||||
func NewPeopleConnection(p *page.Page[*coredata.People, coredata.PeopleOrderField]) *PeopleConnection {
|
||||
var edges = make([]*PeopleEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
@@ -32,7 +36,7 @@ func NewPeopleConnection(p *page.Page[*coredata.People]) *PeopleConnection {
|
||||
}
|
||||
}
|
||||
|
||||
func NewPeopleEdge(p *coredata.People, orderBy page.OrderField) *PeopleEdge {
|
||||
func NewPeopleEdge(p *coredata.People, orderBy coredata.PeopleOrderField) *PeopleEdge {
|
||||
return &PeopleEdge{
|
||||
Cursor: p.CursorKey(orderBy),
|
||||
Node: NewPeople(p),
|
||||
|
||||
@@ -19,7 +19,11 @@ import (
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewPolicyConnection(page *page.Page[*coredata.Policy]) *PolicyConnection {
|
||||
type (
|
||||
PolicyOrderBy OrderBy[coredata.PolicyOrderField]
|
||||
)
|
||||
|
||||
func NewPolicyConnection(page *page.Page[*coredata.Policy, coredata.PolicyOrderField]) *PolicyConnection {
|
||||
edges := make([]*PolicyEdge, len(page.Data))
|
||||
for i, policy := range page.Data {
|
||||
edges[i] = NewPolicyEdge(policy, page.Cursor.OrderBy.Field)
|
||||
@@ -31,7 +35,7 @@ func NewPolicyConnection(page *page.Page[*coredata.Policy]) *PolicyConnection {
|
||||
}
|
||||
}
|
||||
|
||||
func NewPolicyEdge(policy *coredata.Policy, orderBy page.OrderField) *PolicyEdge {
|
||||
func NewPolicyEdge(policy *coredata.Policy, orderBy coredata.PolicyOrderField) *PolicyEdge {
|
||||
return &PolicyEdge{
|
||||
Cursor: policy.CursorKey(orderBy),
|
||||
Node: NewPolicy(policy),
|
||||
|
||||
@@ -19,7 +19,11 @@ import (
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewTaskConnection(p *page.Page[*coredata.Task]) *TaskConnection {
|
||||
type (
|
||||
TaskOrderBy OrderBy[coredata.TaskOrderField]
|
||||
)
|
||||
|
||||
func NewTaskConnection(p *page.Page[*coredata.Task, coredata.TaskOrderField]) *TaskConnection {
|
||||
var edges = make([]*TaskEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
@@ -32,7 +36,7 @@ func NewTaskConnection(p *page.Page[*coredata.Task]) *TaskConnection {
|
||||
}
|
||||
}
|
||||
|
||||
func NewTaskEdge(t *coredata.Task, orderBy page.OrderField) *TaskEdge {
|
||||
func NewTaskEdge(t *coredata.Task, orderBy coredata.TaskOrderField) *TaskEdge {
|
||||
return &TaskEdge{
|
||||
Cursor: t.CursorKey(orderBy),
|
||||
Node: NewTask(t),
|
||||
|
||||
@@ -62,11 +62,6 @@ type ControlEdge struct {
|
||||
Node *Control `json:"node"`
|
||||
}
|
||||
|
||||
type ControlOrder struct {
|
||||
Direction page.OrderDirection `json:"direction"`
|
||||
Field page.GenericOrderField `json:"field"`
|
||||
}
|
||||
|
||||
type CreateControlInput struct {
|
||||
FrameworkID gid.GID `json:"frameworkId"`
|
||||
Name string `json:"name"`
|
||||
@@ -223,11 +218,6 @@ type EvidenceEdge struct {
|
||||
Node *Evidence `json:"node"`
|
||||
}
|
||||
|
||||
type EvidenceOrder struct {
|
||||
Direction page.OrderDirection `json:"direction"`
|
||||
Field page.GenericOrderField `json:"field"`
|
||||
}
|
||||
|
||||
type Framework struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Version int `json:"version"`
|
||||
@@ -251,11 +241,6 @@ type FrameworkEdge struct {
|
||||
Node *Framework `json:"node"`
|
||||
}
|
||||
|
||||
type FrameworkOrder struct {
|
||||
Direction page.OrderDirection `json:"direction"`
|
||||
Field page.GenericOrderField `json:"field"`
|
||||
}
|
||||
|
||||
type ImportFrameworkInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
File graphql.Upload `json:"file"`
|
||||
@@ -365,11 +350,6 @@ type PolicyEdge struct {
|
||||
Node *Policy `json:"node"`
|
||||
}
|
||||
|
||||
type PolicyOrder struct {
|
||||
Direction page.OrderDirection `json:"direction"`
|
||||
Field page.GenericOrderField `json:"field"`
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
}
|
||||
|
||||
@@ -413,11 +393,6 @@ type TaskEdge struct {
|
||||
Node *Task `json:"node"`
|
||||
}
|
||||
|
||||
type TaskOrder struct {
|
||||
Direction page.OrderDirection `json:"direction"`
|
||||
Field page.GenericOrderField `json:"field"`
|
||||
}
|
||||
|
||||
type UnassignTaskInput struct {
|
||||
TaskID gid.GID `json:"taskId"`
|
||||
}
|
||||
@@ -550,11 +525,6 @@ type UserEdge struct {
|
||||
Node *User `json:"node"`
|
||||
}
|
||||
|
||||
type UserOrder struct {
|
||||
Direction page.OrderDirection `json:"direction"`
|
||||
Field UserOrderField `json:"field"`
|
||||
}
|
||||
|
||||
type Vendor struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@@ -632,48 +602,3 @@ func (e *OrganizationOrderField) UnmarshalGQL(v any) error {
|
||||
func (e OrganizationOrderField) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
||||
}
|
||||
|
||||
type UserOrderField string
|
||||
|
||||
const (
|
||||
UserOrderFieldFullName UserOrderField = "FULL_NAME"
|
||||
UserOrderFieldEmail UserOrderField = "EMAIL"
|
||||
UserOrderFieldCreatedAt UserOrderField = "CREATED_AT"
|
||||
UserOrderFieldUpdatedAt UserOrderField = "UPDATED_AT"
|
||||
)
|
||||
|
||||
var AllUserOrderField = []UserOrderField{
|
||||
UserOrderFieldFullName,
|
||||
UserOrderFieldEmail,
|
||||
UserOrderFieldCreatedAt,
|
||||
UserOrderFieldUpdatedAt,
|
||||
}
|
||||
|
||||
func (e UserOrderField) IsValid() bool {
|
||||
switch e {
|
||||
case UserOrderFieldFullName, UserOrderFieldEmail, UserOrderFieldCreatedAt, UserOrderFieldUpdatedAt:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e UserOrderField) String() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (e *UserOrderField) UnmarshalGQL(v any) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("enums must be strings")
|
||||
}
|
||||
|
||||
*e = UserOrderField(str)
|
||||
if !e.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid UserOrderField", str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e UserOrderField) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
||||
}
|
||||
|
||||
@@ -19,7 +19,11 @@ import (
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewUserConnection(p *page.Page[*coredata.User]) *UserConnection {
|
||||
type (
|
||||
UserOrderBy OrderBy[coredata.UserOrderField]
|
||||
)
|
||||
|
||||
func NewUserConnection(p *page.Page[*coredata.User, coredata.UserOrderField]) *UserConnection {
|
||||
var edges = make([]*UserEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
@@ -32,7 +36,7 @@ func NewUserConnection(p *page.Page[*coredata.User]) *UserConnection {
|
||||
}
|
||||
}
|
||||
|
||||
func NewUserEdge(user *coredata.User, orderBy page.OrderField) *UserEdge {
|
||||
func NewUserEdge(user *coredata.User, orderBy coredata.UserOrderField) *UserEdge {
|
||||
return &UserEdge{
|
||||
Cursor: user.CursorKey(orderBy),
|
||||
Node: NewUser(user),
|
||||
|
||||
@@ -19,7 +19,11 @@ import (
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewVendorConnection(p *page.Page[*coredata.Vendor]) *VendorConnection {
|
||||
type (
|
||||
VendorOrderBy OrderBy[coredata.VendorOrderField]
|
||||
)
|
||||
|
||||
func NewVendorConnection(p *page.Page[*coredata.Vendor, coredata.VendorOrderField]) *VendorConnection {
|
||||
var edges = make([]*VendorEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
@@ -32,7 +36,7 @@ func NewVendorConnection(p *page.Page[*coredata.Vendor]) *VendorConnection {
|
||||
}
|
||||
}
|
||||
|
||||
func NewVendorEdge(v *coredata.Vendor, orderBy page.OrderField) *VendorEdge {
|
||||
func NewVendorEdge(v *coredata.Vendor, orderBy coredata.VendorOrderField) *VendorEdge {
|
||||
return &VendorEdge{
|
||||
Cursor: v.CursorKey(orderBy),
|
||||
Node: NewVendor(v),
|
||||
|
||||
@@ -20,9 +20,21 @@ import (
|
||||
)
|
||||
|
||||
// Tasks is the resolver for the tasks field.
|
||||
func (r *controlResolver) Tasks(ctx context.Context, obj *types.Control, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.TaskOrder) (*types.TaskConnection, error) {
|
||||
func (r *controlResolver) Tasks(ctx context.Context, obj *types.Control, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.TaskOrderBy) (*types.TaskConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
cursor := types.NewCursor(first, after, last, before)
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.TaskOrderField]{
|
||||
Field: coredata.TaskOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.TaskOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := svc.Tasks.ListForControlID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
@@ -45,9 +57,21 @@ func (r *evidenceResolver) FileURL(ctx context.Context, obj *types.Evidence) (st
|
||||
}
|
||||
|
||||
// Controls is the resolver for the controls field.
|
||||
func (r *frameworkResolver) Controls(ctx context.Context, obj *types.Framework, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ControlOrder) (*types.ControlConnection, error) {
|
||||
func (r *frameworkResolver) Controls(ctx context.Context, obj *types.Framework, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ControlOrderBy) (*types.ControlConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
cursor := types.NewCursor(first, after, last, before)
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.ControlOrderField]{
|
||||
Field: coredata.ControlOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.ControlOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := svc.Controls.ListForFrameworkID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
@@ -77,7 +101,7 @@ func (r *mutationResolver) CreateVendor(ctx context.Context, input types.CreateV
|
||||
return nil, fmt.Errorf("cannot create vendor: %w", err)
|
||||
}
|
||||
return &types.CreateVendorPayload{
|
||||
VendorEdge: types.NewVendorEdge(vendor, nil),
|
||||
VendorEdge: types.NewVendorEdge(vendor, coredata.VendorOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -138,7 +162,7 @@ func (r *mutationResolver) CreatePeople(ctx context.Context, input types.CreateP
|
||||
}
|
||||
|
||||
return &types.CreatePeoplePayload{
|
||||
PeopleEdge: types.NewPeopleEdge(people, nil),
|
||||
PeopleEdge: types.NewPeopleEdge(people, coredata.PeopleOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -197,7 +221,7 @@ func (r *mutationResolver) CreateOrganization(ctx context.Context, input types.C
|
||||
*tenantIDs = append(*tenantIDs, organization.ID.TenantID())
|
||||
|
||||
return &types.CreateOrganizationPayload{
|
||||
OrganizationEdge: types.NewOrganizationEdge(organization, nil),
|
||||
OrganizationEdge: types.NewOrganizationEdge(organization, coredata.OrganizationOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -244,7 +268,7 @@ func (r *mutationResolver) CreateTask(ctx context.Context, input types.CreateTas
|
||||
}
|
||||
|
||||
return &types.CreateTaskPayload{
|
||||
TaskEdge: types.NewTaskEdge(task, nil),
|
||||
TaskEdge: types.NewTaskEdge(task, coredata.TaskOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -324,7 +348,7 @@ func (r *mutationResolver) CreateFramework(ctx context.Context, input types.Crea
|
||||
}
|
||||
|
||||
return &types.CreateFrameworkPayload{
|
||||
FrameworkEdge: types.NewFrameworkEdge(framework, nil),
|
||||
FrameworkEdge: types.NewFrameworkEdge(framework, coredata.FrameworkOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -362,7 +386,7 @@ func (r *mutationResolver) ImportFramework(ctx context.Context, input types.Impo
|
||||
}
|
||||
|
||||
return &types.ImportFrameworkPayload{
|
||||
FrameworkEdge: types.NewFrameworkEdge(framework, nil),
|
||||
FrameworkEdge: types.NewFrameworkEdge(framework, coredata.FrameworkOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -382,7 +406,7 @@ func (r *mutationResolver) CreateControl(ctx context.Context, input types.Create
|
||||
}
|
||||
|
||||
return &types.CreateControlPayload{
|
||||
ControlEdge: types.NewControlEdge(control, nil),
|
||||
ControlEdge: types.NewControlEdge(control, coredata.ControlOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -424,7 +448,7 @@ func (r *mutationResolver) UploadEvidence(ctx context.Context, input types.Uploa
|
||||
}
|
||||
|
||||
return &types.UploadEvidencePayload{
|
||||
EvidenceEdge: types.NewEvidenceEdge(evidence, nil),
|
||||
EvidenceEdge: types.NewEvidenceEdge(evidence, coredata.EvidenceOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -459,7 +483,7 @@ func (r *mutationResolver) CreatePolicy(ctx context.Context, input types.CreateP
|
||||
}
|
||||
|
||||
return &types.CreatePolicyPayload{
|
||||
PolicyEdge: types.NewPolicyEdge(policy, nil),
|
||||
PolicyEdge: types.NewPolicyEdge(policy, coredata.PolicyOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -564,8 +588,19 @@ func (r *organizationResolver) LogoURL(ctx context.Context, obj *types.Organizat
|
||||
}
|
||||
|
||||
// Users is the resolver for the users field.
|
||||
func (r *organizationResolver) Users(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.UserOrder) (*types.UserConnection, error) {
|
||||
cursor := types.NewCursor(first, after, last, before)
|
||||
func (r *organizationResolver) Users(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.UserOrderBy) (*types.UserConnection, error) {
|
||||
pageOrderBy := page.OrderBy[coredata.UserOrderField]{
|
||||
Field: coredata.UserOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.UserOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := r.usrmgrSvc.ListUsersForTenant(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
@@ -576,10 +611,21 @@ func (r *organizationResolver) Users(ctx context.Context, obj *types.Organizatio
|
||||
}
|
||||
|
||||
// Frameworks is the resolver for the frameworks field.
|
||||
func (r *organizationResolver) Frameworks(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.FrameworkOrder) (*types.FrameworkConnection, error) {
|
||||
func (r *organizationResolver) Frameworks(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.FrameworkOrderBy) (*types.FrameworkConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before)
|
||||
pageOrderBy := page.OrderBy[coredata.FrameworkOrderField]{
|
||||
Field: coredata.FrameworkOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.FrameworkOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := svc.Frameworks.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
@@ -590,10 +636,21 @@ func (r *organizationResolver) Frameworks(ctx context.Context, obj *types.Organi
|
||||
}
|
||||
|
||||
// Vendors is the resolver for the vendors field.
|
||||
func (r *organizationResolver) Vendors(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *page.OrderBy) (*types.VendorConnection, error) {
|
||||
func (r *organizationResolver) Vendors(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.VendorOrderBy) (*types.VendorConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
|
||||
cursor := types.NewCursorWithOrder(first, after, last, before, orderBy)
|
||||
pageOrderBy := page.OrderBy[coredata.VendorOrderField]{
|
||||
Field: coredata.VendorOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.VendorOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := svc.Vendors.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
@@ -604,10 +661,22 @@ func (r *organizationResolver) Vendors(ctx context.Context, obj *types.Organizat
|
||||
}
|
||||
|
||||
// Peoples is the resolver for the peoples field.
|
||||
func (r *organizationResolver) Peoples(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *page.OrderBy) (*types.PeopleConnection, error) {
|
||||
func (r *organizationResolver) Peoples(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.PeopleOrderBy) (*types.PeopleConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
|
||||
cursor := types.NewCursorWithOrder(first, after, last, before, orderBy)
|
||||
pageOrderBy := page.OrderBy[coredata.PeopleOrderField]{
|
||||
Field: coredata.PeopleOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.PeopleOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := svc.Peoples.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list organization peoples: %w", err)
|
||||
@@ -617,10 +686,21 @@ func (r *organizationResolver) Peoples(ctx context.Context, obj *types.Organizat
|
||||
}
|
||||
|
||||
// Policies is the resolver for the policies field.
|
||||
func (r *organizationResolver) Policies(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.PolicyOrder) (*types.PolicyConnection, error) {
|
||||
func (r *organizationResolver) Policies(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.PolicyOrderBy) (*types.PolicyConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before)
|
||||
pageOrderBy := page.OrderBy[coredata.PolicyOrderField]{
|
||||
Field: coredata.PolicyOrderFieldName,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.PolicyOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := svc.Policies.ListByOrganizationID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
@@ -747,10 +827,21 @@ func (r *taskResolver) AssignedTo(ctx context.Context, obj *types.Task) (*types.
|
||||
}
|
||||
|
||||
// Evidences is the resolver for the evidences field.
|
||||
func (r *taskResolver) Evidences(ctx context.Context, obj *types.Task, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.EvidenceOrder) (*types.EvidenceConnection, error) {
|
||||
func (r *taskResolver) Evidences(ctx context.Context, obj *types.Task, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.EvidenceOrderBy) (*types.EvidenceConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
cursor := types.NewCursor(first, after, last, before)
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.EvidenceOrderField]{
|
||||
Field: coredata.EvidenceOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.EvidenceOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
page, err := svc.Evidences.ListForTaskID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to list task evidences: %w", err))
|
||||
@@ -771,7 +862,7 @@ func (r *viewerResolver) Organizations(ctx context.Context, obj *types.Viewer, f
|
||||
|
||||
var edges []*types.OrganizationEdge
|
||||
for _, organization := range organizations {
|
||||
edges = append(edges, types.NewOrganizationEdge(organization, nil))
|
||||
edges = append(edges, types.NewOrganizationEdge(organization, coredata.OrganizationOrderFieldCreatedAt))
|
||||
}
|
||||
|
||||
// The simple implementation doesn't handle pagination yet
|
||||
@@ -820,23 +911,3 @@ type policyResolver struct{ *Resolver }
|
||||
type queryResolver struct{ *Resolver }
|
||||
type taskResolver struct{ *Resolver }
|
||||
type viewerResolver struct{ *Resolver }
|
||||
|
||||
// !!! WARNING !!!
|
||||
// The code below was going to be deleted when updating resolvers. It has been copied here so you have
|
||||
// one last chance to move it out of harms way if you want. There are two reasons this happens:
|
||||
// - When renaming or deleting a resolver the old code will be put in here. You can safely delete
|
||||
// it when you're done.
|
||||
// - You have helper methods in this file. Move them out to keep these resolver files clean.
|
||||
/*
|
||||
func (r *peopleOrderResolver) Field(ctx context.Context, obj *page.OrderBy, data page.GenericOrderField) error {
|
||||
panic(fmt.Errorf("not implemented: Field - field"))
|
||||
}
|
||||
func (r *vendorOrderResolver) Field(ctx context.Context, obj *page.OrderBy, data page.GenericOrderField) error {
|
||||
obj.Field = data
|
||||
return nil
|
||||
}
|
||||
func (r *Resolver) PeopleOrder() schema.PeopleOrderResolver { return &peopleOrderResolver{r} }
|
||||
func (r *Resolver) VendorOrder() schema.VendorOrderResolver { return &vendorOrderResolver{r} }
|
||||
type peopleOrderResolver struct{ *Resolver }
|
||||
type vendorOrderResolver struct{ *Resolver }
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user