From e14f1b4264ec5196834db925202d9d9f93ac35c5 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Mon, 30 Jul 2018 01:36:41 +0200 Subject: graphql: move the mutations to a root Mutation type --- graphql/graph/gen_graph.go | 239 +++++++++++++++++++++------------------------ 1 file changed, 111 insertions(+), 128 deletions(-) (limited to 'graphql/graph/gen_graph.go') diff --git a/graphql/graph/gen_graph.go b/graphql/graph/gen_graph.go index 01887dc8..aa4fcc15 100644 --- a/graphql/graph/gen_graph.go +++ b/graphql/graph/gen_graph.go @@ -40,13 +40,13 @@ type Resolvers interface { LabelChangeOperation_date(ctx context.Context, obj *operations.LabelChangeOperation) (time.Time, error) + Mutation_newBug(ctx context.Context, repoRef *string, title string, message string) (bug.Snapshot, error) + Query_defaultRepository(ctx context.Context) (*models.Repository, error) Query_repository(ctx context.Context, id string) (*models.Repository, error) Repository_allBugs(ctx context.Context, obj *models.Repository, input models.ConnectionInput) (models.BugConnection, error) Repository_bug(ctx context.Context, obj *models.Repository, prefix string) (*bug.Snapshot, error) - Repository_mutation(ctx context.Context, obj *models.Repository) (models.RepositoryMutation, error) - RepositoryMutation_newBug(ctx context.Context, obj *models.RepositoryMutation, title string, message string) (bug.Snapshot, error) SetStatusOperation_date(ctx context.Context, obj *operations.SetStatusOperation) (time.Time, error) SetStatusOperation_status(ctx context.Context, obj *operations.SetStatusOperation) (models.Status, error) @@ -59,9 +59,9 @@ type ResolverRoot interface { Bug() BugResolver CreateOperation() CreateOperationResolver LabelChangeOperation() LabelChangeOperationResolver + Mutation() MutationResolver Query() QueryResolver Repository() RepositoryResolver - RepositoryMutation() RepositoryMutationResolver SetStatusOperation() SetStatusOperationResolver SetTitleOperation() SetTitleOperationResolver } @@ -80,6 +80,9 @@ type CreateOperationResolver interface { type LabelChangeOperationResolver interface { Date(ctx context.Context, obj *operations.LabelChangeOperation) (time.Time, error) } +type MutationResolver interface { + NewBug(ctx context.Context, repoRef *string, title string, message string) (bug.Snapshot, error) +} type QueryResolver interface { DefaultRepository(ctx context.Context) (*models.Repository, error) Repository(ctx context.Context, id string) (*models.Repository, error) @@ -87,10 +90,6 @@ type QueryResolver interface { type RepositoryResolver interface { AllBugs(ctx context.Context, obj *models.Repository, input models.ConnectionInput) (models.BugConnection, error) Bug(ctx context.Context, obj *models.Repository, prefix string) (*bug.Snapshot, error) - Mutation(ctx context.Context, obj *models.Repository) (models.RepositoryMutation, error) -} -type RepositoryMutationResolver interface { - NewBug(ctx context.Context, obj *models.RepositoryMutation, title string, message string) (bug.Snapshot, error) } type SetStatusOperationResolver interface { Date(ctx context.Context, obj *operations.SetStatusOperation) (time.Time, error) @@ -128,6 +127,10 @@ func (s shortMapper) LabelChangeOperation_date(ctx context.Context, obj *operati return s.r.LabelChangeOperation().Date(ctx, obj) } +func (s shortMapper) Mutation_newBug(ctx context.Context, repoRef *string, title string, message string) (bug.Snapshot, error) { + return s.r.Mutation().NewBug(ctx, repoRef, title, message) +} + func (s shortMapper) Query_defaultRepository(ctx context.Context) (*models.Repository, error) { return s.r.Query().DefaultRepository(ctx) } @@ -144,14 +147,6 @@ func (s shortMapper) Repository_bug(ctx context.Context, obj *models.Repository, return s.r.Repository().Bug(ctx, obj, prefix) } -func (s shortMapper) Repository_mutation(ctx context.Context, obj *models.Repository) (models.RepositoryMutation, error) { - return s.r.Repository().Mutation(ctx, obj) -} - -func (s shortMapper) RepositoryMutation_newBug(ctx context.Context, obj *models.RepositoryMutation, title string, message string) (bug.Snapshot, error) { - return s.r.RepositoryMutation().NewBug(ctx, obj, title, message) -} - func (s shortMapper) SetStatusOperation_date(ctx context.Context, obj *operations.SetStatusOperation) (time.Time, error) { return s.r.SetStatusOperation().Date(ctx, obj) } @@ -189,7 +184,19 @@ func (e *executableSchema) Query(ctx context.Context, op *query.Operation) *grap } func (e *executableSchema) Mutation(ctx context.Context, op *query.Operation) *graphql.Response { - return graphql.ErrorResponse(ctx, "mutations are not supported") + ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers} + + buf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte { + data := ec._Mutation(ctx, op.Selections) + var buf bytes.Buffer + data.MarshalGQL(&buf) + return buf.Bytes() + }) + + return &graphql.Response{ + Data: buf, + Errors: ec.Errors, + } } func (e *executableSchema) Subscription(ctx context.Context, op *query.Operation) func() *graphql.Response { @@ -962,6 +969,90 @@ func (ec *executionContext) _LabelChangeOperation_removed(ctx context.Context, f return arr1 } +var mutationImplementors = []string{"Mutation"} + +// nolint: gocyclo, errcheck, gas, goconst +func (ec *executionContext) _Mutation(ctx context.Context, sel []query.Selection) graphql.Marshaler { + fields := graphql.CollectFields(ec.Doc, sel, mutationImplementors, ec.Variables) + + ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ + Object: "Mutation", + }) + + out := graphql.NewOrderedMap(len(fields)) + for i, field := range fields { + out.Keys[i] = field.Alias + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Mutation") + case "newBug": + out.Values[i] = ec._Mutation_newBug(ctx, field) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + + return out +} + +func (ec *executionContext) _Mutation_newBug(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + args := map[string]interface{}{} + var arg0 *string + if tmp, ok := field.Args["repoRef"]; ok { + var err error + var ptr1 string + if tmp != nil { + ptr1, err = graphql.UnmarshalString(tmp) + arg0 = &ptr1 + } + + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + } + args["repoRef"] = arg0 + var arg1 string + if tmp, ok := field.Args["title"]; ok { + var err error + arg1, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + } + args["title"] = arg1 + var arg2 string + if tmp, ok := field.Args["message"]; ok { + var err error + arg2, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + } + args["message"] = arg2 + rctx := graphql.GetResolverContext(ctx) + rctx.Object = "Mutation" + rctx.Args = args + rctx.Field = field + rctx.PushField(field.Alias) + defer rctx.Pop() + resTmp, err := ec.ResolverMiddleware(ctx, func(ctx context.Context) (interface{}, error) { + return ec.resolvers.Mutation_newBug(ctx, args["repoRef"].(*string), args["title"].(string), args["message"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(bug.Snapshot) + return ec._Bug(ctx, field.Selections, &res) +} + var operationConnectionImplementors = []string{"OperationConnection"} // nolint: gocyclo, errcheck, gas, goconst @@ -1338,8 +1429,6 @@ func (ec *executionContext) _Repository(ctx context.Context, sel []query.Selecti out.Values[i] = ec._Repository_allBugs(ctx, field, obj) case "bug": out.Values[i] = ec._Repository_bug(ctx, field, obj) - case "mutation": - out.Values[i] = ec._Repository_mutation(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -1433,110 +1522,6 @@ func (ec *executionContext) _Repository_bug(ctx context.Context, field graphql.C }) } -func (ec *executionContext) _Repository_mutation(ctx context.Context, field graphql.CollectedField, obj *models.Repository) graphql.Marshaler { - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "Repository", - Args: nil, - Field: field, - }) - return graphql.Defer(func() (ret graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - userErr := ec.Recover(ctx, r) - ec.Error(ctx, userErr) - ret = graphql.Null - } - }() - - resTmp, err := ec.ResolverMiddleware(ctx, func(ctx context.Context) (interface{}, error) { - return ec.resolvers.Repository_mutation(ctx, obj) - }) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - if resTmp == nil { - return graphql.Null - } - res := resTmp.(models.RepositoryMutation) - return ec._RepositoryMutation(ctx, field.Selections, &res) - }) -} - -var repositoryMutationImplementors = []string{"RepositoryMutation"} - -// nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _RepositoryMutation(ctx context.Context, sel []query.Selection, obj *models.RepositoryMutation) graphql.Marshaler { - fields := graphql.CollectFields(ec.Doc, sel, repositoryMutationImplementors, ec.Variables) - - out := graphql.NewOrderedMap(len(fields)) - for i, field := range fields { - out.Keys[i] = field.Alias - - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("RepositoryMutation") - case "newBug": - out.Values[i] = ec._RepositoryMutation_newBug(ctx, field, obj) - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - - return out -} - -func (ec *executionContext) _RepositoryMutation_newBug(ctx context.Context, field graphql.CollectedField, obj *models.RepositoryMutation) graphql.Marshaler { - args := map[string]interface{}{} - var arg0 string - if tmp, ok := field.Args["title"]; ok { - var err error - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - } - args["title"] = arg0 - var arg1 string - if tmp, ok := field.Args["message"]; ok { - var err error - arg1, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - } - args["message"] = arg1 - ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{ - Object: "RepositoryMutation", - Args: args, - Field: field, - }) - return graphql.Defer(func() (ret graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - userErr := ec.Recover(ctx, r) - ec.Error(ctx, userErr) - ret = graphql.Null - } - }() - - resTmp, err := ec.ResolverMiddleware(ctx, func(ctx context.Context) (interface{}, error) { - return ec.resolvers.RepositoryMutation_newBug(ctx, obj, args["title"].(string), args["message"].(string)) - }) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - if resTmp == nil { - return graphql.Null - } - res := resTmp.(bug.Snapshot) - return ec._Bug(ctx, field.Selections, &res) - }) -} - var setStatusOperationImplementors = []string{"SetStatusOperation", "Operation", "Authored"} // nolint: gocyclo, errcheck, gas, goconst @@ -2702,8 +2687,6 @@ type Bug { type Repository { allBugs(input: ConnectionInput!): BugConnection! bug(prefix: String!): Bug - - mutation: RepositoryMutation! } type Query { @@ -2711,7 +2694,7 @@ type Query { repository(id: String!): Repository } - -type RepositoryMutation { - newBug(title: String!, message: String!): Bug! -}`) +type Mutation { + newBug(repoRef: String, title: String!, message: String!): Bug! +} +`) -- cgit