Skip to content

Commit

Permalink
feat: create program members with program (#300)
Browse files Browse the repository at this point in the history
* feat: create program memmbers with program

Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>

* remove extra return def

Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>

* fix idents

Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>

* generate

Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>

---------

Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
  • Loading branch information
golanglemonade authored and matoszz committed Dec 11, 2024
1 parent da80d0e commit c875487
Show file tree
Hide file tree
Showing 10 changed files with 543 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/ent/interceptors/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func filterType(ctx context.Context) string {
"updateGroupMembership",
"createProgramMembership",
"updateProgramMembership",
"createProgramWithMembers",
"createProgram",
"updateProgram",
"organization",
Expand Down
11 changes: 11 additions & 0 deletions internal/graphapi/gen_models.go

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

234 changes: 234 additions & 0 deletions internal/graphapi/gen_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,7 @@ type ComplexityRoot struct {
CreateProcedure func(childComplexity int, input generated.CreateProcedureInput) int
CreateProgram func(childComplexity int, input generated.CreateProgramInput) int
CreateProgramMembership func(childComplexity int, input generated.CreateProgramMembershipInput) int
CreateProgramWithMembers func(childComplexity int, input CreateProgramWithMembersInput) int
CreateRisk func(childComplexity int, input generated.CreateRiskInput) int
CreateStandard func(childComplexity int, input generated.CreateStandardInput) int
CreateSubcontrol func(childComplexity int, input generated.CreateSubcontrolInput) int
Expand Down Expand Up @@ -4201,6 +4202,7 @@ type MutationResolver interface {
CreateBulkCSVProgram(ctx context.Context, input graphql.Upload) (*ProgramBulkCreatePayload, error)
UpdateProgram(ctx context.Context, id string, input generated.UpdateProgramInput) (*ProgramUpdatePayload, error)
DeleteProgram(ctx context.Context, id string) (*ProgramDeletePayload, error)
CreateProgramWithMembers(ctx context.Context, input CreateProgramWithMembersInput) (*ProgramCreatePayload, error)
CreateProgramMembership(ctx context.Context, input generated.CreateProgramMembershipInput) (*ProgramMembershipCreatePayload, error)
CreateBulkProgramMembership(ctx context.Context, input []*generated.CreateProgramMembershipInput) (*ProgramMembershipBulkCreatePayload, error)
CreateBulkCSVProgramMembership(ctx context.Context, input graphql.Upload) (*ProgramMembershipBulkCreatePayload, error)
Expand Down Expand Up @@ -13558,6 +13560,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in

return e.complexity.Mutation.CreateProgramMembership(childComplexity, args["input"].(generated.CreateProgramMembershipInput)), true

case "Mutation.createProgramWithMembers":
if e.complexity.Mutation.CreateProgramWithMembers == nil {
break
}

args, err := ec.field_Mutation_createProgramWithMembers_args(context.TODO(), rawArgs)
if err != nil {
return 0, false
}

return e.complexity.Mutation.CreateProgramWithMembers(childComplexity, args["input"].(CreateProgramWithMembersInput)), true

case "Mutation.createRisk":
if e.complexity.Mutation.CreateRisk == nil {
break
Expand Down Expand Up @@ -25107,6 +25121,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
ec.unmarshalInputCreateIntegrationInput,
ec.unmarshalInputCreateInternalPolicyInput,
ec.unmarshalInputCreateInviteInput,
ec.unmarshalInputCreateMemberWithProgramInput,
ec.unmarshalInputCreateNarrativeInput,
ec.unmarshalInputCreateNoteInput,
ec.unmarshalInputCreateOauthProviderInput,
Expand All @@ -25119,6 +25134,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
ec.unmarshalInputCreateProcedureInput,
ec.unmarshalInputCreateProgramInput,
ec.unmarshalInputCreateProgramMembershipInput,
ec.unmarshalInputCreateProgramWithMembersInput,
ec.unmarshalInputCreateRiskInput,
ec.unmarshalInputCreateStandardInput,
ec.unmarshalInputCreateSubcontrolInput,
Expand Down Expand Up @@ -62274,6 +62290,28 @@ type ProgramBulkCreatePayload {
extend input ProgramMembershipWhereInput {
programID: String
userID: String
}

input CreateProgramWithMembersInput{
program: CreateProgramInput!
members: [CreateMemberWithProgramInput!]
}

input CreateMemberWithProgramInput {
role: ProgramMembershipRole
userID: ID!
}

extend type Mutation{
"""
Create a new program with members
"""
createProgramWithMembers(
"""
values of the program
"""
input: CreateProgramWithMembersInput!
): ProgramCreatePayload!
}`, BuiltIn: false},
{Name: "../../schema/programmembership.graphql", Input: `extend type Query {
"""
Expand Down Expand Up @@ -67348,6 +67386,38 @@ func (ec *executionContext) field_Mutation_createProgramMembership_argsInput(
return zeroVal, nil
}

func (ec *executionContext) field_Mutation_createProgramWithMembers_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
var err error
args := map[string]interface{}{}
arg0, err := ec.field_Mutation_createProgramWithMembers_argsInput(ctx, rawArgs)
if err != nil {
return nil, err
}
args["input"] = arg0
return args, nil
}
func (ec *executionContext) field_Mutation_createProgramWithMembers_argsInput(
ctx context.Context,
rawArgs map[string]interface{},
) (CreateProgramWithMembersInput, error) {
// We won't call the directive if the argument is null.
// Set call_argument_directives_with_null to true to call directives
// even if the argument is null.
_, ok := rawArgs["input"]
if !ok {
var zeroVal CreateProgramWithMembersInput
return zeroVal, nil
}

ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("input"))
if tmp, ok := rawArgs["input"]; ok {
return ec.unmarshalNCreateProgramWithMembersInput2githubᚗcomᚋtheopenlaneᚋcoreᚋinternalᚋgraphapiᚐCreateProgramWithMembersInput(ctx, tmp)
}

var zeroVal CreateProgramWithMembersInput
return zeroVal, nil
}

func (ec *executionContext) field_Mutation_createProgram_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
var err error
args := map[string]interface{}{}
Expand Down Expand Up @@ -159013,6 +159083,65 @@ func (ec *executionContext) fieldContext_Mutation_deleteProgram(ctx context.Cont
return fc, nil
}

func (ec *executionContext) _Mutation_createProgramWithMembers(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Mutation_createProgramWithMembers(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.Mutation().CreateProgramWithMembers(rctx, fc.Args["input"].(CreateProgramWithMembersInput))
})
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.(*ProgramCreatePayload)
fc.Result = res
return ec.marshalNProgramCreatePayload2ᚖgithubᚗcomᚋtheopenlaneᚋcoreᚋinternalᚋgraphapiᚐProgramCreatePayload(ctx, field.Selections, res)
}

func (ec *executionContext) fieldContext_Mutation_createProgramWithMembers(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "Mutation",
Field: field,
IsMethod: true,
IsResolver: true,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
switch field.Name {
case "program":
return ec.fieldContext_ProgramCreatePayload_program(ctx, field)
}
return nil, fmt.Errorf("no field named %q was found under type ProgramCreatePayload", field.Name)
},
}
defer func() {
if r := recover(); r != nil {
err = ec.Recover(ctx, r)
ec.Error(ctx, err)
}
}()
ctx = graphql.WithFieldContext(ctx, fc)
if fc.Args, err = ec.field_Mutation_createProgramWithMembers_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
ec.Error(ctx, err)
return fc, err
}
return fc, nil
}

func (ec *executionContext) _Mutation_createProgramMembership(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Mutation_createProgramMembership(ctx, field)
if err != nil {
Expand Down Expand Up @@ -259853,6 +259982,40 @@ func (ec *executionContext) unmarshalInputCreateInviteInput(ctx context.Context,
return it, nil
}

func (ec *executionContext) unmarshalInputCreateMemberWithProgramInput(ctx context.Context, obj interface{}) (CreateMemberWithProgramInput, error) {
var it CreateMemberWithProgramInput
asMap := map[string]interface{}{}
for k, v := range obj.(map[string]interface{}) {
asMap[k] = v
}

fieldsInOrder := [...]string{"role", "userID"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
continue
}
switch k {
case "role":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("role"))
data, err := ec.unmarshalOProgramMembershipRole2ᚖgithubᚗcomᚋtheopenlaneᚋcoreᚋpkgᚋenumsᚐRole(ctx, v)
if err != nil {
return it, err
}
it.Role = data
case "userID":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("userID"))
data, err := ec.unmarshalNID2string(ctx, v)
if err != nil {
return it, err
}
it.UserID = data
}
}

return it, nil
}

func (ec *executionContext) unmarshalInputCreateNarrativeInput(ctx context.Context, obj interface{}) (generated.CreateNarrativeInput, error) {
var it generated.CreateNarrativeInput
asMap := map[string]interface{}{}
Expand Down Expand Up @@ -261348,6 +261511,40 @@ func (ec *executionContext) unmarshalInputCreateProgramMembershipInput(ctx conte
return it, nil
}

func (ec *executionContext) unmarshalInputCreateProgramWithMembersInput(ctx context.Context, obj interface{}) (CreateProgramWithMembersInput, error) {
var it CreateProgramWithMembersInput
asMap := map[string]interface{}{}
for k, v := range obj.(map[string]interface{}) {
asMap[k] = v
}

fieldsInOrder := [...]string{"program", "members"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
continue
}
switch k {
case "program":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("program"))
data, err := ec.unmarshalNCreateProgramInput2ᚖgithubᚗcomᚋtheopenlaneᚋcoreᚋinternalᚋentᚋgeneratedᚐCreateProgramInput(ctx, v)
if err != nil {
return it, err
}
it.Program = data
case "members":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("members"))
data, err := ec.unmarshalOCreateMemberWithProgramInput2ᚕᚖgithubᚗcomᚋtheopenlaneᚋcoreᚋinternalᚋgraphapiᚐCreateMemberWithProgramInputᚄ(ctx, v)
if err != nil {
return it, err
}
it.Members = data
}
}

return it, nil
}

func (ec *executionContext) unmarshalInputCreateRiskInput(ctx context.Context, obj interface{}) (generated.CreateRiskInput, error) {
var it generated.CreateRiskInput
asMap := map[string]interface{}{}
Expand Down Expand Up @@ -382877,6 +383074,13 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet)
if out.Values[i] == graphql.Null {
out.Invalids++
}
case "createProgramWithMembers":
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {
return ec._Mutation_createProgramWithMembers(ctx, field)
})
if out.Values[i] == graphql.Null {
out.Invalids++
}
case "createProgramMembership":
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {
return ec._Mutation_createProgramMembership(ctx, field)
Expand Down Expand Up @@ -404514,6 +404718,11 @@ func (ec *executionContext) unmarshalNCreateInviteInput2ᚖgithubᚗcomᚋtheope
return &res, graphql.ErrorOnPath(ctx, err)
}

func (ec *executionContext) unmarshalNCreateMemberWithProgramInput2ᚖgithubᚗcomᚋtheopenlaneᚋcoreᚋinternalᚋgraphapiᚐCreateMemberWithProgramInput(ctx context.Context, v interface{}) (*CreateMemberWithProgramInput, error) {
res, err := ec.unmarshalInputCreateMemberWithProgramInput(ctx, v)
return &res, graphql.ErrorOnPath(ctx, err)
}

func (ec *executionContext) unmarshalNCreateNarrativeInput2githubᚗcomᚋtheopenlaneᚋcoreᚋinternalᚋentᚋgeneratedᚐCreateNarrativeInput(ctx context.Context, v interface{}) (generated.CreateNarrativeInput, error) {
res, err := ec.unmarshalInputCreateNarrativeInput(ctx, v)
return res, graphql.ErrorOnPath(ctx, err)
Expand Down Expand Up @@ -404624,6 +404833,11 @@ func (ec *executionContext) unmarshalNCreateProgramMembershipInput2ᚖgithubᚗc
return &res, graphql.ErrorOnPath(ctx, err)
}

func (ec *executionContext) unmarshalNCreateProgramWithMembersInput2githubᚗcomᚋtheopenlaneᚋcoreᚋinternalᚋgraphapiᚐCreateProgramWithMembersInput(ctx context.Context, v interface{}) (CreateProgramWithMembersInput, error) {
res, err := ec.unmarshalInputCreateProgramWithMembersInput(ctx, v)
return res, graphql.ErrorOnPath(ctx, err)
}

func (ec *executionContext) unmarshalNCreateRiskInput2githubᚗcomᚋtheopenlaneᚋcoreᚋinternalᚋentᚋgeneratedᚐCreateRiskInput(ctx context.Context, v interface{}) (generated.CreateRiskInput, error) {
res, err := ec.unmarshalInputCreateRiskInput(ctx, v)
return res, graphql.ErrorOnPath(ctx, err)
Expand Down Expand Up @@ -412227,6 +412441,26 @@ func (ec *executionContext) unmarshalOCreateInviteInput2ᚕᚖgithubᚗcomᚋthe
return res, nil
}

func (ec *executionContext) unmarshalOCreateMemberWithProgramInput2ᚕᚖgithubᚗcomᚋtheopenlaneᚋcoreᚋinternalᚋgraphapiᚐCreateMemberWithProgramInputᚄ(ctx context.Context, v interface{}) ([]*CreateMemberWithProgramInput, error) {
if v == nil {
return nil, nil
}
var vSlice []interface{}
if v != nil {
vSlice = graphql.CoerceList(v)
}
var err error
res := make([]*CreateMemberWithProgramInput, len(vSlice))
for i := range vSlice {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i))
res[i], err = ec.unmarshalNCreateMemberWithProgramInput2ᚖgithubᚗcomᚋtheopenlaneᚋcoreᚋinternalᚋgraphapiᚐCreateMemberWithProgramInput(ctx, vSlice[i])
if err != nil {
return nil, err
}
}
return res, nil
}

func (ec *executionContext) unmarshalOCreateNarrativeInput2ᚕᚖgithubᚗcomᚋtheopenlaneᚋcoreᚋinternalᚋentᚋgeneratedᚐCreateNarrativeInputᚄ(ctx context.Context, v interface{}) ([]*generated.CreateNarrativeInput, error) {
if v == nil {
return nil, nil
Expand Down
Loading

0 comments on commit c875487

Please sign in to comment.