diff --git a/MINT.postman_collection.json b/MINT.postman_collection.json index 6b568b6d56..71255fab11 100644 --- a/MINT.postman_collection.json +++ b/MINT.postman_collection.json @@ -1945,7 +1945,7 @@ "body": { "mode": "graphql", "graphql": { - "query": "mutation updateExistingModelLinks{\n \n updateExistingModelLinks(modelPlanID:\"{{modelPlanID}}\", existingModelIDs:\n# null\n [100014,100015] \n currentModelPlanIDs: \n null,\n# [\"{{modelPlanID}}\" ]\n )\n {\n id\n\n currentModelPlan {\n id\n modelName\n }\n existingModel{\n id\n modelName\n }\n\n }\n \n \n}", + "query": "mutation updateExistingModelLinks {\n updateExistingModelLinks(\n modelPlanID: \"{{modelPlanID}}\"\n fieldName: \n # GEN_CHAR_PARTICIPATION_EXISTING_MODEL_WHICH\n GEN_CHAR_RESEMBLES_EXISTING_MODEL_WHICH\n existingModelIDs:\n null\n # [100014,100015]\n currentModelPlanIDs:\n # null\n [\"{{modelPlanID}}\"]\n ) {\n links {\n id\n modelPlanID\n existingModelID\n currentModelPlanID\n fieldName\n model {\n __typename\n\n ... on ExistingModel {\n modelName\n stage\n numberOfParticipants\n keywords\n }\n ... on ModelPlan {\n modelName\n abbreviation\n }\n }\n }\n }\n}\n", "variables": "" } }, @@ -1966,7 +1966,7 @@ "body": { "mode": "graphql", "graphql": { - "query": "query existingModelLink{\n \n existingModelLink(id:\"{{existingModelLinkID}}\"){\n\n currentModelPlan {\n modelName\n }\n existingModel{\n modelName\n }\n\n }\n \n \n}", + "query": "query existingModelLink {\n existingModelLink(id: \"{{existingModelLinkID}}\") {\n id\n modelPlanID\n currentModelPlanID\n existingModelID\n fieldName\n model {\n __typename\n\n ... on ExistingModel {\n modelName\n stage\n numberOfParticipants\n keywords\n }\n ... on ModelPlan {\n modelName\n abbreviation\n }\n }\n }\n}\n", "variables": "" } }, @@ -1980,14 +1980,35 @@ "response": [] }, { - "name": "ModelPlanGetExisting ModelLinks", + "name": "ModelPlanGetExisting ModelLinks (Gen Characteristics)", "request": { "method": "POST", "header": [], "body": { "mode": "graphql", "graphql": { - "query": "query ModelPlan{\n \n modelPlan(id:\"{{modelPlanID}}\"){\n id\n modelName\n nameHistory\n existingModelLinks{\n currentModelPlan {\n modelName\n }\n existingModel{\n modelName\n }\n }\n }\n \n \n}", + "query": "query ModelPlan {\n modelPlan(id: \"{{modelPlanID}}\") {\n id\n modelName\n nameHistory\n generalCharacteristics {\n resemblesExistingModelWhich {\n links {\n id\n modelPlanID\n existingModelID\n currentModelPlanID\n fieldName\n model {\n __typename\n\n ... on ExistingModel {\n modelName\n stage\n numberOfParticipants\n keywords\n }\n ... on ModelPlan {\n modelName\n abbreviation\n }\n }\n }\n }\n }\n }\n}\n", + "variables": "" + } + }, + "url": { + "raw": "{{url}}", + "host": [ + "{{url}}" + ] + } + }, + "response": [] + }, + { + "name": "ModelPlanCollection ModelLinks (Gen Characteristics)", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "graphql", + "graphql": { + "query": "query modelPlanCollection {\n modelPlanCollection(filter: INCLUDE_ALL) {\n id\n modelName\n nameHistory\n generalCharacteristics {\n resemblesExistingModelWhich {\n links {\n id\n modelPlanID\n existingModelID\n currentModelPlanID\n fieldName\n model {\n __typename\n\n ... on ExistingModel {\n modelName\n stage\n numberOfParticipants\n keywords\n }\n ... on ModelPlan {\n modelName\n abbreviation\n }\n }\n }\n }\n }\n }\n}\n", "variables": "" } }, diff --git a/cmd/dbseed/main.go b/cmd/dbseed/main.go index 681a02db72..7ab8b26ed0 100644 --- a/cmd/dbseed/main.go +++ b/cmd/dbseed/main.go @@ -127,7 +127,7 @@ func (s *Seeder) SeedData() { "highLevelNote": "Some high level note", }, ) - s.existingModelLinkCreate(planWithBasics, []int{links[3].ID, links[4].ID}, nil) + s.existingModelLinkCreate(planWithBasics, models.EMLFTGeneralCharacteristicsResemblesExistingModelWhich, []int{links[3].ID, links[4].ID}, nil) // Seed a plan with collaborators planWithCollaborators := s.createModelPlan("Plan With Collaborators", "MINT") @@ -141,7 +141,7 @@ func (s *Seeder) SeedData() { TeamRoles: []models.TeamRole{models.TeamRoleLeadership}, }) - s.existingModelLinkCreate(planWithCollaborators, []int{links[4].ID}, nil) + s.existingModelLinkCreate(planWithCollaborators, models.EMLFTGeneralCharacteristicsResemblesExistingModelWhich, []int{links[4].ID}, nil) // Seed a plan with CRs / TDLs planWithCrTDLs := s.createModelPlan("Plan With CRs and TDLs", "MINT") @@ -161,7 +161,7 @@ func (s *Seeder) SeedData() { Title: "My TDL", Note: &tdlNote, }) - s.existingModelLinkCreate(planWithCrTDLs, nil, []uuid.UUID{planWithCollaborators.ID, planWithBasics.ID}) + s.existingModelLinkCreate(planWithCrTDLs, models.EMLFTGeneralCharacteristicsResemblesExistingModelWhich, nil, []uuid.UUID{planWithCollaborators.ID, planWithBasics.ID}) // Seed a plan that is already archived archivedPlan := s.createModelPlan("Archived Plan", "MINT") diff --git a/cmd/dbseed/resolver_wrappers.go b/cmd/dbseed/resolver_wrappers.go index 789b5b7b5c..c9c652807a 100644 --- a/cmd/dbseed/resolver_wrappers.go +++ b/cmd/dbseed/resolver_wrappers.go @@ -329,9 +329,10 @@ func (s *Seeder) operationalSolutionSubtasksCreate( // It will panic if an error occurs, rather than bubbling the error up func (s *Seeder) existingModelLinkCreate( mp *models.ModelPlan, + fieldName models.ExisitingModelLinkFieldType, existingModelIDs []int, currentModelPlanIDs []uuid.UUID, -) []*models.ExistingModelLink { +) *models.ExistingModelLinks { principal := s.getTestPrincipalByUUID(mp.CreatedBy) links, err := resolvers.ExistingModelLinksUpdate( @@ -339,6 +340,7 @@ func (s *Seeder) existingModelLinkCreate( s.Config.Store, principal, mp.ID, + fieldName, existingModelIDs, currentModelPlanIDs, ) diff --git a/migrations/V143__Add_Field_Name_To_Existing_Model_Link.sql b/migrations/V143__Add_Field_Name_To_Existing_Model_Link.sql new file mode 100644 index 0000000000..23b6ffdcf0 --- /dev/null +++ b/migrations/V143__Add_Field_Name_To_Existing_Model_Link.sql @@ -0,0 +1,46 @@ +-- Create the new type +CREATE TYPE EXISITING_MODEL_LINK_FIELD_TYPE AS ENUM ( + 'GEN_CHAR_RESEMBLES_EXISTING_MODEL_WHICH', + 'GEN_CHAR_PARTICIPATION_EXISTING_MODEL_WHICH' +); + +-- add the column to the table +ALTER TABLE existing_model_link +ADD COLUMN field_name EXISITING_MODEL_LINK_FIELD_TYPE; + +-- Update existing data to point to the new column (this is the only field in use currently) +UPDATE existing_model_link +SET field_name = 'GEN_CHAR_RESEMBLES_EXISTING_MODEL_WHICH', + modified_by = '00000001-0001-0001-0001-000000000001', + modified_dts = CURRENT_TIMESTAMP; + + +ALTER TABLE existing_model_link +ALTER COLUMN field_name SET NOT NULL; + +/* Update Audit table to insert the field when link is created*/ +UPDATE audit.table_config +SET +insert_fields = '{existing_model_id,current_model_plan_id,field_name}', +modified_by = '00000001-0001-0001-0001-000000000001', --system_account +modified_dts = CURRENT_TIMESTAMP +WHERE name = 'existing_model_link'; + + + + +ALTER TABLE existing_model_link +DROP CONSTRAINT unique_existing_model_link_existing; + +/* Add constraint requiring that you can only link a model and existing model once per field*/ +ALTER TABLE existing_model_link +ADD CONSTRAINT unique_existing_model_link_existing_field_name UNIQUE (model_plan_id, existing_model_id, field_name); +COMMENT ON CONSTRAINT unique_existing_model_link_existing_field_name ON existing_model_link IS 'This constraint requires that there is not a duplicate link per model_plan, existing model, and field name'; + + +ALTER TABLE existing_model_link +DROP CONSTRAINT unique_existing_model_link_current_model; +/* Add constraint requiring that you can only link a model and current model once per field*/ +ALTER TABLE existing_model_link +ADD CONSTRAINT unique_existing_model_link_current_model_field_name UNIQUE (model_plan_id, current_model_plan_id, field_name); +COMMENT ON CONSTRAINT unique_existing_model_link_current_model_field_name ON existing_model_link IS 'This constraint requires that there is not a duplicate link per model_plan, current_model, and field name'; diff --git a/pkg/graph/generated/generated.go b/pkg/graph/generated/generated.go index c62a3637c9..6c3a032f92 100644 --- a/pkg/graph/generated/generated.go +++ b/pkg/graph/generated/generated.go @@ -44,6 +44,7 @@ type ResolverRoot interface { AuditChange() AuditChangeResolver DiscussionReply() DiscussionReplyResolver ExistingModelLink() ExistingModelLinkResolver + ExistingModelLinks() ExistingModelLinksResolver ModelPlan() ModelPlanResolver Mutation() MutationResolver OperationalNeed() OperationalNeedResolver @@ -160,17 +161,24 @@ type ComplexityRoot struct { CreatedBy func(childComplexity int) int CreatedByUserAccount func(childComplexity int) int CreatedDts func(childComplexity int) int - CurrentModelPlan func(childComplexity int) int CurrentModelPlanID func(childComplexity int) int - ExistingModel func(childComplexity int) int ExistingModelID func(childComplexity int) int + FieldName func(childComplexity int) int ID func(childComplexity int) int + Model func(childComplexity int) int ModelPlanID func(childComplexity int) int ModifiedBy func(childComplexity int) int ModifiedByUserAccount func(childComplexity int) int ModifiedDts func(childComplexity int) int } + ExistingModelLinks struct { + FieldName func(childComplexity int) int + Links func(childComplexity int) int + ModelPlanID func(childComplexity int) int + Names func(childComplexity int) int + } + Field struct { Name func(childComplexity int) int NameCamelCase func(childComplexity int) int @@ -199,7 +207,6 @@ type ComplexityRoot struct { Crs func(childComplexity int) int Discussions func(childComplexity int) int Documents func(childComplexity int) int - ExistingModelLinks func(childComplexity int) int GeneralCharacteristics func(childComplexity int) int ID func(childComplexity int) int IsCollaborator func(childComplexity int) int @@ -246,7 +253,7 @@ type ComplexityRoot struct { UnlockAllTaskListSections func(childComplexity int, modelPlanID uuid.UUID) int UnlockTaskListSection func(childComplexity int, modelPlanID uuid.UUID, section models.TaskListSection) int UpdateCustomOperationalNeedByID func(childComplexity int, id uuid.UUID, customNeedType *string, needed bool) int - UpdateExistingModelLinks func(childComplexity int, modelPlanID uuid.UUID, existingModelIDs []int, currentModelPlanIDs []uuid.UUID) int + UpdateExistingModelLinks func(childComplexity int, modelPlanID uuid.UUID, fieldName models.ExisitingModelLinkFieldType, existingModelIDs []int, currentModelPlanIDs []uuid.UUID) int UpdateModelPlan func(childComplexity int, id uuid.UUID, changes map[string]interface{}) int UpdateOperationalSolution func(childComplexity int, id uuid.UUID, changes map[string]interface{}) int UpdateOperationalSolutionSubtasks func(childComplexity int, inputs []*model.UpdateOperationalSolutionSubtaskInput) int @@ -575,6 +582,7 @@ type ComplexityRoot struct { ResemblesExistingModel func(childComplexity int) int ResemblesExistingModelHow func(childComplexity int) int ResemblesExistingModelNote func(childComplexity int) int + ResemblesExistingModelWhich func(childComplexity int) int RulemakingRequired func(childComplexity int) int RulemakingRequiredDescription func(childComplexity int) int RulemakingRequiredNote func(childComplexity int) int @@ -1025,9 +1033,10 @@ type DiscussionReplyResolver interface { Content(ctx context.Context, obj *models.DiscussionReply) (*models.TaggedContent, error) } type ExistingModelLinkResolver interface { - ExistingModel(ctx context.Context, obj *models.ExistingModelLink) (*models.ExistingModel, error) - - CurrentModelPlan(ctx context.Context, obj *models.ExistingModelLink) (*models.ModelPlan, error) + Model(ctx context.Context, obj *models.ExistingModelLink) (models.LinkedExistingModel, error) +} +type ExistingModelLinksResolver interface { + Names(ctx context.Context, obj *models.ExistingModelLinks) ([]string, error) } type ModelPlanResolver interface { Basics(ctx context.Context, obj *models.ModelPlan) (*models.PlanBasics, error) @@ -1047,7 +1056,6 @@ type ModelPlanResolver interface { PrepareForClearance(ctx context.Context, obj *models.ModelPlan) (*model.PrepareForClearance, error) NameHistory(ctx context.Context, obj *models.ModelPlan, sort models.SortDirection) ([]string, error) OperationalNeeds(ctx context.Context, obj *models.ModelPlan) ([]*models.OperationalNeed, error) - ExistingModelLinks(ctx context.Context, obj *models.ModelPlan) ([]*models.ExistingModelLink, error) } type MutationResolver interface { CreateModelPlan(ctx context.Context, modelName string) (*models.ModelPlan, error) @@ -1087,7 +1095,7 @@ type MutationResolver interface { CreateOperationalSolutionSubtasks(ctx context.Context, solutionID uuid.UUID, inputs []*model.CreateOperationalSolutionSubtaskInput) ([]*models.OperationalSolutionSubtask, error) UpdateOperationalSolutionSubtasks(ctx context.Context, inputs []*model.UpdateOperationalSolutionSubtaskInput) ([]*models.OperationalSolutionSubtask, error) DeleteOperationalSolutionSubtask(ctx context.Context, id uuid.UUID) (int, error) - UpdateExistingModelLinks(ctx context.Context, modelPlanID uuid.UUID, existingModelIDs []int, currentModelPlanIDs []uuid.UUID) ([]*models.ExistingModelLink, error) + UpdateExistingModelLinks(ctx context.Context, modelPlanID uuid.UUID, fieldName models.ExisitingModelLinkFieldType, existingModelIDs []int, currentModelPlanIDs []uuid.UUID) (*models.ExistingModelLinks, error) ShareModelPlan(ctx context.Context, modelPlanID uuid.UUID, viewFilter *models.ModelViewFilter, usernames []string, optionalMessage *string) (bool, error) ReportAProblem(ctx context.Context, input model.ReportAProblemInput) (bool, error) SendFeedbackEmail(ctx context.Context, input model.SendFeedbackEmailInput) (bool, error) @@ -1140,6 +1148,8 @@ type PlanGeneralCharacteristicsResolver interface { ExistingModelPlan(ctx context.Context, obj *models.PlanGeneralCharacteristics) (*models.ExistingModel, error) + ResemblesExistingModelWhich(ctx context.Context, obj *models.PlanGeneralCharacteristics) (*models.ExistingModelLinks, error) + AlternativePaymentModelTypes(ctx context.Context, obj *models.PlanGeneralCharacteristics) ([]model.AlternativePaymentModelType, error) KeyCharacteristics(ctx context.Context, obj *models.PlanGeneralCharacteristics) ([]model.KeyCharacteristic, error) @@ -1729,13 +1739,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.ExistingModelLink.CreatedDts(childComplexity), true - case "ExistingModelLink.currentModelPlan": - if e.complexity.ExistingModelLink.CurrentModelPlan == nil { - break - } - - return e.complexity.ExistingModelLink.CurrentModelPlan(childComplexity), true - case "ExistingModelLink.currentModelPlanID": if e.complexity.ExistingModelLink.CurrentModelPlanID == nil { break @@ -1743,19 +1746,19 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.ExistingModelLink.CurrentModelPlanID(childComplexity), true - case "ExistingModelLink.existingModel": - if e.complexity.ExistingModelLink.ExistingModel == nil { + case "ExistingModelLink.existingModelID": + if e.complexity.ExistingModelLink.ExistingModelID == nil { break } - return e.complexity.ExistingModelLink.ExistingModel(childComplexity), true + return e.complexity.ExistingModelLink.ExistingModelID(childComplexity), true - case "ExistingModelLink.existingModelID": - if e.complexity.ExistingModelLink.ExistingModelID == nil { + case "ExistingModelLink.fieldName": + if e.complexity.ExistingModelLink.FieldName == nil { break } - return e.complexity.ExistingModelLink.ExistingModelID(childComplexity), true + return e.complexity.ExistingModelLink.FieldName(childComplexity), true case "ExistingModelLink.id": if e.complexity.ExistingModelLink.ID == nil { @@ -1764,6 +1767,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.ExistingModelLink.ID(childComplexity), true + case "ExistingModelLink.model": + if e.complexity.ExistingModelLink.Model == nil { + break + } + + return e.complexity.ExistingModelLink.Model(childComplexity), true + case "ExistingModelLink.modelPlanID": if e.complexity.ExistingModelLink.ModelPlanID == nil { break @@ -1792,6 +1802,34 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.ExistingModelLink.ModifiedDts(childComplexity), true + case "ExistingModelLinks.fieldName": + if e.complexity.ExistingModelLinks.FieldName == nil { + break + } + + return e.complexity.ExistingModelLinks.FieldName(childComplexity), true + + case "ExistingModelLinks.links": + if e.complexity.ExistingModelLinks.Links == nil { + break + } + + return e.complexity.ExistingModelLinks.Links(childComplexity), true + + case "ExistingModelLinks.modelPlanID": + if e.complexity.ExistingModelLinks.ModelPlanID == nil { + break + } + + return e.complexity.ExistingModelLinks.ModelPlanID(childComplexity), true + + case "ExistingModelLinks.names": + if e.complexity.ExistingModelLinks.Names == nil { + break + } + + return e.complexity.ExistingModelLinks.Names(childComplexity), true + case "Field.name": if e.complexity.Field.Name == nil { break @@ -1918,13 +1956,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.ModelPlan.Documents(childComplexity), true - case "ModelPlan.existingModelLinks": - if e.complexity.ModelPlan.ExistingModelLinks == nil { - break - } - - return e.complexity.ModelPlan.ExistingModelLinks(childComplexity), true - case "ModelPlan.generalCharacteristics": if e.complexity.ModelPlan.GeneralCharacteristics == nil { break @@ -2376,7 +2407,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Mutation.UpdateExistingModelLinks(childComplexity, args["modelPlanID"].(uuid.UUID), args["existingModelIDs"].([]int), args["currentModelPlanIDs"].([]uuid.UUID)), true + return e.complexity.Mutation.UpdateExistingModelLinks(childComplexity, args["modelPlanID"].(uuid.UUID), args["fieldName"].(models.ExisitingModelLinkFieldType), args["existingModelIDs"].([]int), args["currentModelPlanIDs"].([]uuid.UUID)), true case "Mutation.updateModelPlan": if e.complexity.Mutation.UpdateModelPlan == nil { @@ -4471,6 +4502,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.PlanGeneralCharacteristics.ResemblesExistingModelNote(childComplexity), true + case "PlanGeneralCharacteristics.resemblesExistingModelWhich": + if e.complexity.PlanGeneralCharacteristics.ResemblesExistingModelWhich == nil { + break + } + + return e.complexity.PlanGeneralCharacteristics.ResemblesExistingModelWhich(childComplexity), true + case "PlanGeneralCharacteristics.rulemakingRequired": if e.complexity.PlanGeneralCharacteristics.RulemakingRequired == nil { break @@ -7526,7 +7564,6 @@ type ModelPlan { prepareForClearance: PrepareForClearance! nameHistory(sort: SortDirection! = DESC): [String!]! operationalNeeds: [OperationalNeed!]! - existingModelLinks: [ExistingModelLink!]! } type OperationalNeed { @@ -7634,7 +7671,7 @@ ExistingModel represents a model that already exists outside of the scope of MIN """ type ExistingModel { id: Int - modelName: String + modelName: String! stage: String! numberOfParticipants: String category: String @@ -7656,14 +7693,26 @@ type ExistingModel { modifiedByUserAccount: UserAccount modifiedDts: Time } +""" +LinkedExistingModel is a union type that returns either an Existing Model, or a Model plan from the database +""" +union LinkedExistingModel = ExistingModel | ModelPlan + + +type ExistingModelLinks { + links: [ExistingModelLink!]! + fieldName: ExisitingModelLinkFieldType! + modelPlanID: UUID! + names: [String!]! +} type ExistingModelLink { id: UUID modelPlanID: UUID! existingModelID: Int - existingModel: ExistingModel currentModelPlanID: UUID - currentModelPlan: ModelPlan + fieldName: ExisitingModelLinkFieldType! + model: LinkedExistingModel! createdBy: UUID! createdByUserAccount: UserAccount! @@ -7983,6 +8032,7 @@ type PlanGeneralCharacteristics { resemblesExistingModel: Boolean resemblesExistingModelHow: String resemblesExistingModelNote: String + resemblesExistingModelWhich: ExistingModelLinks hasComponentsOrTracks: Boolean hasComponentsOrTracksDiffer: String hasComponentsOrTracksNote: String @@ -8868,6 +8918,11 @@ input ReportAProblemInput { severityOther: String } +enum ExisitingModelLinkFieldType { + GEN_CHAR_RESEMBLES_EXISTING_MODEL_WHICH + GEN_CHAR_PARTICIPATION_EXISTING_MODEL_WHICH +} + enum ReportAProblemSection { READ_VIEW TASK_LIST @@ -9368,7 +9423,11 @@ updateOperationalSolutionSubtasks(inputs: [UpdateOperationalSolutionSubtaskInput deleteOperationalSolutionSubtask(id: UUID!): Int! @hasRole(role: MINT_USER) -updateExistingModelLinks(modelPlanID: UUID!, existingModelIDs: [Int!],currentModelPlanIDs: [UUID!]): [ExistingModelLink!]! +""" +This will update linked existing models, and relatede model plans for given model plan and fieldName. +The fieldName allows it so you can create links for multiple sections of the model plan +""" +updateExistingModelLinks(modelPlanID: UUID!,fieldName: ExisitingModelLinkFieldType!, existingModelIDs: [Int!],currentModelPlanIDs: [UUID!]): ExistingModelLinks! @hasRole(role: MINT_USER) shareModelPlan(modelPlanID: UUID!, viewFilter: ModelViewFilter, usernames: [String!]!, optionalMessage: String): Boolean! @@ -10791,24 +10850,33 @@ func (ec *executionContext) field_Mutation_updateExistingModelLinks_args(ctx con } } args["modelPlanID"] = arg0 - var arg1 []int + var arg1 models.ExisitingModelLinkFieldType + if tmp, ok := rawArgs["fieldName"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("fieldName")) + arg1, err = ec.unmarshalNExisitingModelLinkFieldType2githubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExisitingModelLinkFieldType(ctx, tmp) + if err != nil { + return nil, err + } + } + args["fieldName"] = arg1 + var arg2 []int if tmp, ok := rawArgs["existingModelIDs"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("existingModelIDs")) - arg1, err = ec.unmarshalOInt2ᚕintᚄ(ctx, tmp) + arg2, err = ec.unmarshalOInt2ᚕintᚄ(ctx, tmp) if err != nil { return nil, err } } - args["existingModelIDs"] = arg1 - var arg2 []uuid.UUID + args["existingModelIDs"] = arg2 + var arg3 []uuid.UUID if tmp, ok := rawArgs["currentModelPlanIDs"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("currentModelPlanIDs")) - arg2, err = ec.unmarshalOUUID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, tmp) + arg3, err = ec.unmarshalOUUID2ᚕgithubᚗcomᚋgoogleᚋuuidᚐUUIDᚄ(ctx, tmp) if err != nil { return nil, err } } - args["currentModelPlanIDs"] = arg2 + args["currentModelPlanIDs"] = arg3 return args, nil } @@ -13405,11 +13473,14 @@ func (ec *executionContext) _ExistingModel_modelName(ctx context.Context, field return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) fc.Result = res - return ec.marshalOString2string(ctx, field.Selections, res) + return ec.marshalNString2string(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_ExistingModel_modelName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -14386,8 +14457,8 @@ func (ec *executionContext) fieldContext_ExistingModelLink_existingModelID(ctx c return fc, nil } -func (ec *executionContext) _ExistingModelLink_existingModel(ctx context.Context, field graphql.CollectedField, obj *models.ExistingModelLink) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_ExistingModelLink_existingModel(ctx, field) +func (ec *executionContext) _ExistingModelLink_currentModelPlanID(ctx context.Context, field graphql.CollectedField, obj *models.ExistingModelLink) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ExistingModelLink_currentModelPlanID(ctx, field) if err != nil { return graphql.Null } @@ -14400,7 +14471,7 @@ func (ec *executionContext) _ExistingModelLink_existingModel(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.ExistingModelLink().ExistingModel(rctx, obj) + return obj.CurrentModelPlanID, nil }) if err != nil { ec.Error(ctx, err) @@ -14409,70 +14480,26 @@ func (ec *executionContext) _ExistingModelLink_existingModel(ctx context.Context if resTmp == nil { return graphql.Null } - res := resTmp.(*models.ExistingModel) + res := resTmp.(*uuid.UUID) fc.Result = res - return ec.marshalOExistingModel2ᚖgithubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExistingModel(ctx, field.Selections, res) + return ec.marshalOUUID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_ExistingModelLink_existingModel(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ExistingModelLink_currentModelPlanID(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "ExistingModelLink", Field: field, - IsMethod: true, - IsResolver: true, + IsMethod: false, + IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - switch field.Name { - case "id": - return ec.fieldContext_ExistingModel_id(ctx, field) - case "modelName": - return ec.fieldContext_ExistingModel_modelName(ctx, field) - case "stage": - return ec.fieldContext_ExistingModel_stage(ctx, field) - case "numberOfParticipants": - return ec.fieldContext_ExistingModel_numberOfParticipants(ctx, field) - case "category": - return ec.fieldContext_ExistingModel_category(ctx, field) - case "authority": - return ec.fieldContext_ExistingModel_authority(ctx, field) - case "description": - return ec.fieldContext_ExistingModel_description(ctx, field) - case "numberOfBeneficiariesImpacted": - return ec.fieldContext_ExistingModel_numberOfBeneficiariesImpacted(ctx, field) - case "numberOfPhysiciansImpacted": - return ec.fieldContext_ExistingModel_numberOfPhysiciansImpacted(ctx, field) - case "dateBegan": - return ec.fieldContext_ExistingModel_dateBegan(ctx, field) - case "dateEnded": - return ec.fieldContext_ExistingModel_dateEnded(ctx, field) - case "states": - return ec.fieldContext_ExistingModel_states(ctx, field) - case "keywords": - return ec.fieldContext_ExistingModel_keywords(ctx, field) - case "url": - return ec.fieldContext_ExistingModel_url(ctx, field) - case "displayModelSummary": - return ec.fieldContext_ExistingModel_displayModelSummary(ctx, field) - case "createdBy": - return ec.fieldContext_ExistingModel_createdBy(ctx, field) - case "createdByUserAccount": - return ec.fieldContext_ExistingModel_createdByUserAccount(ctx, field) - case "createdDts": - return ec.fieldContext_ExistingModel_createdDts(ctx, field) - case "modifiedBy": - return ec.fieldContext_ExistingModel_modifiedBy(ctx, field) - case "modifiedByUserAccount": - return ec.fieldContext_ExistingModel_modifiedByUserAccount(ctx, field) - case "modifiedDts": - return ec.fieldContext_ExistingModel_modifiedDts(ctx, field) - } - return nil, fmt.Errorf("no field named %q was found under type ExistingModel", field.Name) + return nil, errors.New("field of type UUID does not have child fields") }, } return fc, nil } -func (ec *executionContext) _ExistingModelLink_currentModelPlanID(ctx context.Context, field graphql.CollectedField, obj *models.ExistingModelLink) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_ExistingModelLink_currentModelPlanID(ctx, field) +func (ec *executionContext) _ExistingModelLink_fieldName(ctx context.Context, field graphql.CollectedField, obj *models.ExistingModelLink) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ExistingModelLink_fieldName(ctx, field) if err != nil { return graphql.Null } @@ -14485,35 +14512,38 @@ func (ec *executionContext) _ExistingModelLink_currentModelPlanID(ctx context.Co }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.CurrentModelPlanID, nil + return obj.FieldName, nil }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*uuid.UUID) + res := resTmp.(models.ExisitingModelLinkFieldType) fc.Result = res - return ec.marshalOUUID2ᚖgithubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, field.Selections, res) + return ec.marshalNExisitingModelLinkFieldType2githubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExisitingModelLinkFieldType(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_ExistingModelLink_currentModelPlanID(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ExistingModelLink_fieldName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "ExistingModelLink", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type UUID does not have child fields") + return nil, errors.New("field of type ExisitingModelLinkFieldType does not have child fields") }, } return fc, nil } -func (ec *executionContext) _ExistingModelLink_currentModelPlan(ctx context.Context, field graphql.CollectedField, obj *models.ExistingModelLink) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_ExistingModelLink_currentModelPlan(ctx, field) +func (ec *executionContext) _ExistingModelLink_model(ctx context.Context, field graphql.CollectedField, obj *models.ExistingModelLink) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ExistingModelLink_model(ctx, field) if err != nil { return graphql.Null } @@ -14526,86 +14556,31 @@ func (ec *executionContext) _ExistingModelLink_currentModelPlan(ctx context.Cont }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.ExistingModelLink().CurrentModelPlan(rctx, obj) + return ec.resolvers.ExistingModelLink().Model(rctx, obj) }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*models.ModelPlan) + res := resTmp.(models.LinkedExistingModel) fc.Result = res - return ec.marshalOModelPlan2ᚖgithubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐModelPlan(ctx, field.Selections, res) + return ec.marshalNLinkedExistingModel2githubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐLinkedExistingModel(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_ExistingModelLink_currentModelPlan(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ExistingModelLink_model(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "ExistingModelLink", Field: field, IsMethod: true, IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - switch field.Name { - case "id": - return ec.fieldContext_ModelPlan_id(ctx, field) - case "modelName": - return ec.fieldContext_ModelPlan_modelName(ctx, field) - case "abbreviation": - return ec.fieldContext_ModelPlan_abbreviation(ctx, field) - case "archived": - return ec.fieldContext_ModelPlan_archived(ctx, field) - case "createdBy": - return ec.fieldContext_ModelPlan_createdBy(ctx, field) - case "createdByUserAccount": - return ec.fieldContext_ModelPlan_createdByUserAccount(ctx, field) - case "createdDts": - return ec.fieldContext_ModelPlan_createdDts(ctx, field) - case "modifiedBy": - return ec.fieldContext_ModelPlan_modifiedBy(ctx, field) - case "modifiedByUserAccount": - return ec.fieldContext_ModelPlan_modifiedByUserAccount(ctx, field) - case "modifiedDts": - return ec.fieldContext_ModelPlan_modifiedDts(ctx, field) - case "basics": - return ec.fieldContext_ModelPlan_basics(ctx, field) - case "generalCharacteristics": - return ec.fieldContext_ModelPlan_generalCharacteristics(ctx, field) - case "participantsAndProviders": - return ec.fieldContext_ModelPlan_participantsAndProviders(ctx, field) - case "beneficiaries": - return ec.fieldContext_ModelPlan_beneficiaries(ctx, field) - case "opsEvalAndLearning": - return ec.fieldContext_ModelPlan_opsEvalAndLearning(ctx, field) - case "collaborators": - return ec.fieldContext_ModelPlan_collaborators(ctx, field) - case "documents": - return ec.fieldContext_ModelPlan_documents(ctx, field) - case "discussions": - return ec.fieldContext_ModelPlan_discussions(ctx, field) - case "payments": - return ec.fieldContext_ModelPlan_payments(ctx, field) - case "status": - return ec.fieldContext_ModelPlan_status(ctx, field) - case "isFavorite": - return ec.fieldContext_ModelPlan_isFavorite(ctx, field) - case "isCollaborator": - return ec.fieldContext_ModelPlan_isCollaborator(ctx, field) - case "crs": - return ec.fieldContext_ModelPlan_crs(ctx, field) - case "tdls": - return ec.fieldContext_ModelPlan_tdls(ctx, field) - case "prepareForClearance": - return ec.fieldContext_ModelPlan_prepareForClearance(ctx, field) - case "nameHistory": - return ec.fieldContext_ModelPlan_nameHistory(ctx, field) - case "operationalNeeds": - return ec.fieldContext_ModelPlan_operationalNeeds(ctx, field) - case "existingModelLinks": - return ec.fieldContext_ModelPlan_existingModelLinks(ctx, field) - } - return nil, fmt.Errorf("no field named %q was found under type ModelPlan", field.Name) + return nil, errors.New("field of type LinkedExistingModel does not have child fields") }, } return fc, nil @@ -14910,6 +14885,208 @@ func (ec *executionContext) fieldContext_ExistingModelLink_modifiedDts(ctx conte return fc, nil } +func (ec *executionContext) _ExistingModelLinks_links(ctx context.Context, field graphql.CollectedField, obj *models.ExistingModelLinks) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ExistingModelLinks_links(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Links, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*models.ExistingModelLink) + fc.Result = res + return ec.marshalNExistingModelLink2ᚕᚖgithubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExistingModelLinkᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_ExistingModelLinks_links(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "ExistingModelLinks", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_ExistingModelLink_id(ctx, field) + case "modelPlanID": + return ec.fieldContext_ExistingModelLink_modelPlanID(ctx, field) + case "existingModelID": + return ec.fieldContext_ExistingModelLink_existingModelID(ctx, field) + case "currentModelPlanID": + return ec.fieldContext_ExistingModelLink_currentModelPlanID(ctx, field) + case "fieldName": + return ec.fieldContext_ExistingModelLink_fieldName(ctx, field) + case "model": + return ec.fieldContext_ExistingModelLink_model(ctx, field) + case "createdBy": + return ec.fieldContext_ExistingModelLink_createdBy(ctx, field) + case "createdByUserAccount": + return ec.fieldContext_ExistingModelLink_createdByUserAccount(ctx, field) + case "createdDts": + return ec.fieldContext_ExistingModelLink_createdDts(ctx, field) + case "modifiedBy": + return ec.fieldContext_ExistingModelLink_modifiedBy(ctx, field) + case "modifiedByUserAccount": + return ec.fieldContext_ExistingModelLink_modifiedByUserAccount(ctx, field) + case "modifiedDts": + return ec.fieldContext_ExistingModelLink_modifiedDts(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type ExistingModelLink", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _ExistingModelLinks_fieldName(ctx context.Context, field graphql.CollectedField, obj *models.ExistingModelLinks) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ExistingModelLinks_fieldName(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.FieldName, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(models.ExisitingModelLinkFieldType) + fc.Result = res + return ec.marshalNExisitingModelLinkFieldType2githubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExisitingModelLinkFieldType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_ExistingModelLinks_fieldName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "ExistingModelLinks", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ExisitingModelLinkFieldType does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _ExistingModelLinks_modelPlanID(ctx context.Context, field graphql.CollectedField, obj *models.ExistingModelLinks) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ExistingModelLinks_modelPlanID(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ModelPlanID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(uuid.UUID) + fc.Result = res + return ec.marshalNUUID2githubᚗcomᚋgoogleᚋuuidᚐUUID(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_ExistingModelLinks_modelPlanID(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "ExistingModelLinks", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type UUID does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _ExistingModelLinks_names(ctx context.Context, field graphql.CollectedField, obj *models.ExistingModelLinks) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ExistingModelLinks_names(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.ExistingModelLinks().Names(rctx, obj) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]string) + fc.Result = res + return ec.marshalNString2ᚕstringᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_ExistingModelLinks_names(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "ExistingModelLinks", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Field_name(ctx context.Context, field graphql.CollectedField, obj *models.Field) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Field_name(ctx, field) if err != nil { @@ -15875,6 +16052,8 @@ func (ec *executionContext) fieldContext_ModelPlan_generalCharacteristics(ctx co return ec.fieldContext_PlanGeneralCharacteristics_resemblesExistingModelHow(ctx, field) case "resemblesExistingModelNote": return ec.fieldContext_PlanGeneralCharacteristics_resemblesExistingModelNote(ctx, field) + case "resemblesExistingModelWhich": + return ec.fieldContext_PlanGeneralCharacteristics_resemblesExistingModelWhich(ctx, field) case "hasComponentsOrTracks": return ec.fieldContext_PlanGeneralCharacteristics_hasComponentsOrTracks(ctx, field) case "hasComponentsOrTracksDiffer": @@ -17507,76 +17686,6 @@ func (ec *executionContext) fieldContext_ModelPlan_operationalNeeds(ctx context. return fc, nil } -func (ec *executionContext) _ModelPlan_existingModelLinks(ctx context.Context, field graphql.CollectedField, obj *models.ModelPlan) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_ModelPlan_existingModelLinks(ctx, field) - if err != nil { - return graphql.Null - } - ctx = graphql.WithFieldContext(ctx, fc) - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = graphql.Null - } - }() - resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.ModelPlan().ExistingModelLinks(rctx, obj) - }) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - if resTmp == nil { - if !graphql.HasFieldError(ctx, fc) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.([]*models.ExistingModelLink) - fc.Result = res - return ec.marshalNExistingModelLink2ᚕᚖgithubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExistingModelLinkᚄ(ctx, field.Selections, res) -} - -func (ec *executionContext) fieldContext_ModelPlan_existingModelLinks(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { - fc = &graphql.FieldContext{ - Object: "ModelPlan", - Field: field, - IsMethod: true, - IsResolver: true, - Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - switch field.Name { - case "id": - return ec.fieldContext_ExistingModelLink_id(ctx, field) - case "modelPlanID": - return ec.fieldContext_ExistingModelLink_modelPlanID(ctx, field) - case "existingModelID": - return ec.fieldContext_ExistingModelLink_existingModelID(ctx, field) - case "existingModel": - return ec.fieldContext_ExistingModelLink_existingModel(ctx, field) - case "currentModelPlanID": - return ec.fieldContext_ExistingModelLink_currentModelPlanID(ctx, field) - case "currentModelPlan": - return ec.fieldContext_ExistingModelLink_currentModelPlan(ctx, field) - case "createdBy": - return ec.fieldContext_ExistingModelLink_createdBy(ctx, field) - case "createdByUserAccount": - return ec.fieldContext_ExistingModelLink_createdByUserAccount(ctx, field) - case "createdDts": - return ec.fieldContext_ExistingModelLink_createdDts(ctx, field) - case "modifiedBy": - return ec.fieldContext_ExistingModelLink_modifiedBy(ctx, field) - case "modifiedByUserAccount": - return ec.fieldContext_ExistingModelLink_modifiedByUserAccount(ctx, field) - case "modifiedDts": - return ec.fieldContext_ExistingModelLink_modifiedDts(ctx, field) - } - return nil, fmt.Errorf("no field named %q was found under type ExistingModelLink", field.Name) - }, - } - return fc, nil -} - func (ec *executionContext) _Mutation_createModelPlan(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Mutation_createModelPlan(ctx, field) if err != nil { @@ -17694,8 +17803,6 @@ func (ec *executionContext) fieldContext_Mutation_createModelPlan(ctx context.Co return ec.fieldContext_ModelPlan_nameHistory(ctx, field) case "operationalNeeds": return ec.fieldContext_ModelPlan_operationalNeeds(ctx, field) - case "existingModelLinks": - return ec.fieldContext_ModelPlan_existingModelLinks(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type ModelPlan", field.Name) }, @@ -17831,8 +17938,6 @@ func (ec *executionContext) fieldContext_Mutation_updateModelPlan(ctx context.Co return ec.fieldContext_ModelPlan_nameHistory(ctx, field) case "operationalNeeds": return ec.fieldContext_ModelPlan_operationalNeeds(ctx, field) - case "existingModelLinks": - return ec.fieldContext_ModelPlan_existingModelLinks(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type ModelPlan", field.Name) }, @@ -18404,6 +18509,8 @@ func (ec *executionContext) fieldContext_Mutation_updatePlanGeneralCharacteristi return ec.fieldContext_PlanGeneralCharacteristics_resemblesExistingModelHow(ctx, field) case "resemblesExistingModelNote": return ec.fieldContext_PlanGeneralCharacteristics_resemblesExistingModelNote(ctx, field) + case "resemblesExistingModelWhich": + return ec.fieldContext_PlanGeneralCharacteristics_resemblesExistingModelWhich(ctx, field) case "hasComponentsOrTracks": return ec.fieldContext_PlanGeneralCharacteristics_hasComponentsOrTracks(ctx, field) case "hasComponentsOrTracksDiffer": @@ -22156,7 +22263,7 @@ func (ec *executionContext) _Mutation_updateExistingModelLinks(ctx context.Conte resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { directive0 := func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Mutation().UpdateExistingModelLinks(rctx, fc.Args["modelPlanID"].(uuid.UUID), fc.Args["existingModelIDs"].([]int), fc.Args["currentModelPlanIDs"].([]uuid.UUID)) + return ec.resolvers.Mutation().UpdateExistingModelLinks(rctx, fc.Args["modelPlanID"].(uuid.UUID), fc.Args["fieldName"].(models.ExisitingModelLinkFieldType), fc.Args["existingModelIDs"].([]int), fc.Args["currentModelPlanIDs"].([]uuid.UUID)) } directive1 := func(ctx context.Context) (interface{}, error) { role, err := ec.unmarshalNRole2githubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋgraphᚋmodelᚐRole(ctx, "MINT_USER") @@ -22176,10 +22283,10 @@ func (ec *executionContext) _Mutation_updateExistingModelLinks(ctx context.Conte if tmp == nil { return nil, nil } - if data, ok := tmp.([]*models.ExistingModelLink); ok { + if data, ok := tmp.(*models.ExistingModelLinks); ok { return data, nil } - return nil, fmt.Errorf(`unexpected type %T from directive, should be []*github.com/cmsgov/mint-app/pkg/models.ExistingModelLink`, tmp) + return nil, fmt.Errorf(`unexpected type %T from directive, should be *github.com/cmsgov/mint-app/pkg/models.ExistingModelLinks`, tmp) }) if err != nil { ec.Error(ctx, err) @@ -22191,9 +22298,9 @@ func (ec *executionContext) _Mutation_updateExistingModelLinks(ctx context.Conte } return graphql.Null } - res := resTmp.([]*models.ExistingModelLink) + res := resTmp.(*models.ExistingModelLinks) fc.Result = res - return ec.marshalNExistingModelLink2ᚕᚖgithubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExistingModelLinkᚄ(ctx, field.Selections, res) + return ec.marshalNExistingModelLinks2ᚖgithubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExistingModelLinks(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_Mutation_updateExistingModelLinks(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -22204,32 +22311,16 @@ func (ec *executionContext) fieldContext_Mutation_updateExistingModelLinks(ctx c IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { - case "id": - return ec.fieldContext_ExistingModelLink_id(ctx, field) + case "links": + return ec.fieldContext_ExistingModelLinks_links(ctx, field) + case "fieldName": + return ec.fieldContext_ExistingModelLinks_fieldName(ctx, field) case "modelPlanID": - return ec.fieldContext_ExistingModelLink_modelPlanID(ctx, field) - case "existingModelID": - return ec.fieldContext_ExistingModelLink_existingModelID(ctx, field) - case "existingModel": - return ec.fieldContext_ExistingModelLink_existingModel(ctx, field) - case "currentModelPlanID": - return ec.fieldContext_ExistingModelLink_currentModelPlanID(ctx, field) - case "currentModelPlan": - return ec.fieldContext_ExistingModelLink_currentModelPlan(ctx, field) - case "createdBy": - return ec.fieldContext_ExistingModelLink_createdBy(ctx, field) - case "createdByUserAccount": - return ec.fieldContext_ExistingModelLink_createdByUserAccount(ctx, field) - case "createdDts": - return ec.fieldContext_ExistingModelLink_createdDts(ctx, field) - case "modifiedBy": - return ec.fieldContext_ExistingModelLink_modifiedBy(ctx, field) - case "modifiedByUserAccount": - return ec.fieldContext_ExistingModelLink_modifiedByUserAccount(ctx, field) - case "modifiedDts": - return ec.fieldContext_ExistingModelLink_modifiedDts(ctx, field) + return ec.fieldContext_ExistingModelLinks_modelPlanID(ctx, field) + case "names": + return ec.fieldContext_ExistingModelLinks_names(ctx, field) } - return nil, fmt.Errorf("no field named %q was found under type ExistingModelLink", field.Name) + return nil, fmt.Errorf("no field named %q was found under type ExistingModelLinks", field.Name) }, } defer func() { @@ -32563,8 +32654,6 @@ func (ec *executionContext) fieldContext_PlanGeneralCharacteristics_currentModel return ec.fieldContext_ModelPlan_nameHistory(ctx, field) case "operationalNeeds": return ec.fieldContext_ModelPlan_operationalNeeds(ctx, field) - case "existingModelLinks": - return ec.fieldContext_ModelPlan_existingModelLinks(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type ModelPlan", field.Name) }, @@ -32821,6 +32910,57 @@ func (ec *executionContext) fieldContext_PlanGeneralCharacteristics_resemblesExi return fc, nil } +func (ec *executionContext) _PlanGeneralCharacteristics_resemblesExistingModelWhich(ctx context.Context, field graphql.CollectedField, obj *models.PlanGeneralCharacteristics) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PlanGeneralCharacteristics_resemblesExistingModelWhich(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.PlanGeneralCharacteristics().ResemblesExistingModelWhich(rctx, obj) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*models.ExistingModelLinks) + fc.Result = res + return ec.marshalOExistingModelLinks2ᚖgithubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExistingModelLinks(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PlanGeneralCharacteristics_resemblesExistingModelWhich(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PlanGeneralCharacteristics", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "links": + return ec.fieldContext_ExistingModelLinks_links(ctx, field) + case "fieldName": + return ec.fieldContext_ExistingModelLinks_fieldName(ctx, field) + case "modelPlanID": + return ec.fieldContext_ExistingModelLinks_modelPlanID(ctx, field) + case "names": + return ec.fieldContext_ExistingModelLinks_names(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type ExistingModelLinks", field.Name) + }, + } + return fc, nil +} + func (ec *executionContext) _PlanGeneralCharacteristics_hasComponentsOrTracks(ctx context.Context, field graphql.CollectedField, obj *models.PlanGeneralCharacteristics) (ret graphql.Marshaler) { fc, err := ec.fieldContext_PlanGeneralCharacteristics_hasComponentsOrTracks(ctx, field) if err != nil { @@ -49472,8 +49612,6 @@ func (ec *executionContext) fieldContext_Query_modelPlan(ctx context.Context, fi return ec.fieldContext_ModelPlan_nameHistory(ctx, field) case "operationalNeeds": return ec.fieldContext_ModelPlan_operationalNeeds(ctx, field) - case "existingModelLinks": - return ec.fieldContext_ModelPlan_existingModelLinks(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type ModelPlan", field.Name) }, @@ -49738,8 +49876,6 @@ func (ec *executionContext) fieldContext_Query_modelPlanCollection(ctx context.C return ec.fieldContext_ModelPlan_nameHistory(ctx, field) case "operationalNeeds": return ec.fieldContext_ModelPlan_operationalNeeds(ctx, field) - case "existingModelLinks": - return ec.fieldContext_ModelPlan_existingModelLinks(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type ModelPlan", field.Name) }, @@ -51506,12 +51642,12 @@ func (ec *executionContext) fieldContext_Query_existingModelLink(ctx context.Con return ec.fieldContext_ExistingModelLink_modelPlanID(ctx, field) case "existingModelID": return ec.fieldContext_ExistingModelLink_existingModelID(ctx, field) - case "existingModel": - return ec.fieldContext_ExistingModelLink_existingModel(ctx, field) case "currentModelPlanID": return ec.fieldContext_ExistingModelLink_currentModelPlanID(ctx, field) - case "currentModelPlan": - return ec.fieldContext_ExistingModelLink_currentModelPlan(ctx, field) + case "fieldName": + return ec.fieldContext_ExistingModelLink_fieldName(ctx, field) + case "model": + return ec.fieldContext_ExistingModelLink_model(ctx, field) case "createdBy": return ec.fieldContext_ExistingModelLink_createdBy(ctx, field) case "createdByUserAccount": @@ -56505,6 +56641,29 @@ func (ec *executionContext) unmarshalInputUpdateOperationalSolutionSubtaskInput( // region ************************** interface.gotpl *************************** +func (ec *executionContext) _LinkedExistingModel(ctx context.Context, sel ast.SelectionSet, obj models.LinkedExistingModel) graphql.Marshaler { + switch obj := (obj).(type) { + case nil: + return graphql.Null + case models.ExistingModel: + return ec._ExistingModel(ctx, sel, &obj) + case *models.ExistingModel: + if obj == nil { + return graphql.Null + } + return ec._ExistingModel(ctx, sel, obj) + case models.ModelPlan: + return ec._ModelPlan(ctx, sel, &obj) + case *models.ModelPlan: + if obj == nil { + return graphql.Null + } + return ec._ModelPlan(ctx, sel, obj) + default: + panic(fmt.Errorf("unexpected type %T", obj)) + } +} + func (ec *executionContext) _TaggedEntity(ctx context.Context, sel ast.SelectionSet, obj models.TaggedEntity) graphql.Marshaler { switch obj := (obj).(type) { case nil: @@ -57083,7 +57242,7 @@ func (ec *executionContext) _DiscussionRoleSelection(ctx context.Context, sel as return out } -var existingModelImplementors = []string{"ExistingModel"} +var existingModelImplementors = []string{"ExistingModel", "LinkedExistingModel"} func (ec *executionContext) _ExistingModel(ctx context.Context, sel ast.SelectionSet, obj *models.ExistingModel) graphql.Marshaler { fields := graphql.CollectFields(ec.OperationContext, sel, existingModelImplementors) @@ -57098,6 +57257,9 @@ func (ec *executionContext) _ExistingModel(ctx context.Context, sel ast.Selectio out.Values[i] = ec._ExistingModel_id(ctx, field, obj) case "modelName": out.Values[i] = ec._ExistingModel_modelName(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } case "stage": out.Values[i] = ec._ExistingModel_stage(ctx, field, obj) if out.Values[i] == graphql.Null { @@ -57208,52 +57370,143 @@ func (ec *executionContext) _ExistingModel(ctx context.Context, sel ast.Selectio } out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) - case "modifiedDts": - out.Values[i] = ec._ExistingModel_modifiedDts(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - out.Dispatch(ctx) - if out.Invalids > 0 { - return graphql.Null - } - - atomic.AddInt32(&ec.deferred, int32(len(deferred))) - - for label, dfs := range deferred { - ec.processDeferredGroup(graphql.DeferredGroup{ - Label: label, - Path: graphql.GetPath(ctx), - FieldSet: dfs, - Context: ctx, - }) - } - - return out -} - -var existingModelLinkImplementors = []string{"ExistingModelLink"} - -func (ec *executionContext) _ExistingModelLink(ctx context.Context, sel ast.SelectionSet, obj *models.ExistingModelLink) graphql.Marshaler { - fields := graphql.CollectFields(ec.OperationContext, sel, existingModelLinkImplementors) - - out := graphql.NewFieldSet(fields) - deferred := make(map[string]*graphql.FieldSet) - for i, field := range fields { - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("ExistingModelLink") - case "id": - out.Values[i] = ec._ExistingModelLink_id(ctx, field, obj) - case "modelPlanID": - out.Values[i] = ec._ExistingModelLink_modelPlanID(ctx, field, obj) + case "modifiedDts": + out.Values[i] = ec._ExistingModel_modifiedDts(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + +var existingModelLinkImplementors = []string{"ExistingModelLink"} + +func (ec *executionContext) _ExistingModelLink(ctx context.Context, sel ast.SelectionSet, obj *models.ExistingModelLink) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, existingModelLinkImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("ExistingModelLink") + case "id": + out.Values[i] = ec._ExistingModelLink_id(ctx, field, obj) + case "modelPlanID": + out.Values[i] = ec._ExistingModelLink_modelPlanID(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "existingModelID": + out.Values[i] = ec._ExistingModelLink_existingModelID(ctx, field, obj) + case "currentModelPlanID": + out.Values[i] = ec._ExistingModelLink_currentModelPlanID(ctx, field, obj) + case "fieldName": + out.Values[i] = ec._ExistingModelLink_fieldName(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "model": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._ExistingModelLink_model(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + if field.Deferrable != nil { + dfs, ok := deferred[field.Deferrable.Label] + di := 0 + if ok { + dfs.AddField(field) + di = len(dfs.Values) - 1 + } else { + dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) + deferred[field.Deferrable.Label] = dfs + } + dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, dfs) + }) + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + case "createdBy": + out.Values[i] = ec._ExistingModelLink_createdBy(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "createdByUserAccount": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._ExistingModelLink_createdByUserAccount(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + if field.Deferrable != nil { + dfs, ok := deferred[field.Deferrable.Label] + di := 0 + if ok { + dfs.AddField(field) + di = len(dfs.Values) - 1 + } else { + dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) + deferred[field.Deferrable.Label] = dfs + } + dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, dfs) + }) + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + case "createdDts": + out.Values[i] = ec._ExistingModelLink_createdDts(ctx, field, obj) if out.Values[i] == graphql.Null { atomic.AddUint32(&out.Invalids, 1) } - case "existingModelID": - out.Values[i] = ec._ExistingModelLink_existingModelID(ctx, field, obj) - case "existingModel": + case "modifiedBy": + out.Values[i] = ec._ExistingModelLink_modifiedBy(ctx, field, obj) + case "modifiedByUserAccount": field := field innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { @@ -57262,7 +57515,7 @@ func (ec *executionContext) _ExistingModelLink(ctx context.Context, sel ast.Sele ec.Error(ctx, ec.Recover(ctx, r)) } }() - res = ec._ExistingModelLink_existingModel(ctx, field, obj) + res = ec._ExistingModelLink_modifiedByUserAccount(ctx, field, obj) return res } @@ -57286,90 +57539,58 @@ func (ec *executionContext) _ExistingModelLink(ctx context.Context, sel ast.Sele } out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) - case "currentModelPlanID": - out.Values[i] = ec._ExistingModelLink_currentModelPlanID(ctx, field, obj) - case "currentModelPlan": - field := field + case "modifiedDts": + out.Values[i] = ec._ExistingModelLink_modifiedDts(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } - innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._ExistingModelLink_currentModelPlan(ctx, field, obj) - return res - } + atomic.AddInt32(&ec.deferred, int32(len(deferred))) - if field.Deferrable != nil { - dfs, ok := deferred[field.Deferrable.Label] - di := 0 - if ok { - dfs.AddField(field) - di = len(dfs.Values) - 1 - } else { - dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) - deferred[field.Deferrable.Label] = dfs - } - dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { - return innerFunc(ctx, dfs) - }) + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue - } + return out +} - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) - case "createdBy": - out.Values[i] = ec._ExistingModelLink_createdBy(ctx, field, obj) +var existingModelLinksImplementors = []string{"ExistingModelLinks"} + +func (ec *executionContext) _ExistingModelLinks(ctx context.Context, sel ast.SelectionSet, obj *models.ExistingModelLinks) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, existingModelLinksImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("ExistingModelLinks") + case "links": + out.Values[i] = ec._ExistingModelLinks_links(ctx, field, obj) if out.Values[i] == graphql.Null { atomic.AddUint32(&out.Invalids, 1) } - case "createdByUserAccount": - field := field - - innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._ExistingModelLink_createdByUserAccount(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&fs.Invalids, 1) - } - return res - } - - if field.Deferrable != nil { - dfs, ok := deferred[field.Deferrable.Label] - di := 0 - if ok { - dfs.AddField(field) - di = len(dfs.Values) - 1 - } else { - dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) - deferred[field.Deferrable.Label] = dfs - } - dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { - return innerFunc(ctx, dfs) - }) - - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue + case "fieldName": + out.Values[i] = ec._ExistingModelLinks_fieldName(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) } - - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) - case "createdDts": - out.Values[i] = ec._ExistingModelLink_createdDts(ctx, field, obj) + case "modelPlanID": + out.Values[i] = ec._ExistingModelLinks_modelPlanID(ctx, field, obj) if out.Values[i] == graphql.Null { atomic.AddUint32(&out.Invalids, 1) } - case "modifiedBy": - out.Values[i] = ec._ExistingModelLink_modifiedBy(ctx, field, obj) - case "modifiedByUserAccount": + case "names": field := field innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { @@ -57378,7 +57599,10 @@ func (ec *executionContext) _ExistingModelLink(ctx context.Context, sel ast.Sele ec.Error(ctx, ec.Recover(ctx, r)) } }() - res = ec._ExistingModelLink_modifiedByUserAccount(ctx, field, obj) + res = ec._ExistingModelLinks_names(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } return res } @@ -57402,8 +57626,6 @@ func (ec *executionContext) _ExistingModelLink(ctx context.Context, sel ast.Sele } out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) - case "modifiedDts": - out.Values[i] = ec._ExistingModelLink_modifiedDts(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -57558,7 +57780,7 @@ func (ec *executionContext) _LaunchDarklySettings(ctx context.Context, sel ast.S return out } -var modelPlanImplementors = []string{"ModelPlan"} +var modelPlanImplementors = []string{"ModelPlan", "LinkedExistingModel"} func (ec *executionContext) _ModelPlan(ctx context.Context, sel ast.SelectionSet, obj *models.ModelPlan) graphql.Marshaler { fields := graphql.CollectFields(ec.OperationContext, sel, modelPlanImplementors) @@ -58249,42 +58471,6 @@ func (ec *executionContext) _ModelPlan(ctx context.Context, sel ast.SelectionSet continue } - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) - case "existingModelLinks": - field := field - - innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._ModelPlan_existingModelLinks(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&fs.Invalids, 1) - } - return res - } - - if field.Deferrable != nil { - dfs, ok := deferred[field.Deferrable.Label] - di := 0 - if ok { - dfs.AddField(field) - di = len(dfs.Values) - 1 - } else { - dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) - deferred[field.Deferrable.Label] = dfs - } - dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { - return innerFunc(ctx, dfs) - }) - - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue - } - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) default: panic("unknown field " + strconv.Quote(field.Name)) @@ -61374,6 +61560,39 @@ func (ec *executionContext) _PlanGeneralCharacteristics(ctx context.Context, sel out.Values[i] = ec._PlanGeneralCharacteristics_resemblesExistingModelHow(ctx, field, obj) case "resemblesExistingModelNote": out.Values[i] = ec._PlanGeneralCharacteristics_resemblesExistingModelNote(ctx, field, obj) + case "resemblesExistingModelWhich": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._PlanGeneralCharacteristics_resemblesExistingModelWhich(ctx, field, obj) + return res + } + + if field.Deferrable != nil { + dfs, ok := deferred[field.Deferrable.Label] + di := 0 + if ok { + dfs.AddField(field) + di = len(dfs.Values) - 1 + } else { + dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) + deferred[field.Deferrable.Label] = dfs + } + dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, dfs) + }) + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) case "hasComponentsOrTracks": out.Values[i] = ec._PlanGeneralCharacteristics_hasComponentsOrTracks(ctx, field, obj) case "hasComponentsOrTracksDiffer": @@ -67532,6 +67751,22 @@ func (ec *executionContext) marshalNEvaluationApproachType2ᚕgithubᚗcomᚋcms return ret } +func (ec *executionContext) unmarshalNExisitingModelLinkFieldType2githubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExisitingModelLinkFieldType(ctx context.Context, v interface{}) (models.ExisitingModelLinkFieldType, error) { + tmp, err := graphql.UnmarshalString(v) + res := models.ExisitingModelLinkFieldType(tmp) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNExisitingModelLinkFieldType2githubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExisitingModelLinkFieldType(ctx context.Context, sel ast.SelectionSet, v models.ExisitingModelLinkFieldType) graphql.Marshaler { + res := graphql.MarshalString(string(v)) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + func (ec *executionContext) marshalNExistingModel2ᚕᚖgithubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExistingModelᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.ExistingModel) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup @@ -67644,6 +67879,20 @@ func (ec *executionContext) marshalNExistingModelLink2ᚖgithubᚗcomᚋcmsgov return ec._ExistingModelLink(ctx, sel, v) } +func (ec *executionContext) marshalNExistingModelLinks2githubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExistingModelLinks(ctx context.Context, sel ast.SelectionSet, v models.ExistingModelLinks) graphql.Marshaler { + return ec._ExistingModelLinks(ctx, sel, &v) +} + +func (ec *executionContext) marshalNExistingModelLinks2ᚖgithubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExistingModelLinks(ctx context.Context, sel ast.SelectionSet, v *models.ExistingModelLinks) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._ExistingModelLinks(ctx, sel, v) +} + func (ec *executionContext) marshalNField2ᚕᚖgithubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐFieldᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.Field) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup @@ -68273,6 +68522,16 @@ func (ec *executionContext) marshalNLaunchDarklySettings2ᚖgithubᚗcomᚋcmsgo return ec._LaunchDarklySettings(ctx, sel, v) } +func (ec *executionContext) marshalNLinkedExistingModel2githubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐLinkedExistingModel(ctx context.Context, sel ast.SelectionSet, v models.LinkedExistingModel) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._LinkedExistingModel(ctx, sel, v) +} + func (ec *executionContext) unmarshalNMap2map(ctx context.Context, v interface{}) (map[string]interface{}, error) { res, err := graphql.UnmarshalMap(v) return res, graphql.ErrorOnPath(ctx, err) @@ -72616,6 +72875,13 @@ func (ec *executionContext) marshalOExistingModel2ᚖgithubᚗcomᚋcmsgovᚋmin return ec._ExistingModel(ctx, sel, v) } +func (ec *executionContext) marshalOExistingModelLinks2ᚖgithubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐExistingModelLinks(ctx context.Context, sel ast.SelectionSet, v *models.ExistingModelLinks) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._ExistingModelLinks(ctx, sel, v) +} + func (ec *executionContext) unmarshalOFrequencyType2ᚕgithubᚗcomᚋcmsgovᚋmintᚑappᚋpkgᚋmodelsᚐFrequencyTypeᚄ(ctx context.Context, v interface{}) ([]models.FrequencyType, error) { if v == nil { return nil, nil @@ -74668,16 +74934,6 @@ func (ec *executionContext) marshalOStatesAndTerritories2ᚕgithubᚗcomᚋcmsgo return ret } -func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) { - res, err := graphql.UnmarshalString(v) - return res, graphql.ErrorOnPath(ctx, err) -} - -func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { - res := graphql.MarshalString(v) - return res -} - func (ec *executionContext) unmarshalOString2ᚕstringᚄ(ctx context.Context, v interface{}) ([]string, error) { if v == nil { return nil, nil diff --git a/pkg/graph/gqlresolvers/schema.resolvers.go b/pkg/graph/gqlresolvers/schema.resolvers.go index 865458d6b7..e124bbff5e 100644 --- a/pkg/graph/gqlresolvers/schema.resolvers.go +++ b/pkg/graph/gqlresolvers/schema.resolvers.go @@ -31,21 +31,14 @@ func (r *discussionReplyResolver) Content(ctx context.Context, obj *models.Discu return resolvers.TaggedContentGet(logger, r.store, string(obj.Content.RawContent), "discussion_reply", "content", obj.ID) } -// ExistingModel is the resolver for the existingModel field. -func (r *existingModelLinkResolver) ExistingModel(ctx context.Context, obj *models.ExistingModelLink) (*models.ExistingModel, error) { - if obj.ExistingModelID == nil { //Don't do a DB call if nil - return nil, nil - } - - return resolvers.ExistingModelGetByIDLOADER(ctx, *obj.ExistingModelID) //TODO, implement loader, or this will be many queries +// Model is the resolver for the model field. +func (r *existingModelLinkResolver) Model(ctx context.Context, obj *models.ExistingModelLink) (models.LinkedExistingModel, error) { + return resolvers.ExistingModelLinkGetModel(ctx, obj) } -// CurrentModelPlan is the resolver for the currentModelPlan field. -func (r *existingModelLinkResolver) CurrentModelPlan(ctx context.Context, obj *models.ExistingModelLink) (*models.ModelPlan, error) { - if obj.CurrentModelPlanID == nil { //Don't do a DB call if nil - return nil, nil - } - return resolvers.ModelPlanGetByIDLOADER(ctx, *obj.CurrentModelPlanID) //TODO, implement loader, or this will be many queries +// Names is the resolver for the names field. +func (r *existingModelLinksResolver) Names(ctx context.Context, obj *models.ExistingModelLinks) ([]string, error) { + return resolvers.ExistingModelLinksNameArray(ctx, obj.ModelPlanID, obj.FieldName) } // Basics is the resolver for the basics field. @@ -144,11 +137,6 @@ func (r *modelPlanResolver) OperationalNeeds(ctx context.Context, obj *models.Mo return resolvers.OperationalNeedCollectionGetByModelPlanIDLOADER(ctx, obj.ID) } -// ExistingModelLinks is the resolver for the existingModelLinks field. -func (r *modelPlanResolver) ExistingModelLinks(ctx context.Context, obj *models.ModelPlan) ([]*models.ExistingModelLink, error) { - return resolvers.ExistingModelLinkGetByModelPlanIDLOADER(ctx, obj.ID) -} - // CreateModelPlan is the resolver for the createModelPlan field. func (r *mutationResolver) CreateModelPlan(ctx context.Context, modelName string) (*models.ModelPlan, error) { logger := appcontext.ZLogger(ctx) @@ -484,10 +472,10 @@ func (r *mutationResolver) DeleteOperationalSolutionSubtask(ctx context.Context, } // UpdateExistingModelLinks is the resolver for the updateExistingModelLinks field. -func (r *mutationResolver) UpdateExistingModelLinks(ctx context.Context, modelPlanID uuid.UUID, existingModelIDs []int, currentModelPlanIDs []uuid.UUID) ([]*models.ExistingModelLink, error) { +func (r *mutationResolver) UpdateExistingModelLinks(ctx context.Context, modelPlanID uuid.UUID, fieldName models.ExisitingModelLinkFieldType, existingModelIDs []int, currentModelPlanIDs []uuid.UUID) (*models.ExistingModelLinks, error) { logger := appcontext.ZLogger(ctx) principal := appcontext.Principal(ctx) - return resolvers.ExistingModelLinksUpdate(logger, r.store, principal, modelPlanID, existingModelIDs, currentModelPlanIDs) + return resolvers.ExistingModelLinksUpdate(logger, r.store, principal, modelPlanID, fieldName, existingModelIDs, currentModelPlanIDs) } // ShareModelPlan is the resolver for the shareModelPlan field. @@ -672,6 +660,11 @@ func (r *planGeneralCharacteristicsResolver) ExistingModelPlan(ctx context.Conte return resolvers.ExistingModelGetByIDLOADER(ctx, *obj.ExistingModelID) //TODO, implement loader, or this will be many queries } +// ResemblesExistingModelWhich is the resolver for the resemblesExistingModelWhich field. +func (r *planGeneralCharacteristicsResolver) ResemblesExistingModelWhich(ctx context.Context, obj *models.PlanGeneralCharacteristics) (*models.ExistingModelLinks, error) { + return resolvers.ExistingModelLinksGetByModelPlanIDAndFieldNameLOADER(ctx, obj.ModelPlanID, models.EMLFTGeneralCharacteristicsResemblesExistingModelWhich) +} + // AlternativePaymentModelTypes is the resolver for the alternativePaymentModelTypes field. func (r *planGeneralCharacteristicsResolver) AlternativePaymentModelTypes(ctx context.Context, obj *models.PlanGeneralCharacteristics) ([]model.AlternativePaymentModelType, error) { apmTypes := models.ConvertEnums[model.AlternativePaymentModelType](obj.AlternativePaymentModelTypes) @@ -1125,6 +1118,11 @@ func (r *Resolver) ExistingModelLink() generated.ExistingModelLinkResolver { return &existingModelLinkResolver{r} } +// ExistingModelLinks returns generated.ExistingModelLinksResolver implementation. +func (r *Resolver) ExistingModelLinks() generated.ExistingModelLinksResolver { + return &existingModelLinksResolver{r} +} + // ModelPlan returns generated.ModelPlanResolver implementation. func (r *Resolver) ModelPlan() generated.ModelPlanResolver { return &modelPlanResolver{r} } @@ -1205,6 +1203,7 @@ func (r *Resolver) TaggedContent() generated.TaggedContentResolver { return &tag type auditChangeResolver struct{ *Resolver } type discussionReplyResolver struct{ *Resolver } type existingModelLinkResolver struct{ *Resolver } +type existingModelLinksResolver struct{ *Resolver } type modelPlanResolver struct{ *Resolver } type mutationResolver struct{ *Resolver } type operationalNeedResolver struct{ *Resolver } @@ -1224,3 +1223,23 @@ type queryResolver struct{ *Resolver } type subscriptionResolver struct{ *Resolver } type tagResolver struct{ *Resolver } type taggedContentResolver 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 *existingModelLinkResolver) ExistingModel(ctx context.Context, obj *models.ExistingModelLink) (*models.ExistingModel, error) { + if obj.ExistingModelID == nil { //Don't do a DB call if nil + return nil, nil + } + + return resolvers.ExistingModelGetByIDLOADER(ctx, *obj.ExistingModelID) //TODO, implement loader, or this will be many queries +} +func (r *existingModelLinkResolver) CurrentModelPlan(ctx context.Context, obj *models.ExistingModelLink) (*models.ModelPlan, error) { + if obj.CurrentModelPlanID == nil { //Don't do a DB call if nil + return nil, nil + } + return resolvers.ModelPlanGetByIDLOADER(ctx, *obj.CurrentModelPlanID) //TODO, implement loader, or this will be many queries +} diff --git a/pkg/graph/resolvers/exisiting_model_link.go b/pkg/graph/resolvers/exisiting_model_link.go index 86e8d60f1d..bcf2dbfcaa 100644 --- a/pkg/graph/resolvers/exisiting_model_link.go +++ b/pkg/graph/resolvers/exisiting_model_link.go @@ -2,6 +2,7 @@ package resolvers import ( "context" + "fmt" "go.uber.org/zap" @@ -13,12 +14,13 @@ import ( "github.com/cmsgov/mint-app/pkg/storage/loaders" ) -// ExistingModelLinkGetByModelPlanIDLOADER implements resolver logic to get Existing Model Link by a model plan ID using a data loader -func ExistingModelLinkGetByModelPlanIDLOADER(ctx context.Context, modelPlanID uuid.UUID) ([]*models.ExistingModelLink, error) { +// ExistingModelLinkGetByModelPlanIDAndFieldNameLOADER implements resolver logic to get Existing Model Link by a model plan ID using a data loader +func ExistingModelLinkGetByModelPlanIDAndFieldNameLOADER(ctx context.Context, modelPlanID uuid.UUID, fieldName models.ExisitingModelLinkFieldType) ([]*models.ExistingModelLink, error) { allLoaders := loaders.Loaders(ctx) linkLoader := allLoaders.ExistingModelLinkLoader key := loaders.NewKeyArgs() key.Args["model_plan_id"] = modelPlanID + key.Args["field_name"] = fieldName thunk := linkLoader.Loader.Load(ctx, key) result, err := thunk() @@ -30,19 +32,33 @@ func ExistingModelLinkGetByModelPlanIDLOADER(ctx context.Context, modelPlanID uu return result.([]*models.ExistingModelLink), nil } +// ExistingModelLinksGetByModelPlanIDAndFieldNameLOADER implements resolver logic to get Existing Model Link by a model plan ID using a data loader +func ExistingModelLinksGetByModelPlanIDAndFieldNameLOADER(ctx context.Context, modelPlanID uuid.UUID, fieldName models.ExisitingModelLinkFieldType) (*models.ExistingModelLinks, error) { + linkCollection, err := ExistingModelLinkGetByModelPlanIDAndFieldNameLOADER(ctx, modelPlanID, fieldName) + + if err != nil { + return nil, err + } + links := models.NewExistingModelLinks(modelPlanID, fieldName, linkCollection) + + return links, nil +} + // ExistingModelLinksUpdate creates or deletes existing model links based on the list provided. -func ExistingModelLinksUpdate(logger *zap.Logger, store *storage.Store, principal authentication.Principal, modelPlanID uuid.UUID, existingModelIDs []int, currentModelPlanIDs []uuid.UUID) ([]*models.ExistingModelLink, error) { +func ExistingModelLinksUpdate(logger *zap.Logger, store *storage.Store, principal authentication.Principal, modelPlanID uuid.UUID, fieldName models.ExisitingModelLinkFieldType, existingModelIDs []int, currentModelPlanIDs []uuid.UUID) (*models.ExistingModelLinks, error) { link := models.NewExistingModelLink(principal.Account().ID, modelPlanID, nil, nil) // this is for access check err := BaseStructPreCreate(logger, link, principal, store, true) if err != nil { return nil, err } - retLink, err := store.ExistingModelLinksUpdate(logger, principal.Account().ID, modelPlanID, existingModelIDs, currentModelPlanIDs) + retLinks, err := store.ExistingModelLinksUpdate(logger, principal.Account().ID, modelPlanID, fieldName, existingModelIDs, currentModelPlanIDs) if err != nil { return nil, err } - return retLink, err + links := models.NewExistingModelLinks(modelPlanID, fieldName, retLinks) + + return links, err } @@ -56,3 +72,33 @@ func ExistingModelLinkGetByID(logger *zap.Logger, store *storage.Store, principa return retLink, err } + +// ExistingModelLinkGetModel conditionally returns either an ExistingModel, or a ModelPlan that is connected in an existing model link +func ExistingModelLinkGetModel(ctx context.Context, link *models.ExistingModelLink) (models.LinkedExistingModel, error) { + if link.CurrentModelPlanID != nil { + return ModelPlanGetByIDLOADER(ctx, *link.CurrentModelPlanID) + } + + if link.ExistingModelID != nil { + return ExistingModelGetByIDLOADER(ctx, *link.ExistingModelID) + } + return nil, fmt.Errorf("no valid model for existing model link %s for model_plan_id %s", link.ID, link.ModelPlanID) + +} + +func ExistingModelLinksNameArray(ctx context.Context, modelPlanID uuid.UUID, fieldName models.ExisitingModelLinkFieldType) ([]string, error) { + allLoaders := loaders.Loaders(ctx) + linkLoader := allLoaders.ExistingModelLinkNameLoader + key := loaders.NewKeyArgs() + key.Args["model_plan_id"] = modelPlanID + key.Args["field_name"] = fieldName + + thunk := linkLoader.Loader.Load(ctx, key) + result, err := thunk() + + if err != nil { + return nil, err + } + + return result.([]string), nil +} diff --git a/pkg/graph/resolvers/existing_model_link_test.go b/pkg/graph/resolvers/existing_model_link_test.go index 0f12bf396b..9efece2a22 100644 --- a/pkg/graph/resolvers/existing_model_link_test.go +++ b/pkg/graph/resolvers/existing_model_link_test.go @@ -3,6 +3,7 @@ package resolvers import ( "context" "fmt" + "sync" "github.com/google/uuid" "github.com/samber/lo" @@ -21,16 +22,21 @@ func (suite *ResolverSuite) TestExistingModelLinksUpdate() { }) /* LINK ALL EXISTING MODELS AND ASSERT LENGTH MATCHES */ - links, err := ExistingModelLinksUpdate(suite.testConfigs.Logger, suite.testConfigs.Store, suite.testConfigs.Principal, plan.ID, ids, nil) + links, err := ExistingModelLinksUpdate(suite.testConfigs.Logger, suite.testConfigs.Store, suite.testConfigs.Principal, plan.ID, models.EMLFTGeneralCharacteristicsResemblesExistingModelWhich, ids, nil) suite.NoError(err) - suite.Len(links, len(ids)) + suite.Len(links.Links, len(ids)) + + /* Get links for another section, and confirm that there are no links */ + otherLinks, err := ExistingModelLinksGetByModelPlanIDAndFieldNameLOADER(suite.testConfigs.Context, plan.ID, models.EMLFTGeneralCharacteristicsParticipationExistingModelWhich) + suite.NoError(err) + suite.Len(otherLinks.Links, 0) /* Link the model plan, make sure other links were deleted, and that there is only the one link*/ - links2, err := ExistingModelLinksUpdate(suite.testConfigs.Logger, suite.testConfigs.Store, suite.testConfigs.Principal, plan.ID, nil, []uuid.UUID{modelToLink.ID}) + links2, err := ExistingModelLinksUpdate(suite.testConfigs.Logger, suite.testConfigs.Store, suite.testConfigs.Principal, plan.ID, models.EMLFTGeneralCharacteristicsResemblesExistingModelWhich, nil, []uuid.UUID{modelToLink.ID}) suite.NoError(err) - suite.Len(links2, 1) - suite.Equal(links2[0].ModelPlanID, plan.ID) - suite.Equal(links2[0].CurrentModelPlanID, &modelToLink.ID) + suite.Len(links2.Links, 1) + suite.Equal(links2.Links[0].ModelPlanID, plan.ID) + suite.Equal(links2.Links[0].CurrentModelPlanID, &modelToLink.ID) } @@ -38,10 +44,10 @@ func (suite *ResolverSuite) ExistingModelLinkGetByID() { plan1 := suite.createModelPlan("Plan For Link 1") existingModels, _ := ExistingModelCollectionGet(suite.testConfigs.Logger, suite.testConfigs.Store) - links, err := ExistingModelLinksUpdate(suite.testConfigs.Logger, suite.testConfigs.Store, suite.testConfigs.Principal, plan1.ID, []int{existingModels[0].ID}, nil) + links, err := ExistingModelLinksUpdate(suite.testConfigs.Logger, suite.testConfigs.Store, suite.testConfigs.Principal, plan1.ID, models.EMLFTGeneralCharacteristicsResemblesExistingModelWhich, []int{existingModels[0].ID}, nil) suite.NoError(err) suite.Len(links, 1) - link1 := links[0] + link1 := links.Links[0] suite.NotNil(link1) retLink, err := ExistingModelLinkGetByID(suite.testConfigs.Logger, suite.testConfigs.Store, suite.testConfigs.Principal, link1.ID) @@ -58,26 +64,49 @@ func (suite *ResolverSuite) ExistingModelLinkGetByID() { func (suite *ResolverSuite) TestExistingModelLinkDataLoader() { plan1 := suite.createModelPlan("Plan For Link 1") plan2 := suite.createModelPlan("Plan For Link 2") - _, err := ExistingModelLinksUpdate(suite.testConfigs.Logger, suite.testConfigs.Store, suite.testConfigs.Principal, plan1.ID, nil, []uuid.UUID{plan2.ID, plan1.ID}) + + plan3 := suite.createModelPlan("Alphabetical Plan For Link 3") + + genCharWhichField := models.EMLFTGeneralCharacteristicsResemblesExistingModelWhich + _, err := ExistingModelLinksUpdate(suite.testConfigs.Logger, suite.testConfigs.Store, suite.testConfigs.Principal, plan1.ID, genCharWhichField, nil, []uuid.UUID{plan2.ID, plan1.ID}) suite.NoError(err) - _, err2 := ExistingModelLinksUpdate(suite.testConfigs.Logger, suite.testConfigs.Store, suite.testConfigs.Principal, plan2.ID, nil, []uuid.UUID{plan2.ID, plan1.ID}) + _, err2 := ExistingModelLinksUpdate(suite.testConfigs.Logger, suite.testConfigs.Store, suite.testConfigs.Principal, plan2.ID, genCharWhichField, nil, []uuid.UUID{plan2.ID, plan1.ID, plan3.ID}) suite.NoError(err2) g, ctx := errgroup.WithContext(suite.testConfigs.Context) g.Go(func() error { - return verifyExistingModelLinkLoader(ctx, plan1.ID) + return verifyExistingModelLinkLoader(ctx, plan1.ID, genCharWhichField) }) g.Go(func() error { - return verifyExistingModelLinkLoader(ctx, plan2.ID) + return verifyExistingModelLinkLoader(ctx, plan2.ID, genCharWhichField) }) err3 := g.Wait() suite.NoError(err3) + suite.Run("Name data loader returns correctly", func() { + + var wg sync.WaitGroup + wg.Add(3) //note there are three tests + go func() { + defer wg.Done() + suite.verifyExistingModelLinkNameLoader(plan1.ID, genCharWhichField, 2, plan1.ModelName) + }() + go func() { + defer wg.Done() + suite.verifyExistingModelLinkNameLoader(plan2.ID, genCharWhichField, 3, plan3.ModelName) + }() + go func() { + defer wg.Done() + suite.verifyExistingModelLinkNameLoader(plan3.ID, genCharWhichField, 0, "") + }() + wg.Wait() + }) + } -func verifyExistingModelLinkLoader(ctx context.Context, modelPlanID uuid.UUID) error { +func verifyExistingModelLinkLoader(ctx context.Context, modelPlanID uuid.UUID, fieldName models.ExisitingModelLinkFieldType) error { - links, err := ExistingModelLinkGetByModelPlanIDLOADER(ctx, modelPlanID) + links, err := ExistingModelLinkGetByModelPlanIDAndFieldNameLOADER(ctx, modelPlanID, fieldName) if err != nil { return err } @@ -90,3 +119,18 @@ func verifyExistingModelLinkLoader(ctx context.Context, modelPlanID uuid.UUID) e } return nil } + +func (suite *ResolverSuite) verifyExistingModelLinkNameLoader( + modelPlanID uuid.UUID, + fieldName models.ExisitingModelLinkFieldType, + expectedCount int, + firstName string) { + + names, err := ExistingModelLinksNameArray(suite.testConfigs.Context, modelPlanID, fieldName) + suite.NoError(err) + suite.Len(names, expectedCount) + if len(names) > 1 { + suite.EqualValues(firstName, names[0]) + } + +} diff --git a/pkg/graph/schema.graphql b/pkg/graph/schema.graphql index a6edd0d2b0..c84d12dc37 100644 --- a/pkg/graph/schema.graphql +++ b/pkg/graph/schema.graphql @@ -78,7 +78,6 @@ type ModelPlan { prepareForClearance: PrepareForClearance! nameHistory(sort: SortDirection! = DESC): [String!]! operationalNeeds: [OperationalNeed!]! - existingModelLinks: [ExistingModelLink!]! } type OperationalNeed { @@ -186,7 +185,7 @@ ExistingModel represents a model that already exists outside of the scope of MIN """ type ExistingModel { id: Int - modelName: String + modelName: String! stage: String! numberOfParticipants: String category: String @@ -208,14 +207,26 @@ type ExistingModel { modifiedByUserAccount: UserAccount modifiedDts: Time } +""" +LinkedExistingModel is a union type that returns either an Existing Model, or a Model plan from the database +""" +union LinkedExistingModel = ExistingModel | ModelPlan + + +type ExistingModelLinks { + links: [ExistingModelLink!]! + fieldName: ExisitingModelLinkFieldType! + modelPlanID: UUID! + names: [String!]! +} type ExistingModelLink { id: UUID modelPlanID: UUID! existingModelID: Int - existingModel: ExistingModel currentModelPlanID: UUID - currentModelPlan: ModelPlan + fieldName: ExisitingModelLinkFieldType! + model: LinkedExistingModel! createdBy: UUID! createdByUserAccount: UserAccount! @@ -535,6 +546,7 @@ type PlanGeneralCharacteristics { resemblesExistingModel: Boolean resemblesExistingModelHow: String resemblesExistingModelNote: String + resemblesExistingModelWhich: ExistingModelLinks hasComponentsOrTracks: Boolean hasComponentsOrTracksDiffer: String hasComponentsOrTracksNote: String @@ -1420,6 +1432,11 @@ input ReportAProblemInput { severityOther: String } +enum ExisitingModelLinkFieldType { + GEN_CHAR_RESEMBLES_EXISTING_MODEL_WHICH + GEN_CHAR_PARTICIPATION_EXISTING_MODEL_WHICH +} + enum ReportAProblemSection { READ_VIEW TASK_LIST @@ -1920,7 +1937,11 @@ updateOperationalSolutionSubtasks(inputs: [UpdateOperationalSolutionSubtaskInput deleteOperationalSolutionSubtask(id: UUID!): Int! @hasRole(role: MINT_USER) -updateExistingModelLinks(modelPlanID: UUID!, existingModelIDs: [Int!],currentModelPlanIDs: [UUID!]): [ExistingModelLink!]! +""" +This will update linked existing models, and relatede model plans for given model plan and fieldName. +The fieldName allows it so you can create links for multiple sections of the model plan +""" +updateExistingModelLinks(modelPlanID: UUID!,fieldName: ExisitingModelLinkFieldType!, existingModelIDs: [Int!],currentModelPlanIDs: [UUID!]): ExistingModelLinks! @hasRole(role: MINT_USER) shareModelPlan(modelPlanID: UUID!, viewFilter: ModelViewFilter, usernames: [String!]!, optionalMessage: String): Boolean! diff --git a/pkg/models/existing_model.go b/pkg/models/existing_model.go index 6f0de272e2..4127ea3235 100644 --- a/pkg/models/existing_model.go +++ b/pkg/models/existing_model.go @@ -25,3 +25,5 @@ type ExistingModel struct { URL *string `json:"url" db:"url"` DisplayModelSummary *bool `json:"displayModelSummary" db:"display_model_summary"` } + +func (m ExistingModel) isLinkedExistingModel() {} diff --git a/pkg/models/existing_model_link.go b/pkg/models/existing_model_link.go index 9e9fb54d82..42058c90d0 100644 --- a/pkg/models/existing_model_link.go +++ b/pkg/models/existing_model_link.go @@ -2,17 +2,53 @@ package models import ( "github.com/google/uuid" + "github.com/lib/pq" ) // ExistingModelLink represents a link between another current model, or an existing model from the existing model table. type ExistingModelLink struct { - ExistingModelID *int `json:"existingModelID" db:"existing_model_id"` - CurrentModelPlanID *uuid.UUID `json:"currentModelPlanID" db:"current_model_plan_id"` + ExistingModelID *int `json:"existingModelID" db:"existing_model_id"` + CurrentModelPlanID *uuid.UUID `json:"currentModelPlanID" db:"current_model_plan_id"` + FieldName ExisitingModelLinkFieldType `json:"fieldName" db:"field_name"` baseStruct modelPlanRelation } +// ExisitingModelLinkFieldType is used to distinguish what part of the model plan this link refers to. +type ExisitingModelLinkFieldType string + +const ( + // EMLFTGeneralCharacteristicsResemblesExistingModelWhich is used to denote the link is in reference to the ResemblesExistingModelWhich question on Plan_General_Characteristics + EMLFTGeneralCharacteristicsResemblesExistingModelWhich ExisitingModelLinkFieldType = "GEN_CHAR_RESEMBLES_EXISTING_MODEL_WHICH" + // EMLFTGeneralCharacteristicsParticipationExistingModelWhich is used to denote the link is in refernce to the Participation in an existing model which question on Plan_Genereal_Characteristics + EMLFTGeneralCharacteristicsParticipationExistingModelWhich ExisitingModelLinkFieldType = "GEN_CHAR_PARTICIPATION_EXISTING_MODEL_WHICH" +) + +// LinkedExistingModel is an interface which is used to return a Union type for graphql. +// Specifically, it allows us to return either a model plan or an existing model. +type LinkedExistingModel interface { + isLinkedExistingModel() +} + +// ExistingModelLinks is a wrapper for a collection of Existing Model Links +type ExistingModelLinks struct { + FieldName ExisitingModelLinkFieldType `json:"fieldName" db:"field_name"` + Links []*ExistingModelLink + modelPlanRelation + // Name array to store data when specifically requested from the database. It isn't specifcally returned from the database unless requested by GQL + NameArray pq.StringArray `json:"names_array_db" db:"name_array"` +} + +func NewExistingModelLinks(modelPlanID uuid.UUID, fieldName ExisitingModelLinkFieldType, links []*ExistingModelLink) *ExistingModelLinks { + return &ExistingModelLinks{ + Links: links, + modelPlanRelation: NewModelPlanRelation(modelPlanID), + FieldName: fieldName, + } + +} + // NewExistingModelLink instantiates a new Existing ModelLink func NewExistingModelLink(createdBy uuid.UUID, modelPlanID uuid.UUID, existingModelID *int, currentModelPlanID *uuid.UUID) *ExistingModelLink { return &ExistingModelLink{ diff --git a/pkg/models/model_plan.go b/pkg/models/model_plan.go index 5f87943256..e6d45c92e2 100644 --- a/pkg/models/model_plan.go +++ b/pkg/models/model_plan.go @@ -21,6 +21,7 @@ func NewModelPlan(createdBy uuid.UUID, modelName string) *ModelPlan { } } +func (m ModelPlan) isLinkedExistingModel() {} // GetModelPlanID returns the modelPlanID of the task list section func (m ModelPlan) GetModelPlanID() uuid.UUID { diff --git a/pkg/storage/SQL/existing_model_link/create.sql b/pkg/storage/SQL/existing_model_link/create.sql index f011610ea7..06fbb55a28 100644 --- a/pkg/storage/SQL/existing_model_link/create.sql +++ b/pkg/storage/SQL/existing_model_link/create.sql @@ -3,6 +3,7 @@ INSERT INTO existing_model_link( model_plan_id, existing_model_id, current_model_plan_id, + field_name, created_by, modified_by ) @@ -11,6 +12,7 @@ VALUES( :model_plan_id, :existing_model_id, :current_model_plan_id, + :field_name, :created_by, :modified_by ) @@ -19,6 +21,7 @@ id, model_plan_id, existing_model_id, current_model_plan_id, +field_name, created_by, created_dts, modified_by, diff --git a/pkg/storage/SQL/existing_model_link/delete.sql b/pkg/storage/SQL/existing_model_link/delete.sql index 56ea5f1814..7ba6950814 100644 --- a/pkg/storage/SQL/existing_model_link/delete.sql +++ b/pkg/storage/SQL/existing_model_link/delete.sql @@ -5,6 +5,7 @@ id, model_plan_id, existing_model_id, current_model_plan_id, +field_name, created_by, created_dts, modified_by, diff --git a/pkg/storage/SQL/existing_model_link/get_by_id.sql b/pkg/storage/SQL/existing_model_link/get_by_id.sql index 818bbb1fb8..f2d93ef4ed 100644 --- a/pkg/storage/SQL/existing_model_link/get_by_id.sql +++ b/pkg/storage/SQL/existing_model_link/get_by_id.sql @@ -3,6 +3,7 @@ SELECT model_plan_id, existing_model_id, current_model_plan_id, + field_name, created_by, created_dts, modified_by, diff --git a/pkg/storage/SQL/existing_model_link/get_by_model_plan_id_LOADER.sql b/pkg/storage/SQL/existing_model_link/get_by_model_plan_id_and_field_name_LOADER.sql similarity index 64% rename from pkg/storage/SQL/existing_model_link/get_by_model_plan_id_LOADER.sql rename to pkg/storage/SQL/existing_model_link/get_by_model_plan_id_and_field_name_LOADER.sql index 6b04339117..cde485a4ce 100644 --- a/pkg/storage/SQL/existing_model_link/get_by_model_plan_id_LOADER.sql +++ b/pkg/storage/SQL/existing_model_link/get_by_model_plan_id_and_field_name_LOADER.sql @@ -1,9 +1,11 @@ WITH QUERIED_IDS AS ( /*Translate the input to a table */ - SELECT model_plan_id + SELECT + model_plan_id, + field_name FROM JSON_TO_RECORDSET(:paramTableJSON) - AS x("model_plan_id" UUID) --noqa + AS x("model_plan_id" UUID, "field_name" EXISITING_MODEL_LINK_FIELD_TYPE) --noqa ) SELECT @@ -11,10 +13,11 @@ SELECT link.model_plan_id, link.existing_model_id, link.current_model_plan_id, + link.field_name, link.created_by, link.created_dts, link.modified_by, link.modified_dts FROM QUERIED_IDS AS qIDs -INNER JOIN existing_model_link AS link ON link.model_plan_id = qIDs.model_plan_id; +INNER JOIN existing_model_link AS link ON link.model_plan_id = qIDs.model_plan_id AND link.field_name = qIDs.field_name; diff --git a/pkg/storage/SQL/existing_model_link/get_names_by_model_plan_id_and_field_name_LOADER.sql b/pkg/storage/SQL/existing_model_link/get_names_by_model_plan_id_and_field_name_LOADER.sql new file mode 100644 index 0000000000..916badcf99 --- /dev/null +++ b/pkg/storage/SQL/existing_model_link/get_names_by_model_plan_id_and_field_name_LOADER.sql @@ -0,0 +1,35 @@ +WITH QUERIED_IDS AS ( + /*Translate the input to a table */ + SELECT + model_plan_id, + field_name + FROM + JSON_TO_RECORDSET(:paramTableJSON) + AS x("model_plan_id" UUID, "field_name" EXISITING_MODEL_LINK_FIELD_TYPE) --noqa +), + +links AS ( + + SELECT + qIDs.model_plan_id, + qIDs.field_name, + CASE + WHEN eml.current_model_plan_id IS NOT NULL THEN plan.model_name + ELSE existing_model.model_name + END AS model_name + + FROM QUERIED_IDS AS qIDs + INNER JOIN existing_model_link AS eml ON eml.model_plan_id = qIDs.model_plan_id AND eml.field_name = qIDs.field_name + LEFT JOIN model_plan AS plan ON plan.id = eml.current_model_plan_id + LEFT JOIN existing_model AS existing_model ON existing_model.id = eml.existing_model_id +), + +ordered_links AS ( + SELECT * FROM links ORDER BY model_name +) + +SELECT + model_plan_id, + field_name, + ARRAY_AGG(model_name) AS name_array +FROM ordered_links GROUP BY model_plan_id, field_name diff --git a/pkg/storage/SQL/existing_model_link/merge.sql b/pkg/storage/SQL/existing_model_link/merge.sql index 7cc4599303..fad984dfe1 100644 --- a/pkg/storage/SQL/existing_model_link/merge.sql +++ b/pkg/storage/SQL/existing_model_link/merge.sql @@ -14,7 +14,7 @@ WITH links AS ( existing_model_links AS ( SELECT * FROM existing_model_link - WHERE model_plan_id = :model_plan_id + WHERE model_plan_id = :model_plan_id AND field_name = :field_name ), /* Find the links that already exist */ @@ -28,8 +28,8 @@ matchedLinks AS ( ELSE FALSE END AS dontInsert FROM links - LEFT JOIN existing_model_link AS cml ON ( cml.model_plan_id = :model_plan_id AND links.current_model_plan_id = cml.current_model_plan_id) - LEFT JOIN existing_model_link AS eml ON ( eml.model_plan_id = :model_plan_id AND links.existing_model_id = eml.existing_model_id) + LEFT JOIN existing_model_link AS cml ON ( cml.model_plan_id = :model_plan_id AND cml.field_name = :field_name AND links.current_model_plan_id = cml.current_model_plan_id) + LEFT JOIN existing_model_link AS eml ON ( eml.model_plan_id = :model_plan_id AND eml.field_name = :field_name AND links.existing_model_id = eml.existing_model_id) ), /* Find the links not matched by source (EG ok to delete) */ @@ -48,10 +48,11 @@ existingToDelete AS ( /* insert new records as needed */ inserted AS ( - INSERT INTO existing_model_link(id, model_plan_id, existing_model_id, current_model_plan_id, created_by) + INSERT INTO existing_model_link(id, model_plan_id, field_name, existing_model_id, current_model_plan_id, created_by) SELECT gen_random_uuid() AS id, --Use the actual id, not gen random id here :model_plan_id AS model_plan_id, + :field_name AS field_name, matchedLinks.existing_model_id, matchedLinks.current_model_plan_id, :created_by AS created_by @@ -63,6 +64,7 @@ id, model_plan_id, existing_model_id, current_model_plan_id, +field_name, created_by, created_dts, modified_by, @@ -79,18 +81,20 @@ deletedRows AS ( model_plan_id, existing_model_id, current_model_plan_id, + field_name, created_by, created_dts, modified_by, modified_dts ) -/* return all links */ +/* return all inserted and existing links */ SELECT eml.id, eml.model_plan_id, eml.existing_model_id, eml.current_model_plan_id, + eml.field_name, eml.created_by, eml.created_dts, eml.modified_by, @@ -105,6 +109,7 @@ SELECT inserted.model_plan_id, inserted.existing_model_id, inserted.current_model_plan_id, + inserted.field_name, inserted.created_by, inserted.created_dts, inserted.modified_by, diff --git a/pkg/storage/existing_model_linkStore.go b/pkg/storage/existing_model_linkStore.go index 044e58b9b5..1a8957b55f 100644 --- a/pkg/storage/existing_model_linkStore.go +++ b/pkg/storage/existing_model_linkStore.go @@ -18,18 +18,48 @@ var existingModelLinkMergeSQL string //go:embed SQL/existing_model_link/get_by_id.sql var existingModelLinkGetByIDSQL string -//go:embed SQL/existing_model_link/get_by_model_plan_id_LOADER.sql -var existingModelLinkGetByModelPlanIDLoaderSQL string +//go:embed SQL/existing_model_link/get_by_model_plan_id_and_field_name_LOADER.sql +var existingModelLinkGetByModelPlanIDAndFieldNameLoaderSQL string -// ExistingModelLinkGetByModelPlanIDLOADER returns the plan GeneralCharacteristics for a slice of model plan ids -func (s *Store) ExistingModelLinkGetByModelPlanIDLOADER( +//go:embed SQL/existing_model_link/get_names_by_model_plan_id_and_field_name_LOADER.sql +var existingModelLinkGetNamesByModelPlanIDAndFieldNameSQL string + +// GetExistingModelLinkNamesByModelPlanIDAndFieldNameLOADER returns the plan GeneralCharacteristics for a slice of model plan ids and field Names +func (s *Store) GetExistingModelLinkNamesByModelPlanIDAndFieldNameLOADER( + logger *zap.Logger, + paramTableJSON string, +) ([]*models.ExistingModelLinks, error) { + + var linkSlice []*models.ExistingModelLinks + + stmt, err := s.db.PrepareNamed(existingModelLinkGetNamesByModelPlanIDAndFieldNameSQL) + if err != nil { + return nil, err + } + defer stmt.Close() + + arg := map[string]interface{}{ + "paramTableJSON": paramTableJSON, + } + + err = stmt.Select(&linkSlice, arg) //this returns more than one + if err != nil { + logger.Error("failed to get names of all model links by modelPlanID and field name", zap.Error(err)) + return nil, err + } + + return linkSlice, nil +} + +// ExistingModelLinkGetByModelPlanIDAndFieldNameLOADER returns the plan GeneralCharacteristics for a slice of model plan ids +func (s *Store) ExistingModelLinkGetByModelPlanIDAndFieldNameLOADER( logger *zap.Logger, paramTableJSON string, ) ([]*models.ExistingModelLink, error) { var linkSlice []*models.ExistingModelLink - stmt, err := s.db.PrepareNamed(existingModelLinkGetByModelPlanIDLoaderSQL) + stmt, err := s.db.PrepareNamed(existingModelLinkGetByModelPlanIDAndFieldNameLoaderSQL) if err != nil { return nil, err } @@ -53,6 +83,7 @@ func (s *Store) ExistingModelLinksUpdate( logger *zap.Logger, userID uuid.UUID, modelPlanID uuid.UUID, + fieldName models.ExisitingModelLinkFieldType, existingModelIDs []int, currentModelPlanIDs []uuid.UUID, ) ([]*models.ExistingModelLink, error) { @@ -69,6 +100,7 @@ func (s *Store) ExistingModelLinksUpdate( existingModelIDsArray := convertIntToPQStringArray(existingModelIDs) arg := map[string]interface{}{ "model_plan_id": modelPlanID, + "field_name": fieldName, "current_model_plan_ids": currentModelPlanIDsArray, "existing_model_ids": existingModelIDsArray, "created_by": userID, diff --git a/pkg/storage/loaders/data_loaders.go b/pkg/storage/loaders/data_loaders.go index 0ab652142f..90745754b9 100644 --- a/pkg/storage/loaders/data_loaders.go +++ b/pkg/storage/loaders/data_loaders.go @@ -21,6 +21,7 @@ type DataLoaders struct { UserAccountLoader *WrappedDataLoader DataReader *DataReader ExistingModelLinkLoader *WrappedDataLoader + ExistingModelLinkNameLoader *WrappedDataLoader ExistingModelLoader *WrappedDataLoader ModelPlanLoader *WrappedDataLoader @@ -50,7 +51,8 @@ func NewDataLoaders(store *storage.Store) *DataLoaders { loaders.OperationSolutionSubtaskLoader = newWrappedDataLoader(loaders.GetOperationalSolutionSubtaskByModelPlanID) loaders.UserAccountLoader = newWrappedDataLoader(loaders.GetUserAccountsByIDLoader) - loaders.ExistingModelLinkLoader = newWrappedDataLoader(loaders.GetExistingModelLinkByModelPlanID) + loaders.ExistingModelLinkLoader = newWrappedDataLoader(loaders.GetExistingModelLinkByModelPlanIDAndFieldName) + loaders.ExistingModelLinkNameLoader = newWrappedDataLoader(loaders.GetExistingModelLinkNamesByModelPlanIDAndFieldName) loaders.ExistingModelLoader = newWrappedDataLoader(loaders.GetExistingModelByModelPlanID) loaders.ModelPlanLoader = newWrappedDataLoader(loaders.GetModelPlanByModelPlanID) diff --git a/pkg/storage/loaders/existing_model_link_loader.go b/pkg/storage/loaders/existing_model_link_loader.go index 8c40ac1e35..45a60c3b96 100644 --- a/pkg/storage/loaders/existing_model_link_loader.go +++ b/pkg/storage/loaders/existing_model_link_loader.go @@ -11,8 +11,8 @@ import ( "github.com/cmsgov/mint-app/pkg/models" ) -// GetExistingModelLinkByModelPlanID uses a DataLoader to aggreggate a SQL call and return all Existing Model Link in one query -func (loaders *DataLoaders) GetExistingModelLinkByModelPlanID(ctx context.Context, keys dataloader.Keys) []*dataloader.Result { +// GetExistingModelLinkNamesByModelPlanIDAndFieldName uses a DataLoader to aggreggate a SQL call and return all Existing Model Link Names in one query for a given model_plan_id and field_name combination +func (loaders *DataLoaders) GetExistingModelLinkNamesByModelPlanIDAndFieldName(ctx context.Context, keys dataloader.Keys) []*dataloader.Result { dr := loaders.DataReader logger := appcontext.ZLogger(ctx) @@ -25,16 +25,56 @@ func (loaders *DataLoaders) GetExistingModelLinkByModelPlanID(ctx context.Contex logger.Error("issue converting keys to JSON for data loader in Existing Model Link", zap.Error(*err)) } - links, _ := dr.Store.ExistingModelLinkGetByModelPlanIDLOADER(logger, marshaledParams) + links, _ := dr.Store.GetExistingModelLinkNamesByModelPlanIDAndFieldNameLOADER(logger, marshaledParams) + nameArrayByResKey := map[string][]string{} //Only get the names from the links structure + for _, link := range links { + resKey := fmt.Sprint(link.ModelPlanID, link.FieldName) //The key is a compound key, the model_plan_id, and the field name + nameArrayByResKey[resKey] = link.NameArray + } + + // RETURN IN THE SAME ORDER REQUESTED + output := make([]*dataloader.Result, len(keys)) + for index, key := range keys { + ck, ok := key.Raw().(KeyArgs) + if ok { + resKey := fmt.Sprint(ck.Args["model_plan_id"], ck.Args["field_name"]) + links := nameArrayByResKey[resKey] //Any not found will return an empty array + + output[index] = &dataloader.Result{Data: links, Error: nil} + } else { + err := fmt.Errorf("could not retrive key from %s", key.String()) + output[index] = &dataloader.Result{Data: nil, Error: err} + } + } + return output + +} + +// GetExistingModelLinkByModelPlanIDAndFieldName uses a DataLoader to aggreggate a SQL call and return all Existing Model Link in one query for a given model_plan_id and field_name +func (loaders *DataLoaders) GetExistingModelLinkByModelPlanIDAndFieldName(ctx context.Context, keys dataloader.Keys) []*dataloader.Result { + dr := loaders.DataReader + + logger := appcontext.ZLogger(ctx) + arrayCK, err := ConvertToKeyArgsArray(keys) + if err != nil { + logger.Error("issue converting keys for data loader in Existing Model Link", zap.Error(*err)) + } + marshaledParams, err := arrayCK.ToJSONArray() + if err != nil { + logger.Error("issue converting keys to JSON for data loader in Existing Model Link", zap.Error(*err)) + } + + links, _ := dr.Store.ExistingModelLinkGetByModelPlanIDAndFieldNameLOADER(logger, marshaledParams) linksByID := map[string][]*models.ExistingModelLink{} for _, link := range links { - slice, ok := linksByID[string(link.ModelPlanID.String())] + resKey := fmt.Sprint(link.ModelPlanID, link.FieldName) //The key is a compound key, the model_plan_id, and the field name + slice, ok := linksByID[resKey] if ok { slice = append(slice, link) //Add to existing slice - linksByID[string(link.ModelPlanID.String())] = slice + linksByID[resKey] = slice continue } - linksByID[string(link.ModelPlanID.String())] = []*models.ExistingModelLink{link} + linksByID[resKey] = []*models.ExistingModelLink{link} } // RETURN IN THE SAME ORDER REQUESTED @@ -42,7 +82,7 @@ func (loaders *DataLoaders) GetExistingModelLinkByModelPlanID(ctx context.Contex for index, key := range keys { ck, ok := key.Raw().(KeyArgs) if ok { - resKey := fmt.Sprint(ck.Args["model_plan_id"]) + resKey := fmt.Sprint(ck.Args["model_plan_id"], ck.Args["field_name"]) links := linksByID[resKey] //Any not found will return an empty array output[index] = &dataloader.Result{Data: links, Error: nil} diff --git a/src/components/ShareExport/__snapshots__/index.test.tsx.snap b/src/components/ShareExport/__snapshots__/index.test.tsx.snap index 67438c3681..8db36cfa01 100644 --- a/src/components/ShareExport/__snapshots__/index.test.tsx.snap +++ b/src/components/ShareExport/__snapshots__/index.test.tsx.snap @@ -935,12 +935,12 @@ exports[`ShareExportModal > matches the snapshot 1`] = ` data-testid="grid" >
- Which existing models does your proposed track/model most closely resemble? + existingModelLinks.label
matches the snapshot 2`] = ` data-testid="grid" >
- Which existing models does your proposed track/model most closely resemble? + existingModelLinks.label
;
id?: Maybe
- Which existing models does your proposed track/model most closely resemble?
+ existingModelLinks.label
{
return (
- data?.modelPlan?.existingModelLinks?.map(
- link =>
- (link.currentModelPlan?.modelName || link.existingModel?.modelName)!
+ data?.modelPlan?.generalCharacteristics?.resemblesExistingModelWhich?.links?.map(
+ link => link.model.modelName!
) || []
);
- }, [data?.modelPlan?.existingModelLinks]);
+ }, [
+ data?.modelPlan?.generalCharacteristics?.resemblesExistingModelWhich?.links
+ ]);
if ((!loading && error) || (!loading && !data?.modelPlan)) {
return