Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MINT-3235] Get milestones and solutions by relation loaders and helper methods #1563

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MINT.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -3351,7 +3351,7 @@
"body": {
"mode": "graphql",
"graphql": {
"query": "mutation NewMTOMilestone {\n createMTOMilestoneCommon(modelPlanID: \"{{modelPlanID}}\",\n commonMilestoneKey: MANAGE_CD\n) {\n id\n name\n key\n addedFromMilestoneLibrary\n facilitatedBy\n needBy\n status\n riskIndicator\n # isDraftMilestone\n mtoCategoryID\n categories {\n category{\n name\n position\n }\n subCategory{\n name\n position\n }\n } \n\n # commonMilestone\n # solutions\n }\n}",
"query": "mutation NewMTOMilestone {\n createMTOMilestoneCommon(modelPlanID: \"{{modelPlanID}}\",\n commonMilestoneKey: MANAGE_CD,\n commonSolutions: [INNOVATION, ACO_OS]\n) {\n id\n name\n key\n addedFromMilestoneLibrary\n facilitatedBy\n needBy\n status\n riskIndicator\n # isDraftMilestone\n mtoCategoryID\n categories {\n category{\n name\n position\n }\n subCategory{\n name\n position\n }\n } \n\n # commonMilestone\n # solutions\n }\n}",
"variables": ""
}
},
Expand Down Expand Up @@ -3471,7 +3471,7 @@
"body": {
"mode": "graphql",
"graphql": {
"query": "query ModelPlanMTOCategories {\nmodelPlan(id: \"{{modelPlanID}}\") {\n mtoMatrix{\n categories{\n id\n name\n isUncategorized\n subCategories {\n id\n name\n isUncategorized\n milestones {\n id\n name\n addedFromMilestoneLibrary\n key\n facilitatedBy\n needBy\n status\n riskIndicator\n # isDraftMilestone\n }\n }\n }\n }\n id\n modelName\n }\n}",
"query": "query ModelPlanMTOCategories {\nmodelPlan(id: \"{{modelPlanID}}\") {\n mtoMatrix{\n categories{\n id\n name\n isUncategorized\n subCategories {\n id\n name\n isUncategorized\n milestones {\n id\n name\n addedFromMilestoneLibrary\n key\n facilitatedBy\n needBy\n status\n riskIndicator\n solutions {\n name\n key\n type\n milestones {\n name\n type\n }\n }\n # isDraftMilestone\n }\n }\n }\n }\n id\n modelName\n }\n}",
"variables": ""
}
},
Expand Down
52 changes: 26 additions & 26 deletions pkg/graph/generated/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,14 @@ type ComplexityRoot struct {
FacilitatedBy func(childComplexity int) int
ID func(childComplexity int) int
Key func(childComplexity int) int
Milestones func(childComplexity int) int
ModifiedBy func(childComplexity int) int
ModifiedByUserAccount func(childComplexity int) int
ModifiedDts func(childComplexity int) int
Name func(childComplexity int) int
NeededBy func(childComplexity int) int
PocEmail func(childComplexity int) int
PocName func(childComplexity int) int
RelatedMilestones func(childComplexity int) int
RiskIndicator func(childComplexity int) int
Status func(childComplexity int) int
Type func(childComplexity int) int
Expand Down Expand Up @@ -2356,7 +2356,7 @@ type MTOMilestoneResolver interface {
type MTOSolutionResolver interface {
FacilitatedBy(ctx context.Context, obj *models.MTOSolution) ([]models.MTOFacilitator, error)

RelatedMilestones(ctx context.Context, obj *models.MTOSolution) ([]*models.MTOMilestone, error)
Milestones(ctx context.Context, obj *models.MTOSolution) ([]*models.MTOMilestone, error)

CommonSolution(ctx context.Context, obj *models.MTOSolution) (*models.MTOCommonSolution, error)
}
Expand Down Expand Up @@ -4403,6 +4403,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in

return e.complexity.MTOSolution.Key(childComplexity), true

case "MTOSolution.milestones":
if e.complexity.MTOSolution.Milestones == nil {
break
}

return e.complexity.MTOSolution.Milestones(childComplexity), true

case "MTOSolution.modifiedBy":
if e.complexity.MTOSolution.ModifiedBy == nil {
break
Expand Down Expand Up @@ -4452,13 +4459,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in

return e.complexity.MTOSolution.PocName(childComplexity), true

case "MTOSolution.relatedMilestones":
if e.complexity.MTOSolution.RelatedMilestones == nil {
break
}

return e.complexity.MTOSolution.RelatedMilestones(childComplexity), true

case "MTOSolution.riskIndicator":
if e.complexity.MTOSolution.RiskIndicator == nil {
break
Expand Down Expand Up @@ -17288,7 +17288,7 @@ type MTOSolution {
modifiedDts: Time

# Custom Resolvers
relatedMilestones: [MTOMilestone!]! # Can be empty, since you can have a solution with no milestones
milestones: [MTOMilestone!]! # Can be empty, since you can have a solution with no milestones
addedFromSolutionLibrary: Boolean!
commonSolution: MTOCommonSolution
}
Expand Down Expand Up @@ -34051,8 +34051,8 @@ func (ec *executionContext) fieldContext_MTOMilestone_solutions(ctx context.Cont
return ec.fieldContext_MTOSolution_modifiedByUserAccount(ctx, field)
case "modifiedDts":
return ec.fieldContext_MTOSolution_modifiedDts(ctx, field)
case "relatedMilestones":
return ec.fieldContext_MTOSolution_relatedMilestones(ctx, field)
case "milestones":
return ec.fieldContext_MTOSolution_milestones(ctx, field)
case "addedFromSolutionLibrary":
return ec.fieldContext_MTOSolution_addedFromSolutionLibrary(ctx, field)
case "commonSolution":
Expand Down Expand Up @@ -34993,8 +34993,8 @@ func (ec *executionContext) fieldContext_MTOSolution_modifiedDts(ctx context.Con
return fc, nil
}

func (ec *executionContext) _MTOSolution_relatedMilestones(ctx context.Context, field graphql.CollectedField, obj *models.MTOSolution) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_MTOSolution_relatedMilestones(ctx, field)
func (ec *executionContext) _MTOSolution_milestones(ctx context.Context, field graphql.CollectedField, obj *models.MTOSolution) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_MTOSolution_milestones(ctx, field)
if err != nil {
return graphql.Null
}
Expand All @@ -35007,7 +35007,7 @@ func (ec *executionContext) _MTOSolution_relatedMilestones(ctx context.Context,
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.MTOSolution().RelatedMilestones(rctx, obj)
return ec.resolvers.MTOSolution().Milestones(rctx, obj)
})
if err != nil {
ec.Error(ctx, err)
Expand All @@ -35024,7 +35024,7 @@ func (ec *executionContext) _MTOSolution_relatedMilestones(ctx context.Context,
return ec.marshalNMTOMilestone2ᚕᚖgithubᚗcomᚋcmsᚑenterpriseᚋmintᚑappᚋpkgᚋmodelsᚐMTOMilestoneᚄ(ctx, field.Selections, res)
}

func (ec *executionContext) fieldContext_MTOSolution_relatedMilestones(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
func (ec *executionContext) fieldContext_MTOSolution_milestones(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "MTOSolution",
Field: field,
Expand Down Expand Up @@ -39963,8 +39963,8 @@ func (ec *executionContext) fieldContext_ModelsToOperationMatrix_solutions(ctx c
return ec.fieldContext_MTOSolution_modifiedByUserAccount(ctx, field)
case "modifiedDts":
return ec.fieldContext_MTOSolution_modifiedDts(ctx, field)
case "relatedMilestones":
return ec.fieldContext_MTOSolution_relatedMilestones(ctx, field)
case "milestones":
return ec.fieldContext_MTOSolution_milestones(ctx, field)
case "addedFromSolutionLibrary":
return ec.fieldContext_MTOSolution_addedFromSolutionLibrary(ctx, field)
case "commonSolution":
Expand Down Expand Up @@ -41945,8 +41945,8 @@ func (ec *executionContext) fieldContext_Mutation_createMTOSolutionCustom(ctx co
return ec.fieldContext_MTOSolution_modifiedByUserAccount(ctx, field)
case "modifiedDts":
return ec.fieldContext_MTOSolution_modifiedDts(ctx, field)
case "relatedMilestones":
return ec.fieldContext_MTOSolution_relatedMilestones(ctx, field)
case "milestones":
return ec.fieldContext_MTOSolution_milestones(ctx, field)
case "addedFromSolutionLibrary":
return ec.fieldContext_MTOSolution_addedFromSolutionLibrary(ctx, field)
case "commonSolution":
Expand Down Expand Up @@ -42064,8 +42064,8 @@ func (ec *executionContext) fieldContext_Mutation_createMTOSolutionCommon(ctx co
return ec.fieldContext_MTOSolution_modifiedByUserAccount(ctx, field)
case "modifiedDts":
return ec.fieldContext_MTOSolution_modifiedDts(ctx, field)
case "relatedMilestones":
return ec.fieldContext_MTOSolution_relatedMilestones(ctx, field)
case "milestones":
return ec.fieldContext_MTOSolution_milestones(ctx, field)
case "addedFromSolutionLibrary":
return ec.fieldContext_MTOSolution_addedFromSolutionLibrary(ctx, field)
case "commonSolution":
Expand Down Expand Up @@ -42183,8 +42183,8 @@ func (ec *executionContext) fieldContext_Mutation_updateMTOSolution(ctx context.
return ec.fieldContext_MTOSolution_modifiedByUserAccount(ctx, field)
case "modifiedDts":
return ec.fieldContext_MTOSolution_modifiedDts(ctx, field)
case "relatedMilestones":
return ec.fieldContext_MTOSolution_relatedMilestones(ctx, field)
case "milestones":
return ec.fieldContext_MTOSolution_milestones(ctx, field)
case "addedFromSolutionLibrary":
return ec.fieldContext_MTOSolution_addedFromSolutionLibrary(ctx, field)
case "commonSolution":
Expand Down Expand Up @@ -137773,7 +137773,7 @@ func (ec *executionContext) _MTOSolution(ctx context.Context, sel ast.SelectionS
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
case "modifiedDts":
out.Values[i] = ec._MTOSolution_modifiedDts(ctx, field, obj)
case "relatedMilestones":
case "milestones":
field := field

innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {
Expand All @@ -137782,7 +137782,7 @@ func (ec *executionContext) _MTOSolution(ctx context.Context, sel ast.SelectionS
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._MTOSolution_relatedMilestones(ctx, field, obj)
res = ec._MTOSolution_milestones(ctx, field, obj)
if res == graphql.Null {
atomic.AddUint32(&fs.Invalids, 1)
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/graph/resolvers/mto_milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,10 @@ func MTOMilestoneGetByModelPlanIDAndCategoryIDLOADER(ctx context.Context, modelP
MTOCategoryID: mtoCategoryID,
})
}

func MTOMilestoneGetBySolutionIDLOADER(
ctx context.Context,
solutionID uuid.UUID,
) ([]*models.MTOMilestone, error) {
return loaders.MTOMilestone.BySolutionID.Load(ctx, solutionID)
}
3 changes: 1 addition & 2 deletions pkg/graph/resolvers/mto_milestone.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions pkg/graph/resolvers/mto_milestone_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package resolvers

import (
"github.com/google/uuid"
"github.com/samber/lo"

"github.com/cms-enterprise/mint-app/pkg/models"
"github.com/cms-enterprise/mint-app/pkg/storage"
"github.com/cms-enterprise/mint-app/pkg/storage/loaders"
)

// This test ensures that we can properly create a Custom milestone with preset category information
Expand Down Expand Up @@ -249,3 +251,83 @@ func (suite *ResolverSuite) TestCreateMilestoneSolutionLinksNoCommonSolutions()
suite.NoError(err)
suite.Len(milestoneSolutionLinks, 0)
}

func (suite *ResolverSuite) TestMTOMilestoneGetBySolutionIDLoader() {
plan1 := suite.createModelPlan("model plan 1")
commonMilestoneKey1 := models.MTOCommonMilestoneKeyAppSupportCon
milestone1 := suite.createMilestoneCommon(plan1.ID, commonMilestoneKey1, []models.MTOCommonSolutionKey{
models.MTOCSKCcw,
models.MTOCSKApps,
})

commonMilestoneKey2 := models.MTOCommonMilestoneKeyCommWPart
milestone2 := suite.createMilestoneCommon(plan1.ID, commonMilestoneKey2, []models.MTOCommonSolutionKey{
models.MTOCSKCcw,
models.MTOCSKApps,
})
commonMilestoneKey3 := models.MTOCommonMilestoneKeyAcquireALearnCont
milestone3 := suite.createMilestoneCommon(plan1.ID, commonMilestoneKey3, []models.MTOCommonSolutionKey{
models.MTOCSKBcda,
models.MTOCSKCmsBox,
models.MTOCSKCcw,
})
/***
Validate the created solutions and assign them by key
***/

solutions, err := MTOSolutionGetByModelPlanIDLOADER(suite.testConfigs.Context, plan1.ID)
suite.NoError(err)
suite.Len(solutions, 4)

solMTOCSKCcw, ok := lo.Find(solutions, func(solution *models.MTOSolution) bool {
if solution.Key != nil {
return *solution.Key == models.MTOCSKCcw
}
return false
})
suite.True(ok)
solMTOCSKApps, ok := lo.Find(solutions, func(solution *models.MTOSolution) bool {
if solution.Key != nil {
return *solution.Key == models.MTOCSKApps
}
return false
})
suite.True(ok)
solMTOCSKBcda, ok := lo.Find(solutions, func(solution *models.MTOSolution) bool {
if solution.Key != nil {
return *solution.Key == models.MTOCSKBcda
}
return false
})
suite.True(ok)
solMTOCSKCmsBox, ok := lo.Find(solutions, func(solution *models.MTOSolution) bool {
if solution.Key != nil {
return *solution.Key == models.MTOCSKCmsBox
}
return false
})
suite.True(ok)
/***
end select solutions
***/

expectedResults := []loaders.KeyAndExpected[uuid.UUID, []uuid.UUID]{
// All three milestones use this solution
{Key: solMTOCSKCcw.ID, Expected: []uuid.UUID{milestone1.ID, milestone2.ID, milestone3.ID}},
{Key: solMTOCSKApps.ID, Expected: []uuid.UUID{milestone1.ID, milestone2.ID}},
{Key: solMTOCSKBcda.ID, Expected: []uuid.UUID{milestone3.ID}},
{Key: solMTOCSKCmsBox.ID, Expected: []uuid.UUID{milestone3.ID}},
}

verifyFunc := func(data []*models.MTOMilestone, expected []uuid.UUID) bool {
// Map the IDs from the milestones, assert they match the expected returned result
dataIDs := lo.Map(data, func(item *models.MTOMilestone, _ int) uuid.UUID {
return item.ID
})
return suite.ElementsMatch(dataIDs, expected)
}
// Call the helper method to validate all results
loaders.VerifyLoaders[uuid.UUID, []*models.MTOMilestone, []uuid.UUID](suite.testConfigs.Context, &suite.Suite, loaders.MTOMilestone.BySolutionID,
expectedResults, verifyFunc)

}
7 changes: 7 additions & 0 deletions pkg/graph/resolvers/mto_solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,10 @@ func MTOSolutionGetByModelPlanIDLOADER(
// TODO look into expanding this to also take contextual model plan data to return is added etc
return loaders.MTOSolution.ByModelPlanID.Load(ctx, modelPlanID)
}

func MTOSolutionGetByMilestoneIDLOADER(
ctx context.Context,
milestoneID uuid.UUID,
) ([]*models.MTOSolution, error) {
return loaders.MTOSolution.ByMilestoneID.Load(ctx, milestoneID)
}
7 changes: 3 additions & 4 deletions pkg/graph/resolvers/mto_solution.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading