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.90 import ( "context" "errors" "fmt" "github.com/vikstrous/dataloadgen" "go.gearno.de/kit/log" "go.probo.inc/probo/pkg/coredata" "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" ) // Owner is the resolver for the owner field. func (r *assetResolver) Owner(ctx context.Context, obj *types.Asset) (*types.Profile, error) { if _, err := r.authorize(ctx, obj.ID, iam.ActionMembershipProfileGet); err != nil { return nil, err } loaders := dataloader.FromContext(ctx) owner, err := loaders.Profile.Load(ctx, obj.Owner.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 get owner", log.Error(err)) return nil, gqlutils.Internal(ctx) } return types.NewProfile(owner), nil } // ThirdParties is the resolver for the thirdParties field. func (r *assetResolver) ThirdParties(ctx context.Context, obj *types.Asset, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ThirdPartyOrderBy) (*types.ThirdPartyConnection, error) { scope, err := r.authorize(ctx, obj.ID, probo.ActionThirdPartyList) if err != nil { return nil, err } pageOrderBy := page.OrderBy[coredata.ThirdPartyOrderField]{ Field: coredata.ThirdPartyOrderFieldCreatedAt, Direction: page.OrderDirectionDesc, } if orderBy != nil { pageOrderBy = page.OrderBy[coredata.ThirdPartyOrderField]{ Field: orderBy.Field, Direction: orderBy.Direction, } } cursor := types.NewCursor(first, after, last, before, pageOrderBy) page, err := r.probo.ThirdParties.ListForAssetID(ctx, scope, obj.ID, cursor) if err != nil { r.logger.ErrorCtx(ctx, "cannot list asset thirdParties", log.Error(err)) return nil, gqlutils.Internal(ctx) } return types.NewThirdPartyConnection(page, r, obj.ID, nil), nil } // Organization is the resolver for the organization field. func (r *assetResolver) Organization(ctx context.Context, obj *types.Asset) (*types.Organization, error) { scope, err := r.authorize(ctx, obj.ID, probo.ActionOrganizationGet) if err != nil { return nil, err } asset, err := r.probo.Assets.Get(ctx, scope, obj.ID) if err != nil { r.logger.ErrorCtx(ctx, "cannot load audit", log.Error(err)) return nil, gqlutils.Internal(ctx) } org, err := r.probo.Organizations.Get(ctx, scope, asset.OrganizationID) if err != nil { if errors.Is(err, coredata.ErrResourceNotFound) { return nil, gqlutils.NotFound(ctx, err) } r.logger.ErrorCtx(ctx, "cannot get organization", log.Error(err)) return nil, gqlutils.Internal(ctx) } return types.NewOrganization(org), nil } // Permission is the resolver for the permission field. func (r *assetResolver) Permission(ctx context.Context, obj *types.Asset, action string) (bool, error) { return r.Resolver.Permission(ctx, obj, action) } // TotalCount is the resolver for the totalCount field. func (r *assetConnectionResolver) TotalCount(ctx context.Context, obj *types.AssetConnection) (int, error) { scope, err := r.authorize(ctx, obj.ParentID, probo.ActionAssetList) if err != nil { return 0, err } switch obj.Resolver.(type) { case *organizationResolver: count, err := r.probo.Assets.CountForOrganizationID(ctx, scope, obj.ParentID) if err != nil { r.logger.ErrorCtx(ctx, "cannot count assets", log.Error(err)) return 0, gqlutils.Internal(ctx) } return count, nil } r.logger.ErrorCtx(ctx, "unsupported resolver") return 0, gqlutils.Internal(ctx) } // Owner is the resolver for the owner field. func (r *datumResolver) Owner(ctx context.Context, obj *types.Datum) (*types.Profile, error) { if _, err := r.authorize(ctx, obj.ID, iam.ActionMembershipProfileGet); err != nil { return nil, err } loaders := dataloader.FromContext(ctx) owner, err := loaders.Profile.Load(ctx, obj.Owner.ID) if err != nil { if errors.Is(err, coredata.ErrResourceNotFound) || errors.Is(err, dataloadgen.ErrNotFound) { return nil, gqlutils.NotFound(ctx, err) } return nil, fmt.Errorf("cannot get owner: %w", err) } return types.NewProfile(owner), nil } // ThirdParties is the resolver for the thirdParties field. func (r *datumResolver) ThirdParties(ctx context.Context, obj *types.Datum, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ThirdPartyOrderBy) (*types.ThirdPartyConnection, error) { scope, err := r.authorize(ctx, obj.ID, probo.ActionThirdPartyList) if err != nil { return nil, err } pageOrderBy := page.OrderBy[coredata.ThirdPartyOrderField]{ Field: coredata.ThirdPartyOrderFieldCreatedAt, Direction: page.OrderDirectionDesc, } if orderBy != nil { pageOrderBy = page.OrderBy[coredata.ThirdPartyOrderField]{ Field: orderBy.Field, Direction: orderBy.Direction, } } cursor := types.NewCursor(first, after, last, before, pageOrderBy) page, err := r.probo.Data.ListThirdParties(ctx, scope, obj.ID, cursor) if err != nil { r.logger.ErrorCtx(ctx, "cannot list data thirdParties", log.Error(err)) return nil, gqlutils.Internal(ctx) } return types.NewThirdPartyConnection(page, r, obj.ID, nil), nil } // Organization is the resolver for the organization field. func (r *datumResolver) Organization(ctx context.Context, obj *types.Datum) (*types.Organization, error) { if _, err := r.authorize(ctx, obj.ID, probo.ActionOrganizationGet); err != nil { return nil, err } loaders := dataloader.FromContext(ctx) org, err := loaders.Organization.Load(ctx, obj.OrganizationID) 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 get organization", log.Error(err)) return nil, gqlutils.Internal(ctx) } return types.NewOrganization(org), nil } // Permission is the resolver for the permission field. func (r *datumResolver) Permission(ctx context.Context, obj *types.Datum, action string) (bool, error) { return r.Resolver.Permission(ctx, obj, action) } // TotalCount is the resolver for the totalCount field. func (r *datumConnectionResolver) TotalCount(ctx context.Context, obj *types.DatumConnection) (int, error) { scope, err := r.authorize(ctx, obj.ParentID, probo.ActionDatumList) if err != nil { return 0, err } switch obj.Resolver.(type) { case *organizationResolver: count, err := r.probo.Data.CountForOrganizationID(ctx, scope, obj.ParentID) if err != nil { r.logger.ErrorCtx(ctx, "cannot count data", log.Error(err)) return 0, gqlutils.Internal(ctx) } return count, nil } r.logger.ErrorCtx(ctx, "unsupported resolver") return 0, gqlutils.Internal(ctx) } // CreateAsset is the resolver for the createAsset field. func (r *mutationResolver) CreateAsset(ctx context.Context, input types.CreateAssetInput) (*types.CreateAssetPayload, error) { scope, err := r.authorize(ctx, input.OrganizationID, probo.ActionAssetCreate) if err != nil { return nil, err } asset, err := r.probo.Assets.Create( ctx, scope, probo.CreateAssetRequest{ OrganizationID: input.OrganizationID, Name: input.Name, Amount: input.Amount, OwnerID: input.OwnerID, AssetType: input.AssetType, DataTypesStored: input.DataTypesStored, ThirdPartyIDs: input.ThirdPartyIds, }, ) if err != nil { if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok { return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors) } r.logger.ErrorCtx(ctx, "cannot create asset", log.Error(err)) return nil, gqlutils.Internal(ctx) } return &types.CreateAssetPayload{ AssetEdge: types.NewAssetEdge(asset, coredata.AssetOrderFieldCreatedAt), }, nil } // UpdateAsset is the resolver for the updateAsset field. func (r *mutationResolver) UpdateAsset(ctx context.Context, input types.UpdateAssetInput) (*types.UpdateAssetPayload, error) { scope, err := r.authorize(ctx, input.ID, probo.ActionAssetUpdate) if err != nil { return nil, err } asset, err := r.probo.Assets.Update( ctx, scope, probo.UpdateAssetRequest{ ID: input.ID, Name: input.Name, Amount: input.Amount, OwnerID: input.OwnerID, AssetType: input.AssetType, DataTypesStored: input.DataTypesStored, ThirdPartyIDs: input.ThirdPartyIds, }, ) if err != nil { if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok { return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors) } r.logger.ErrorCtx(ctx, "cannot update asset", log.Error(err)) return nil, gqlutils.Internal(ctx) } return &types.UpdateAssetPayload{ Asset: types.NewAsset(asset), }, nil } // DeleteAsset is the resolver for the deleteAsset field. func (r *mutationResolver) DeleteAsset(ctx context.Context, input types.DeleteAssetInput) (*types.DeleteAssetPayload, error) { scope, err := r.authorize(ctx, input.AssetID, probo.ActionAssetDelete) if err != nil { return nil, err } if err := r.probo.Assets.Delete(ctx, scope, input.AssetID); err != nil { r.logger.ErrorCtx(ctx, "cannot delete asset", log.Error(err)) return nil, gqlutils.Internal(ctx) } return &types.DeleteAssetPayload{ DeletedAssetID: input.AssetID, }, nil } // CreateDatum is the resolver for the createDatum field. func (r *mutationResolver) CreateDatum(ctx context.Context, input types.CreateDatumInput) (*types.CreateDatumPayload, error) { scope, err := r.authorize(ctx, input.OrganizationID, probo.ActionDatumCreate) if err != nil { return nil, err } data, err := r.probo.Data.Create( ctx, scope, probo.CreateDatumRequest{ OrganizationID: input.OrganizationID, Name: input.Name, DataClassification: input.DataClassification, OwnerID: input.OwnerID, ThirdPartyIDs: input.ThirdPartyIds, }, ) if err != nil { if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok { return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors) } r.logger.ErrorCtx(ctx, "cannot create datum", log.Error(err)) return nil, gqlutils.Internal(ctx) } return &types.CreateDatumPayload{ DatumEdge: types.NewDatumEdge(data, coredata.DatumOrderFieldCreatedAt), }, nil } // UpdateDatum is the resolver for the updateDatum field. func (r *mutationResolver) UpdateDatum(ctx context.Context, input types.UpdateDatumInput) (*types.UpdateDatumPayload, error) { scope, err := r.authorize(ctx, input.ID, probo.ActionDatumUpdate) if err != nil { return nil, err } datum, err := r.probo.Data.Update( ctx, scope, probo.UpdateDatumRequest{ ID: input.ID, Name: input.Name, DataClassification: input.DataClassification, OwnerID: input.OwnerID, ThirdPartyIDs: input.ThirdPartyIds, }, ) if err != nil { if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok { return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors) } r.logger.ErrorCtx(ctx, "cannot update datum", log.Error(err)) return nil, gqlutils.Internal(ctx) } return &types.UpdateDatumPayload{ Datum: types.NewDatum(datum), }, nil } // DeleteDatum is the resolver for the deleteDatum field. func (r *mutationResolver) DeleteDatum(ctx context.Context, input types.DeleteDatumInput) (*types.DeleteDatumPayload, error) { scope, err := r.authorize(ctx, input.DatumID, probo.ActionDatumDelete) if err != nil { return nil, err } if err := r.probo.Data.Delete(ctx, scope, input.DatumID); err != nil { r.logger.ErrorCtx(ctx, "cannot delete datum", log.Error(err)) return nil, gqlutils.Internal(ctx) } return &types.DeleteDatumPayload{ DeletedDatumID: input.DatumID, }, nil } // PublishDataList is the resolver for the publishDataList field. func (r *mutationResolver) PublishDataList(ctx context.Context, input types.PublishDataListInput) (*types.PublishDataListPayload, error) { scope, err := r.authorize(ctx, input.OrganizationID, probo.ActionDatumPublish) if err != nil { return nil, err } document, documentVersion, err := r.probo.GeneratedDocuments.PublishDataList(ctx, scope, input.OrganizationID, input.ApproverIds, input.Minor) if err != nil { if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, gqlutils.Conflict(ctx, err) } r.logger.ErrorCtx(ctx, "cannot publish data list", log.Error(err)) return nil, gqlutils.Internal(ctx) } return &types.PublishDataListPayload{ DocumentEdge: types.NewDocumentEdge(document, coredata.DocumentOrderFieldCreatedAt), DocumentVersionEdge: types.NewDocumentVersionEdge(documentVersion, coredata.DocumentVersionOrderFieldCreatedAt), }, nil } // PublishAssetList is the resolver for the publishAssetList field. func (r *mutationResolver) PublishAssetList(ctx context.Context, input types.PublishAssetListInput) (*types.PublishAssetListPayload, error) { scope, err := r.authorize(ctx, input.OrganizationID, probo.ActionAssetPublish) if err != nil { return nil, err } document, documentVersion, err := r.probo.GeneratedDocuments.PublishAssetList(ctx, scope, input.OrganizationID, input.ApproverIds, input.Minor) if err != nil { if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, gqlutils.Conflict(ctx, err) } r.logger.ErrorCtx(ctx, "cannot publish asset list", log.Error(err)) return nil, gqlutils.Internal(ctx) } return &types.PublishAssetListPayload{ DocumentEdge: types.NewDocumentEdge(document, coredata.DocumentOrderFieldCreatedAt), DocumentVersionEdge: types.NewDocumentVersionEdge(documentVersion, coredata.DocumentVersionOrderFieldCreatedAt), }, nil } // Asset returns schema.AssetResolver implementation. func (r *Resolver) Asset() schema.AssetResolver { return &assetResolver{r} } // AssetConnection returns schema.AssetConnectionResolver implementation. func (r *Resolver) AssetConnection() schema.AssetConnectionResolver { return &assetConnectionResolver{r} } // Datum returns schema.DatumResolver implementation. func (r *Resolver) Datum() schema.DatumResolver { return &datumResolver{r} } // DatumConnection returns schema.DatumConnectionResolver implementation. func (r *Resolver) DatumConnection() schema.DatumConnectionResolver { return &datumConnectionResolver{r} } type assetResolver struct{ *Resolver } type assetConnectionResolver struct{ *Resolver } type datumResolver struct{ *Resolver } type datumConnectionResolver struct{ *Resolver }