From 06fcd85bf9817c30fbc0b9284044b02fba9317f1 Mon Sep 17 00:00:00 2001 From: Steven Wade Date: Tue, 3 Dec 2024 11:39:06 -0500 Subject: [PATCH] feat: address feedback around comments and naming --- pkg/graph/generated/generated.go | 14 ++++---------- pkg/graph/resolvers/mto_category.go | 10 +++++----- pkg/graph/schema/types/mto_milestone.graphql | 2 -- pkg/models/mto_category.go | 7 ++++--- pkg/storage/loaders/mto_category.go | 2 +- pkg/storage/loaders/mto_milestone.go | 2 +- pkg/storage/mto_category.go | 4 ++-- pkg/storage/mto_milestone.go | 4 ++-- src/gql/generated/graphql.ts | 6 +----- 9 files changed, 20 insertions(+), 31 deletions(-) diff --git a/pkg/graph/generated/generated.go b/pkg/graph/generated/generated.go index 3ed446b869..2863f1bce3 100644 --- a/pkg/graph/generated/generated.go +++ b/pkg/graph/generated/generated.go @@ -17129,8 +17129,6 @@ type MTOMilestone { solutions: [MTOSolution!]! """ Category resolves relational category information. - if a milestone is uncategorized, this struct will still return - it will have a null value for both """ categories: MTOCategories! } @@ -31301,9 +31299,9 @@ func (ec *executionContext) _MTOCategories_category(ctx context.Context, field g } return graphql.Null } - res := resTmp.(models.MTOCategory) + res := resTmp.(*models.MTOCategory) fc.Result = res - return ec.marshalNMTOCategory2githubᚗcomᚋcmsᚑenterpriseᚋmintᚑappᚋpkgᚋmodelsᚐMTOCategory(ctx, field.Selections, res) + return ec.marshalNMTOCategory2ᚖgithubᚗcomᚋcmsᚑenterpriseᚋmintᚑappᚋpkgᚋmodelsᚐMTOCategory(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_MTOCategories_category(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -31357,9 +31355,9 @@ func (ec *executionContext) _MTOCategories_subCategory(ctx context.Context, fiel } return graphql.Null } - res := resTmp.(models.MTOSubcategory) + res := resTmp.(*models.MTOSubcategory) fc.Result = res - return ec.marshalNMTOSubcategory2githubᚗcomᚋcmsᚑenterpriseᚋmintᚑappᚋpkgᚋmodelsᚐMTOSubcategory(ctx, field.Selections, res) + return ec.marshalNMTOSubcategory2ᚖgithubᚗcomᚋcmsᚑenterpriseᚋmintᚑappᚋpkgᚋmodelsᚐMTOSubcategory(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_MTOCategories_subCategory(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -156558,10 +156556,6 @@ func (ec *executionContext) marshalNMTOStatus2githubᚗcomᚋcmsᚑenterpriseᚋ return res } -func (ec *executionContext) marshalNMTOSubcategory2githubᚗcomᚋcmsᚑenterpriseᚋmintᚑappᚋpkgᚋmodelsᚐMTOSubcategory(ctx context.Context, sel ast.SelectionSet, v models.MTOSubcategory) graphql.Marshaler { - return ec._MTOSubcategory(ctx, sel, &v) -} - func (ec *executionContext) marshalNMTOSubcategory2ᚕᚖgithubᚗcomᚋcmsᚑenterpriseᚋmintᚑappᚋpkgᚋmodelsᚐMTOSubcategoryᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.MTOSubcategory) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup diff --git a/pkg/graph/resolvers/mto_category.go b/pkg/graph/resolvers/mto_category.go index c2d38074c2..e4b4815710 100644 --- a/pkg/graph/resolvers/mto_category.go +++ b/pkg/graph/resolvers/mto_category.go @@ -151,8 +151,8 @@ func MTOCategoryGetByID(ctx context.Context, id uuid.UUID) (*models.MTOCategory, // We are not doing a larger SQL call that would return both objects, as that would result in less maintainable code func MTOCategoriesGetByID(ctx context.Context, id *uuid.UUID, modelPlanID uuid.UUID) (*models.MTOCategories, error) { Categories := &models.MTOCategories{ - Category: *models.MTOUncategorized(modelPlanID, nil, 0), - SubCategory: *models.MTOUncategorizedSubcategory(modelPlanID, helpers.PointerTo(uuid.Nil), 0), + Category: models.MTOUncategorized(modelPlanID, nil, 0), + SubCategory: models.MTOUncategorizedSubcategory(modelPlanID, helpers.PointerTo(uuid.Nil), 0), } if id == nil { return Categories, nil @@ -163,7 +163,7 @@ func MTOCategoriesGetByID(ctx context.Context, id *uuid.UUID, modelPlanID uuid.U } // Check if it is a parent category, if so early return without fetching parent if immediateCategory.ParentID == nil { - Categories.Category = *immediateCategory + Categories.Category = immediateCategory return Categories, nil } @@ -172,8 +172,8 @@ func MTOCategoriesGetByID(ctx context.Context, id *uuid.UUID, modelPlanID uuid.U if err != nil { return nil, err } - Categories.SubCategory = *immediateCategory.ToSubcategory() - Categories.Category = *parentCategory + Categories.SubCategory = immediateCategory.ToSubcategory() + Categories.Category = parentCategory return Categories, nil } diff --git a/pkg/graph/schema/types/mto_milestone.graphql b/pkg/graph/schema/types/mto_milestone.graphql index 3e4a8184b7..b4f1775776 100644 --- a/pkg/graph/schema/types/mto_milestone.graphql +++ b/pkg/graph/schema/types/mto_milestone.graphql @@ -38,8 +38,6 @@ type MTOMilestone { solutions: [MTOSolution!]! """ Category resolves relational category information. - if a milestone is uncategorized, this struct will still return - it will have a null value for both """ categories: MTOCategories! } diff --git a/pkg/models/mto_category.go b/pkg/models/mto_category.go index 9f021902fe..338ebc473c 100644 --- a/pkg/models/mto_category.go +++ b/pkg/models/mto_category.go @@ -22,10 +22,11 @@ type MTOCategory struct { ParentID *uuid.UUID `json:"parent_id" db:"parent_id"` } +// MTOCategories is a struct meant to represent the Category and Subcategory associated with a given MTO Milestone. +// This struct exists to allow us to resolve/fetch both Category and Subcategory at the same time and return them together in a single resolver. type MTOCategories struct { - // TODO (mto) should these fields be pointers? Technically they should never be null - Category MTOCategory `json:"category,omitempty"` - SubCategory MTOSubcategory `json:"subCategory,omitempty"` + Category *MTOCategory `json:"category,omitempty"` + SubCategory *MTOSubcategory `json:"subCategory,omitempty"` } func (m MTOCategory) GetPosition() int { diff --git a/pkg/storage/loaders/mto_category.go b/pkg/storage/loaders/mto_category.go index ef015ee1c5..fbf9b87440 100644 --- a/pkg/storage/loaders/mto_category.go +++ b/pkg/storage/loaders/mto_category.go @@ -47,7 +47,7 @@ func batchMTOCategoryGetByID(ctx context.Context, ids []uuid.UUID) []*dataloader if err != nil { return errorPerEachKey[uuid.UUID, *models.MTOCategory](ids, err) } - data, err := storage.MTOCategoryGetByIDsLoader(loaders.DataReader.Store, logger, ids) + data, err := storage.MTOCategoryGetByIDLoader(loaders.DataReader.Store, logger, ids) if err != nil { return errorPerEachKey[uuid.UUID, *models.MTOCategory](ids, err) } diff --git a/pkg/storage/loaders/mto_milestone.go b/pkg/storage/loaders/mto_milestone.go index 4a85670503..2c645f2bbe 100644 --- a/pkg/storage/loaders/mto_milestone.go +++ b/pkg/storage/loaders/mto_milestone.go @@ -36,7 +36,7 @@ func batchMTOMilestoneGetByID(ctx context.Context, ids []uuid.UUID) []*dataloade if err != nil { return errorPerEachKey[uuid.UUID, *models.MTOMilestone](ids, err) } - data, err := storage.MTOMilestoneGetByIDsLoader(loaders.DataReader.Store, logger, ids) + data, err := storage.MTOMilestoneGetByIDLoader(loaders.DataReader.Store, logger, ids) if err != nil { return errorPerEachKey[uuid.UUID, *models.MTOMilestone](ids, err) } diff --git a/pkg/storage/mto_category.go b/pkg/storage/mto_category.go index abf06cdf73..fba3675ed5 100644 --- a/pkg/storage/mto_category.go +++ b/pkg/storage/mto_category.go @@ -12,8 +12,8 @@ import ( "github.com/cms-enterprise/mint-app/pkg/sqlutils" ) -// MTOCategoryGetByIDsLoader returns all categories by the provided -func MTOCategoryGetByIDsLoader(np sqlutils.NamedPreparer, _ *zap.Logger, ids []uuid.UUID) ([]*models.MTOCategory, error) { +// MTOCategoryGetByIDLoader returns all categories by the provided +func MTOCategoryGetByIDLoader(np sqlutils.NamedPreparer, _ *zap.Logger, ids []uuid.UUID) ([]*models.MTOCategory, error) { args := map[string]interface{}{ "ids": pq.Array(ids), diff --git a/pkg/storage/mto_milestone.go b/pkg/storage/mto_milestone.go index 1c7bb3ca0c..ecb3de7017 100644 --- a/pkg/storage/mto_milestone.go +++ b/pkg/storage/mto_milestone.go @@ -12,8 +12,8 @@ import ( "github.com/cms-enterprise/mint-app/pkg/sqlutils" ) -// MTOMilestoneGetByIDsLoader returns all milestones by the provided ids -func MTOMilestoneGetByIDsLoader(np sqlutils.NamedPreparer, _ *zap.Logger, ids []uuid.UUID) ([]*models.MTOMilestone, error) { +// MTOMilestoneGetByIDLoader returns all milestones by the provided ids +func MTOMilestoneGetByIDLoader(np sqlutils.NamedPreparer, _ *zap.Logger, ids []uuid.UUID) ([]*models.MTOMilestone, error) { args := map[string]interface{}{ "ids": pq.Array(ids), diff --git a/src/gql/generated/graphql.ts b/src/gql/generated/graphql.ts index 6542fa77a7..ac956ebb5b 100644 --- a/src/gql/generated/graphql.ts +++ b/src/gql/generated/graphql.ts @@ -900,11 +900,7 @@ export type MtoInfoTranslation = { export type MtoMilestone = { __typename: 'MTOMilestone'; addedFromMilestoneLibrary: Scalars['Boolean']['output']; - /** - * Category resolves relational category information. - * if a milestone is uncategorized, this struct will still return - * it will have a null value for both - */ + /** Category resolves relational category information. */ categories: MtoCategories; commonMilestone?: Maybe; createdBy: Scalars['UUID']['output'];