Split each API's monolithic schema.graphql into per-coredata-model
files under graphql/ subdirectories. gqlgen's follow-schema layout
with {name}.resolvers.go template generates one resolver file per
schema file. Relay uses schema + schemaExtensions to load the split
files.
Connect API: 8 files (base, session, organization, profile,
personal_api_key, saml, scim, audit_log)
Trust API: 5 files (base, trust_center, auth, nda, mailing_list)
Console API: 25 files covering all domain entities
Types extended across files (Organization, Mutation, Viewer,
TrustCenter, Identity) are defined in base.graphql as required by
Relay's schemaExtensions.
Signed-off-by: Émile Ré <emile@getprobo.com>
228 lines
7.2 KiB
Go
228 lines
7.2 KiB
Go
package console_v1
|
|
|
|
// This file will be automatically regenerated based on the schema, any resolver
|
|
// implementations
|
|
// will be copied through when generating and any unknown code will be moved to the end.
|
|
// Code generated by github.com/99designs/gqlgen version v0.17.87
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/vikstrous/dataloadgen"
|
|
"go.gearno.de/kit/log"
|
|
"go.probo.inc/probo/pkg/coredata"
|
|
"go.probo.inc/probo/pkg/gid"
|
|
"go.probo.inc/probo/pkg/iam"
|
|
"go.probo.inc/probo/pkg/page"
|
|
"go.probo.inc/probo/pkg/probo"
|
|
"go.probo.inc/probo/pkg/server/api/console/v1/dataloader"
|
|
"go.probo.inc/probo/pkg/server/api/console/v1/schema"
|
|
"go.probo.inc/probo/pkg/server/api/console/v1/types"
|
|
"go.probo.inc/probo/pkg/server/gqlutils"
|
|
"go.probo.inc/probo/pkg/validator"
|
|
)
|
|
|
|
// Attendees is the resolver for the attendees field.
|
|
func (r *meetingResolver) Attendees(ctx context.Context, obj *types.Meeting) ([]*types.Profile, error) {
|
|
// TODO bug must be paginated
|
|
|
|
if err := r.authorize(ctx, obj.ID, iam.ActionMembershipProfileList); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
attendees, err := prb.Meetings.GetAttendees(ctx, obj.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot load meeting attendees", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
if len(attendees) == 0 {
|
|
return []*types.Profile{}, nil
|
|
}
|
|
|
|
people := make([]*types.Profile, len(attendees))
|
|
for i, attendee := range attendees {
|
|
people[i] = types.NewProfile(attendee)
|
|
}
|
|
|
|
return people, nil
|
|
}
|
|
|
|
// Organization is the resolver for the organization field.
|
|
func (r *meetingResolver) Organization(ctx context.Context, obj *types.Meeting) (*types.Organization, error) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionOrganizationGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
loaders := dataloader.FromContext(ctx)
|
|
|
|
organization, err := loaders.Organization.Load(ctx, obj.Organization.ID)
|
|
if err != nil {
|
|
if errors.Is(err, coredata.ErrResourceNotFound) || errors.Is(err, dataloadgen.ErrNotFound) {
|
|
return nil, gqlutils.NotFound(ctx, err)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot load organization", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewOrganization(organization), nil
|
|
}
|
|
|
|
// Permission is the resolver for the permission field.
|
|
func (r *meetingResolver) Permission(ctx context.Context, obj *types.Meeting, action string) (bool, error) {
|
|
return r.Resolver.Permission(ctx, obj, action)
|
|
}
|
|
|
|
// TotalCount is the resolver for the totalCount field.
|
|
func (r *meetingConnectionResolver) TotalCount(ctx context.Context, obj *types.MeetingConnection) (int, error) {
|
|
if err := r.authorize(ctx, obj.ParentID, probo.ActionMeetingList); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
|
|
|
switch obj.Resolver.(type) {
|
|
case *organizationResolver:
|
|
count, err := prb.Meetings.CountForOrganizationID(ctx, obj.ParentID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot count meetings", log.Error(err))
|
|
return 0, gqlutils.Internal(ctx)
|
|
}
|
|
return count, nil
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "unsupported resolver")
|
|
return 0, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
// CreateMeeting is the resolver for the createMeeting field.
|
|
func (r *mutationResolver) CreateMeeting(ctx context.Context, input types.CreateMeetingInput) (*types.CreateMeetingPayload, error) {
|
|
if err := r.authorize(ctx, input.OrganizationID, probo.ActionMeetingCreate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
|
|
|
meeting, err := prb.Meetings.Create(
|
|
ctx,
|
|
probo.CreateMeetingRequest{
|
|
OrganizationID: input.OrganizationID,
|
|
Name: input.Name,
|
|
Date: input.Date,
|
|
AttendeeIDs: input.AttendeeIds,
|
|
Minutes: input.Minutes,
|
|
},
|
|
)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
r.logger.ErrorCtx(ctx, "cannot create meeting", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.CreateMeetingPayload{
|
|
MeetingEdge: types.NewMeetingEdge(meeting, coredata.MeetingOrderFieldCreatedAt),
|
|
}, nil
|
|
}
|
|
|
|
// UpdateMeeting is the resolver for the updateMeeting field.
|
|
func (r *mutationResolver) UpdateMeeting(ctx context.Context, input types.UpdateMeetingInput) (*types.UpdateMeetingPayload, error) {
|
|
if err := r.authorize(ctx, input.MeetingID, probo.ActionMeetingUpdate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.MeetingID.TenantID())
|
|
|
|
var attendeeIDs []gid.GID
|
|
if input.AttendeeIds != nil {
|
|
attendeeIDs = input.AttendeeIds
|
|
}
|
|
|
|
meeting, err := prb.Meetings.Update(
|
|
ctx,
|
|
probo.UpdateMeetingRequest{
|
|
MeetingID: input.MeetingID,
|
|
Name: input.Name,
|
|
Date: input.Date,
|
|
AttendeeIDs: attendeeIDs,
|
|
Minutes: gqlutils.UnwrapOmittable(input.Minutes),
|
|
},
|
|
)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
r.logger.ErrorCtx(ctx, "cannot update meeting", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.UpdateMeetingPayload{
|
|
Meeting: types.NewMeeting(meeting),
|
|
}, nil
|
|
}
|
|
|
|
// DeleteMeeting is the resolver for the deleteMeeting field.
|
|
func (r *mutationResolver) DeleteMeeting(ctx context.Context, input types.DeleteMeetingInput) (*types.DeleteMeetingPayload, error) {
|
|
if err := r.authorize(ctx, input.MeetingID, probo.ActionMeetingDelete); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.MeetingID.TenantID())
|
|
|
|
err := prb.Meetings.Delete(ctx, input.MeetingID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot delete meeting", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.DeleteMeetingPayload{
|
|
DeletedMeetingID: input.MeetingID,
|
|
}, nil
|
|
}
|
|
|
|
// Meetings is the resolver for the meetings field.
|
|
func (r *organizationResolver) Meetings(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.MeetingOrderBy) (*types.MeetingConnection, error) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionMeetingList); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
pageOrderBy := page.OrderBy[coredata.MeetingOrderField]{
|
|
Field: coredata.MeetingOrderFieldCreatedAt,
|
|
Direction: page.OrderDirectionDesc,
|
|
}
|
|
if orderBy != nil {
|
|
pageOrderBy = page.OrderBy[coredata.MeetingOrderField]{
|
|
Field: orderBy.Field,
|
|
Direction: orderBy.Direction,
|
|
}
|
|
}
|
|
|
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
|
|
|
page, err := prb.Meetings.ListForOrganizationID(ctx, obj.ID, cursor)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot list organization meetings", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewMeetingConnection(page, r, obj.ID), nil
|
|
}
|
|
|
|
// Meeting returns schema.MeetingResolver implementation.
|
|
func (r *Resolver) Meeting() schema.MeetingResolver { return &meetingResolver{r} }
|
|
|
|
// MeetingConnection returns schema.MeetingConnectionResolver implementation.
|
|
func (r *Resolver) MeetingConnection() schema.MeetingConnectionResolver {
|
|
return &meetingConnectionResolver{r}
|
|
}
|
|
|
|
type meetingResolver struct{ *Resolver }
|
|
type meetingConnectionResolver struct{ *Resolver }
|