diff options
author | Michael Muré <batolettre@gmail.com> | 2022-08-23 15:01:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-23 15:01:36 +0200 |
commit | 5a70e8b3a2e0fe3d1a1dcd4c24bb6bf64633cb7f (patch) | |
tree | e5382a09a45098672b6d60397eac201617fdd6ec /api | |
parent | 81fd7a5d8b6443e65c861f00a7387c0a3c926c66 (diff) | |
parent | 6ed4b8b7a1185ad278eb2e40b32e859f828233d9 (diff) | |
download | git-bug-5a70e8b3a2e0fe3d1a1dcd4c24bb6bf64633cb7f.tar.gz |
Merge pull request #664 from MichaelMure/combined-id-rework
bug: have a type for combined ids, fix #653
Diffstat (limited to 'api')
25 files changed, 302 insertions, 367 deletions
diff --git a/api/graphql/gen_graphql.go b/api/graphql/gen_graphql.go deleted file mode 100644 index 19c5f1e3..00000000 --- a/api/graphql/gen_graphql.go +++ /dev/null @@ -1,33 +0,0 @@ -//go:build ignore - -package main - -import ( - "fmt" - "io/ioutil" - "log" - "os" - - "github.com/99designs/gqlgen/api" - "github.com/99designs/gqlgen/codegen/config" - "github.com/pkg/errors" -) - -func main() { - fmt.Println("Generating graphql code ...") - - log.SetOutput(ioutil.Discard) - - cfg, err := config.LoadConfigFromDefaultLocations() - if os.IsNotExist(errors.Cause(err)) { - cfg = config.DefaultConfig() - } else if err != nil { - _, _ = fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(2) - } - - if err = api.Generate(cfg); err != nil { - _, _ = fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(3) - } -} diff --git a/api/graphql/gqlgen.yml b/api/graphql/gqlgen.yml index fbb46db6..98d31a5c 100644 --- a/api/graphql/gqlgen.yml +++ b/api/graphql/gqlgen.yml @@ -6,17 +6,18 @@ exec: model: filename: models/gen_models.go -skip_mod_tidy: true - autobind: - "github.com/MichaelMure/git-bug/api/graphql/models" - "github.com/MichaelMure/git-bug/repository" + - "github.com/MichaelMure/git-bug/entity" - "github.com/MichaelMure/git-bug/entity/dag" - "github.com/MichaelMure/git-bug/entities/common" - "github.com/MichaelMure/git-bug/entities/bug" - "github.com/MichaelMure/git-bug/entities/identity" models: + ID: + model: github.com/MichaelMure/git-bug/entity.Id Bug: model: github.com/MichaelMure/git-bug/api/graphql/models.BugWrapper Color: diff --git a/api/graphql/graph/bug.generated.go b/api/graphql/graph/bug.generated.go index 67af1933..ab9c6c34 100644 --- a/api/graphql/graph/bug.generated.go +++ b/api/graphql/graph/bug.generated.go @@ -15,6 +15,7 @@ import ( "github.com/MichaelMure/git-bug/api/graphql/models" "github.com/MichaelMure/git-bug/entities/bug" "github.com/MichaelMure/git-bug/entities/common" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/repository" "github.com/vektah/gqlparser/v2/ast" ) @@ -22,7 +23,6 @@ import ( // region ************************** generated!.gotpl ************************** type BugResolver interface { - ID(ctx context.Context, obj models.BugWrapper) (string, error) HumanID(ctx context.Context, obj models.BugWrapper) (string, error) Actors(ctx context.Context, obj models.BugWrapper, after *string, before *string, first *int, last *int) (*models.IdentityConnection, error) @@ -32,6 +32,7 @@ type BugResolver interface { Operations(ctx context.Context, obj models.BugWrapper, after *string, before *string, first *int, last *int) (*models.OperationConnection, error) } type CommentResolver interface { + ID(ctx context.Context, obj *bug.Comment) (entity.CombinedId, error) Author(ctx context.Context, obj *bug.Comment) (models.IdentityWrapper, error) } @@ -271,7 +272,7 @@ func (ec *executionContext) _Bug_id(ctx context.Context, field graphql.Collected }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Bug().ID(rctx, obj) + return obj.Id(), nil }) if err != nil { ec.Error(ctx, err) @@ -283,9 +284,9 @@ func (ec *executionContext) _Bug_id(ctx context.Context, field graphql.Collected } return graphql.Null } - res := resTmp.(string) + res := resTmp.(entity.Id) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNID2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐId(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_Bug_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -293,9 +294,9 @@ func (ec *executionContext) fieldContext_Bug_id(ctx context.Context, field graph Object: "Bug", Field: field, IsMethod: true, - IsResolver: true, + IsResolver: false, 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 nil, errors.New("field of type ID does not have child fields") }, } return fc, nil @@ -1294,6 +1295,50 @@ func (ec *executionContext) fieldContext_BugEdge_node(ctx context.Context, field return fc, nil } +func (ec *executionContext) _Comment_id(ctx context.Context, field graphql.CollectedField, obj *bug.Comment) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Comment_id(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.Comment().ID(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.(entity.CombinedId) + fc.Result = res + return ec.marshalNCombinedId2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐCombinedId(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Comment_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Comment", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type CombinedId does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Comment_author(ctx context.Context, field graphql.CollectedField, obj *bug.Comment) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Comment_author(ctx, field) if err != nil { @@ -1533,6 +1578,8 @@ func (ec *executionContext) fieldContext_CommentConnection_nodes(ctx context.Con IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { + case "id": + return ec.fieldContext_Comment_id(ctx, field) case "author": return ec.fieldContext_Comment_author(ctx, field) case "message": @@ -1727,6 +1774,8 @@ func (ec *executionContext) fieldContext_CommentEdge_node(ctx context.Context, f IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { + case "id": + return ec.fieldContext_Comment_id(ctx, field) case "author": return ec.fieldContext_Comment_author(ctx, field) case "message": @@ -1763,25 +1812,12 @@ func (ec *executionContext) _Bug(ctx context.Context, sel ast.SelectionSet, obj case "__typename": out.Values[i] = graphql.MarshalString("Bug") case "id": - field := field - innerFunc := func(ctx context.Context) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._Bug_id(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } - return res - } - - out.Concurrently(i, func() graphql.Marshaler { - return innerFunc(ctx) + out.Values[i] = ec._Bug_id(ctx, field, obj) - }) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&invalids, 1) + } case "humanId": field := field @@ -2049,6 +2085,26 @@ func (ec *executionContext) _Comment(ctx context.Context, sel ast.SelectionSet, switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Comment") + case "id": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Comment_id(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + } + + out.Concurrently(i, func() graphql.Marshaler { + return innerFunc(ctx) + + }) case "author": field := field diff --git a/api/graphql/graph/identity.generated.go b/api/graphql/graph/identity.generated.go index 7fa9b9f0..51aa188b 100644 --- a/api/graphql/graph/identity.generated.go +++ b/api/graphql/graph/identity.generated.go @@ -12,13 +12,13 @@ import ( "github.com/99designs/gqlgen/graphql" "github.com/MichaelMure/git-bug/api/graphql/models" + "github.com/MichaelMure/git-bug/entity" "github.com/vektah/gqlparser/v2/ast" ) // region ************************** generated!.gotpl ************************** type IdentityResolver interface { - ID(ctx context.Context, obj models.IdentityWrapper) (string, error) HumanID(ctx context.Context, obj models.IdentityWrapper) (string, error) } @@ -48,7 +48,7 @@ func (ec *executionContext) _Identity_id(ctx context.Context, field graphql.Coll }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Identity().ID(rctx, obj) + return obj.Id(), nil }) if err != nil { ec.Error(ctx, err) @@ -60,9 +60,9 @@ func (ec *executionContext) _Identity_id(ctx context.Context, field graphql.Coll } return graphql.Null } - res := resTmp.(string) + res := resTmp.(entity.Id) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNID2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐId(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_Identity_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -70,9 +70,9 @@ func (ec *executionContext) fieldContext_Identity_id(ctx context.Context, field Object: "Identity", Field: field, IsMethod: true, - IsResolver: true, + IsResolver: false, 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 nil, errors.New("field of type ID does not have child fields") }, } return fc, nil @@ -713,25 +713,12 @@ func (ec *executionContext) _Identity(ctx context.Context, sel ast.SelectionSet, case "__typename": out.Values[i] = graphql.MarshalString("Identity") case "id": - field := field - - innerFunc := func(ctx context.Context) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._Identity_id(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } - return res - } - out.Concurrently(i, func() graphql.Marshaler { - return innerFunc(ctx) + out.Values[i] = ec._Identity_id(ctx, field, obj) - }) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&invalids, 1) + } case "humanId": field := field diff --git a/api/graphql/graph/mutations.generated.go b/api/graphql/graph/mutations.generated.go index 9d5df56e..11604d11 100644 --- a/api/graphql/graph/mutations.generated.go +++ b/api/graphql/graph/mutations.generated.go @@ -2097,7 +2097,7 @@ func (ec *executionContext) unmarshalInputEditCommentInput(ctx context.Context, asMap[k] = v } - fieldsInOrder := [...]string{"clientMutationId", "repoRef", "prefix", "target", "message", "files"} + fieldsInOrder := [...]string{"clientMutationId", "repoRef", "targetPrefix", "message", "files"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -2120,19 +2120,11 @@ func (ec *executionContext) unmarshalInputEditCommentInput(ctx context.Context, if err != nil { return it, err } - case "prefix": - var err error - - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("prefix")) - it.Prefix, err = ec.unmarshalNString2string(ctx, v) - if err != nil { - return it, err - } - case "target": + case "targetPrefix": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("target")) - it.Target, err = ec.unmarshalNString2string(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("targetPrefix")) + it.TargetPrefix, err = ec.unmarshalNString2string(ctx, v) if err != nil { return it, err } diff --git a/api/graphql/graph/operations.generated.go b/api/graphql/graph/operations.generated.go index 39a216f4..cc3cd9b7 100644 --- a/api/graphql/graph/operations.generated.go +++ b/api/graphql/graph/operations.generated.go @@ -15,6 +15,7 @@ import ( "github.com/MichaelMure/git-bug/api/graphql/models" "github.com/MichaelMure/git-bug/entities/bug" "github.com/MichaelMure/git-bug/entities/common" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" "github.com/MichaelMure/git-bug/repository" "github.com/vektah/gqlparser/v2/ast" @@ -23,33 +24,27 @@ import ( // region ************************** generated!.gotpl ************************** type AddCommentOperationResolver interface { - ID(ctx context.Context, obj *bug.AddCommentOperation) (string, error) Author(ctx context.Context, obj *bug.AddCommentOperation) (models.IdentityWrapper, error) Date(ctx context.Context, obj *bug.AddCommentOperation) (*time.Time, error) } type CreateOperationResolver interface { - ID(ctx context.Context, obj *bug.CreateOperation) (string, error) Author(ctx context.Context, obj *bug.CreateOperation) (models.IdentityWrapper, error) Date(ctx context.Context, obj *bug.CreateOperation) (*time.Time, error) } type EditCommentOperationResolver interface { - ID(ctx context.Context, obj *bug.EditCommentOperation) (string, error) Author(ctx context.Context, obj *bug.EditCommentOperation) (models.IdentityWrapper, error) Date(ctx context.Context, obj *bug.EditCommentOperation) (*time.Time, error) Target(ctx context.Context, obj *bug.EditCommentOperation) (string, error) } type LabelChangeOperationResolver interface { - ID(ctx context.Context, obj *bug.LabelChangeOperation) (string, error) Author(ctx context.Context, obj *bug.LabelChangeOperation) (models.IdentityWrapper, error) Date(ctx context.Context, obj *bug.LabelChangeOperation) (*time.Time, error) } type SetStatusOperationResolver interface { - ID(ctx context.Context, obj *bug.SetStatusOperation) (string, error) Author(ctx context.Context, obj *bug.SetStatusOperation) (models.IdentityWrapper, error) Date(ctx context.Context, obj *bug.SetStatusOperation) (*time.Time, error) } type SetTitleOperationResolver interface { - ID(ctx context.Context, obj *bug.SetTitleOperation) (string, error) Author(ctx context.Context, obj *bug.SetTitleOperation) (models.IdentityWrapper, error) Date(ctx context.Context, obj *bug.SetTitleOperation) (*time.Time, error) } @@ -80,7 +75,7 @@ func (ec *executionContext) _AddCommentOperation_id(ctx context.Context, field g }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.AddCommentOperation().ID(rctx, obj) + return obj.Id(), nil }) if err != nil { ec.Error(ctx, err) @@ -92,9 +87,9 @@ func (ec *executionContext) _AddCommentOperation_id(ctx context.Context, field g } return graphql.Null } - res := resTmp.(string) + res := resTmp.(entity.Id) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNID2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐId(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_AddCommentOperation_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -102,9 +97,9 @@ func (ec *executionContext) fieldContext_AddCommentOperation_id(ctx context.Cont Object: "AddCommentOperation", Field: field, IsMethod: true, - IsResolver: true, + IsResolver: false, 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 nil, errors.New("field of type ID does not have child fields") }, } return fc, nil @@ -318,7 +313,7 @@ func (ec *executionContext) _CreateOperation_id(ctx context.Context, field graph }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.CreateOperation().ID(rctx, obj) + return obj.Id(), nil }) if err != nil { ec.Error(ctx, err) @@ -330,9 +325,9 @@ func (ec *executionContext) _CreateOperation_id(ctx context.Context, field graph } return graphql.Null } - res := resTmp.(string) + res := resTmp.(entity.Id) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNID2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐId(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_CreateOperation_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -340,9 +335,9 @@ func (ec *executionContext) fieldContext_CreateOperation_id(ctx context.Context, Object: "CreateOperation", Field: field, IsMethod: true, - IsResolver: true, + IsResolver: false, 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 nil, errors.New("field of type ID does not have child fields") }, } return fc, nil @@ -600,7 +595,7 @@ func (ec *executionContext) _EditCommentOperation_id(ctx context.Context, field }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.EditCommentOperation().ID(rctx, obj) + return obj.Id(), nil }) if err != nil { ec.Error(ctx, err) @@ -612,9 +607,9 @@ func (ec *executionContext) _EditCommentOperation_id(ctx context.Context, field } return graphql.Null } - res := resTmp.(string) + res := resTmp.(entity.Id) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNID2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐId(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_EditCommentOperation_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -622,9 +617,9 @@ func (ec *executionContext) fieldContext_EditCommentOperation_id(ctx context.Con Object: "EditCommentOperation", Field: field, IsMethod: true, - IsResolver: true, + IsResolver: false, 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 nil, errors.New("field of type ID does not have child fields") }, } return fc, nil @@ -882,7 +877,7 @@ func (ec *executionContext) _LabelChangeOperation_id(ctx context.Context, field }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.LabelChangeOperation().ID(rctx, obj) + return obj.Id(), nil }) if err != nil { ec.Error(ctx, err) @@ -894,9 +889,9 @@ func (ec *executionContext) _LabelChangeOperation_id(ctx context.Context, field } return graphql.Null } - res := resTmp.(string) + res := resTmp.(entity.Id) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNID2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐId(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_LabelChangeOperation_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -904,9 +899,9 @@ func (ec *executionContext) fieldContext_LabelChangeOperation_id(ctx context.Con Object: "LabelChangeOperation", Field: field, IsMethod: true, - IsResolver: true, + IsResolver: false, 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 nil, errors.New("field of type ID does not have child fields") }, } return fc, nil @@ -1412,7 +1407,7 @@ func (ec *executionContext) _SetStatusOperation_id(ctx context.Context, field gr }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.SetStatusOperation().ID(rctx, obj) + return obj.Id(), nil }) if err != nil { ec.Error(ctx, err) @@ -1424,9 +1419,9 @@ func (ec *executionContext) _SetStatusOperation_id(ctx context.Context, field gr } return graphql.Null } - res := resTmp.(string) + res := resTmp.(entity.Id) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNID2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐId(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_SetStatusOperation_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -1434,9 +1429,9 @@ func (ec *executionContext) fieldContext_SetStatusOperation_id(ctx context.Conte Object: "SetStatusOperation", Field: field, IsMethod: true, - IsResolver: true, + IsResolver: false, 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 nil, errors.New("field of type ID does not have child fields") }, } return fc, nil @@ -1606,7 +1601,7 @@ func (ec *executionContext) _SetTitleOperation_id(ctx context.Context, field gra }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.SetTitleOperation().ID(rctx, obj) + return obj.Id(), nil }) if err != nil { ec.Error(ctx, err) @@ -1618,9 +1613,9 @@ func (ec *executionContext) _SetTitleOperation_id(ctx context.Context, field gra } return graphql.Null } - res := resTmp.(string) + res := resTmp.(entity.Id) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNID2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐId(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_SetTitleOperation_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -1628,9 +1623,9 @@ func (ec *executionContext) fieldContext_SetTitleOperation_id(ctx context.Contex Object: "SetTitleOperation", Field: field, IsMethod: true, - IsResolver: true, + IsResolver: false, 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 nil, errors.New("field of type ID does not have child fields") }, } return fc, nil @@ -1892,25 +1887,12 @@ func (ec *executionContext) _AddCommentOperation(ctx context.Context, sel ast.Se case "__typename": out.Values[i] = graphql.MarshalString("AddCommentOperation") case "id": - field := field - - innerFunc := func(ctx context.Context) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._AddCommentOperation_id(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } - return res - } - out.Concurrently(i, func() graphql.Marshaler { - return innerFunc(ctx) + out.Values[i] = ec._AddCommentOperation_id(ctx, field, obj) - }) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&invalids, 1) + } case "author": field := field @@ -1987,25 +1969,12 @@ func (ec *executionContext) _CreateOperation(ctx context.Context, sel ast.Select case "__typename": out.Values[i] = graphql.MarshalString("CreateOperation") case "id": - field := field - - innerFunc := func(ctx context.Context) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._CreateOperation_id(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } - return res - } - out.Concurrently(i, func() graphql.Marshaler { - return innerFunc(ctx) + out.Values[i] = ec._CreateOperation_id(ctx, field, obj) - }) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&invalids, 1) + } case "author": field := field @@ -2089,25 +2058,12 @@ func (ec *executionContext) _EditCommentOperation(ctx context.Context, sel ast.S case "__typename": out.Values[i] = graphql.MarshalString("EditCommentOperation") case "id": - field := field - - innerFunc := func(ctx context.Context) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._EditCommentOperation_id(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } - return res - } - out.Concurrently(i, func() graphql.Marshaler { - return innerFunc(ctx) + out.Values[i] = ec._EditCommentOperation_id(ctx, field, obj) - }) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&invalids, 1) + } case "author": field := field @@ -2204,25 +2160,12 @@ func (ec *executionContext) _LabelChangeOperation(ctx context.Context, sel ast.S case "__typename": out.Values[i] = graphql.MarshalString("LabelChangeOperation") case "id": - field := field - - innerFunc := func(ctx context.Context) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._LabelChangeOperation_id(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } - return res - } - out.Concurrently(i, func() graphql.Marshaler { - return innerFunc(ctx) + out.Values[i] = ec._LabelChangeOperation_id(ctx, field, obj) - }) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&invalids, 1) + } case "author": field := field @@ -2383,25 +2326,12 @@ func (ec *executionContext) _SetStatusOperation(ctx context.Context, sel ast.Sel case "__typename": out.Values[i] = graphql.MarshalString("SetStatusOperation") case "id": - field := field - - innerFunc := func(ctx context.Context) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._SetStatusOperation_id(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } - return res - } - out.Concurrently(i, func() graphql.Marshaler { - return innerFunc(ctx) + out.Values[i] = ec._SetStatusOperation_id(ctx, field, obj) - }) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&invalids, 1) + } case "author": field := field @@ -2471,25 +2401,12 @@ func (ec *executionContext) _SetTitleOperation(ctx context.Context, sel ast.Sele case "__typename": out.Values[i] = graphql.MarshalString("SetTitleOperation") case "id": - field := field - innerFunc := func(ctx context.Context) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._SetTitleOperation_id(ctx, field, obj) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } - return res - } - - out.Concurrently(i, func() graphql.Marshaler { - return innerFunc(ctx) + out.Values[i] = ec._SetTitleOperation_id(ctx, field, obj) - }) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&invalids, 1) + } case "author": field := field diff --git a/api/graphql/graph/prelude.generated.go b/api/graphql/graph/prelude.generated.go index 81978efa..3767b0cd 100644 --- a/api/graphql/graph/prelude.generated.go +++ b/api/graphql/graph/prelude.generated.go @@ -11,6 +11,7 @@ import ( "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/introspection" + "github.com/MichaelMure/git-bug/entity" "github.com/vektah/gqlparser/v2/ast" ) @@ -2172,6 +2173,16 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se return res } +func (ec *executionContext) unmarshalNID2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐId(ctx context.Context, v interface{}) (entity.Id, error) { + var res entity.Id + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNID2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐId(ctx context.Context, sel ast.SelectionSet, v entity.Id) graphql.Marshaler { + return v +} + func (ec *executionContext) unmarshalNInt2int(ctx context.Context, v interface{}) (int, error) { res, err := graphql.UnmarshalInt(v) return res, graphql.ErrorOnPath(ctx, err) diff --git a/api/graphql/graph/root_.generated.go b/api/graphql/graph/root_.generated.go index 297fc6a2..a1434228 100644 --- a/api/graphql/graph/root_.generated.go +++ b/api/graphql/graph/root_.generated.go @@ -74,7 +74,7 @@ type ComplexityRoot struct { Author func(childComplexity int) int Date func(childComplexity int) int Files func(childComplexity int) int - ID func(childComplexity int) int + Id func(childComplexity int) int Message func(childComplexity int) int } @@ -102,7 +102,7 @@ type ComplexityRoot struct { Comments func(childComplexity int, after *string, before *string, first *int, last *int) int CreatedAt func(childComplexity int) int HumanID func(childComplexity int) int - ID func(childComplexity int) int + Id func(childComplexity int) int Labels func(childComplexity int) int LastEdit func(childComplexity int) int Operations func(childComplexity int, after *string, before *string, first *int, last *int) int @@ -146,6 +146,7 @@ type ComplexityRoot struct { Comment struct { Author func(childComplexity int) int Files func(childComplexity int) int + ID func(childComplexity int) int Message func(childComplexity int) int } @@ -170,7 +171,7 @@ type ComplexityRoot struct { Author func(childComplexity int) int Date func(childComplexity int) int Files func(childComplexity int) int - ID func(childComplexity int) int + Id func(childComplexity int) int Message func(childComplexity int) int Title func(childComplexity int) int } @@ -191,7 +192,7 @@ type ComplexityRoot struct { Author func(childComplexity int) int Date func(childComplexity int) int Files func(childComplexity int) int - ID func(childComplexity int) int + Id func(childComplexity int) int Message func(childComplexity int) int Target func(childComplexity int) int } @@ -207,7 +208,7 @@ type ComplexityRoot struct { DisplayName func(childComplexity int) int Email func(childComplexity int) int HumanID func(childComplexity int) int - ID func(childComplexity int) int + Id func(childComplexity int) int IsProtected func(childComplexity int) int Login func(childComplexity int) int Name func(childComplexity int) int @@ -234,7 +235,7 @@ type ComplexityRoot struct { Added func(childComplexity int) int Author func(childComplexity int) int Date func(childComplexity int) int - ID func(childComplexity int) int + Id func(childComplexity int) int Removed func(childComplexity int) int } @@ -323,7 +324,7 @@ type ComplexityRoot struct { SetStatusOperation struct { Author func(childComplexity int) int Date func(childComplexity int) int - ID func(childComplexity int) int + Id func(childComplexity int) int Status func(childComplexity int) int } @@ -337,7 +338,7 @@ type ComplexityRoot struct { SetTitleOperation struct { Author func(childComplexity int) int Date func(childComplexity int) int - ID func(childComplexity int) int + Id func(childComplexity int) int Title func(childComplexity int) int Was func(childComplexity int) int } @@ -462,11 +463,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.AddCommentOperation.Files(childComplexity), true case "AddCommentOperation.id": - if e.complexity.AddCommentOperation.ID == nil { + if e.complexity.AddCommentOperation.Id == nil { break } - return e.complexity.AddCommentOperation.ID(childComplexity), true + return e.complexity.AddCommentOperation.Id(childComplexity), true case "AddCommentOperation.message": if e.complexity.AddCommentOperation.Message == nil { @@ -605,11 +606,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Bug.HumanID(childComplexity), true case "Bug.id": - if e.complexity.Bug.ID == nil { + if e.complexity.Bug.Id == nil { break } - return e.complexity.Bug.ID(childComplexity), true + return e.complexity.Bug.Id(childComplexity), true case "Bug.labels": if e.complexity.Bug.Labels == nil { @@ -801,6 +802,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Comment.Files(childComplexity), true + case "Comment.id": + if e.complexity.Comment.ID == nil { + break + } + + return e.complexity.Comment.ID(childComplexity), true + case "Comment.message": if e.complexity.Comment.Message == nil { break @@ -886,11 +894,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.CreateOperation.Files(childComplexity), true case "CreateOperation.id": - if e.complexity.CreateOperation.ID == nil { + if e.complexity.CreateOperation.Id == nil { break } - return e.complexity.CreateOperation.ID(childComplexity), true + return e.complexity.CreateOperation.Id(childComplexity), true case "CreateOperation.message": if e.complexity.CreateOperation.Message == nil { @@ -991,11 +999,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.EditCommentOperation.Files(childComplexity), true case "EditCommentOperation.id": - if e.complexity.EditCommentOperation.ID == nil { + if e.complexity.EditCommentOperation.Id == nil { break } - return e.complexity.EditCommentOperation.ID(childComplexity), true + return e.complexity.EditCommentOperation.Id(childComplexity), true case "EditCommentOperation.message": if e.complexity.EditCommentOperation.Message == nil { @@ -1061,11 +1069,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Identity.HumanID(childComplexity), true case "Identity.id": - if e.complexity.Identity.ID == nil { + if e.complexity.Identity.Id == nil { break } - return e.complexity.Identity.ID(childComplexity), true + return e.complexity.Identity.Id(childComplexity), true case "Identity.isProtected": if e.complexity.Identity.IsProtected == nil { @@ -1166,11 +1174,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.LabelChangeOperation.Date(childComplexity), true case "LabelChangeOperation.id": - if e.complexity.LabelChangeOperation.ID == nil { + if e.complexity.LabelChangeOperation.Id == nil { break } - return e.complexity.LabelChangeOperation.ID(childComplexity), true + return e.complexity.LabelChangeOperation.Id(childComplexity), true case "LabelChangeOperation.removed": if e.complexity.LabelChangeOperation.Removed == nil { @@ -1591,11 +1599,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.SetStatusOperation.Date(childComplexity), true case "SetStatusOperation.id": - if e.complexity.SetStatusOperation.ID == nil { + if e.complexity.SetStatusOperation.Id == nil { break } - return e.complexity.SetStatusOperation.ID(childComplexity), true + return e.complexity.SetStatusOperation.Id(childComplexity), true case "SetStatusOperation.status": if e.complexity.SetStatusOperation.Status == nil { @@ -1647,11 +1655,11 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.SetTitleOperation.Date(childComplexity), true case "SetTitleOperation.id": - if e.complexity.SetTitleOperation.ID == nil { + if e.complexity.SetTitleOperation.Id == nil { break } - return e.complexity.SetTitleOperation.ID(childComplexity), true + return e.complexity.SetTitleOperation.Id(childComplexity), true case "SetTitleOperation.title": if e.complexity.SetTitleOperation.Title == nil { @@ -1844,6 +1852,8 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er var sources = []*ast.Source{ {Name: "../schema/bug.graphql", Input: `"""Represents a comment on a bug.""" type Comment implements Authored { + id: CombinedId! + """The author of this comment.""" author: Identity! @@ -1873,7 +1883,7 @@ enum Status { type Bug implements Authored { """The identifier for this bug""" - id: String! + id: ID! """The human version (truncated) identifier for this bug""" humanId: String! status: Status! @@ -1964,7 +1974,7 @@ type BugEdge { {Name: "../schema/identity.graphql", Input: `"""Represents an identity""" type Identity { """The identifier for this identity""" - id: String! + id: ID! """The human version (truncated) identifier for this identity""" humanId: String! """The name of the person, if known.""" @@ -2109,10 +2119,8 @@ input EditCommentInput { clientMutationId: String """The name of the repository. If not set, the default repository is used.""" repoRef: String - """The bug ID's prefix.""" - prefix: String! - """The ID of the comment to be changed.""" - target: String! + """A prefix of the CombinedId of the comment to be changed.""" + targetPrefix: String! """The new message to be set.""" message: String! """The collection of file's hash required for the first message.""" @@ -2226,7 +2234,7 @@ type SetTitlePayload { {Name: "../schema/operations.graphql", Input: `"""An operation applied to a bug.""" interface Operation { """The identifier of the operation""" - id: String! + id: ID! """The operations author.""" author: Identity! """The datetime when this operation was issued.""" @@ -2253,7 +2261,7 @@ type OperationEdge { type CreateOperation implements Operation & Authored { """The identifier of the operation""" - id: String! + id: ID! """The author of this object.""" author: Identity! """The datetime when this operation was issued.""" @@ -2266,7 +2274,7 @@ type CreateOperation implements Operation & Authored { type SetTitleOperation implements Operation & Authored { """The identifier of the operation""" - id: String! + id: ID! """The author of this object.""" author: Identity! """The datetime when this operation was issued.""" @@ -2278,7 +2286,7 @@ type SetTitleOperation implements Operation & Authored { type AddCommentOperation implements Operation & Authored { """The identifier of the operation""" - id: String! + id: ID! """The author of this object.""" author: Identity! """The datetime when this operation was issued.""" @@ -2290,7 +2298,7 @@ type AddCommentOperation implements Operation & Authored { type EditCommentOperation implements Operation & Authored { """The identifier of the operation""" - id: String! + id: ID! """The author of this object.""" author: Identity! """The datetime when this operation was issued.""" @@ -2303,7 +2311,7 @@ type EditCommentOperation implements Operation & Authored { type SetStatusOperation implements Operation & Authored { """The identifier of the operation""" - id: String! + id: ID! """The author of this object.""" author: Identity! """The datetime when this operation was issued.""" @@ -2314,7 +2322,7 @@ type SetStatusOperation implements Operation & Authored { type LabelChangeOperation implements Operation & Authored { """The identifier of the operation""" - id: String! + id: ID! """The author of this object.""" author: Identity! """The datetime when this operation was issued.""" @@ -2404,7 +2412,7 @@ type Mutation { {Name: "../schema/timeline.graphql", Input: `"""An item in the timeline of events""" interface TimelineItem { """The identifier of the source operation""" - id: String! + id: CombinedId! } """CommentHistoryStep hold one version of a message in the history""" @@ -2434,7 +2442,7 @@ type TimelineItemEdge { """CreateTimelineItem is a TimelineItem that represent the creation of a bug and its message edition history""" type CreateTimelineItem implements TimelineItem & Authored { """The identifier of the source operation""" - id: String! + id: CombinedId! author: Identity! message: String! messageIsEmpty: Boolean! @@ -2448,7 +2456,7 @@ type CreateTimelineItem implements TimelineItem & Authored { """AddCommentTimelineItem is a TimelineItem that represent a Comment and its edition history""" type AddCommentTimelineItem implements TimelineItem & Authored { """The identifier of the source operation""" - id: String! + id: CombinedId! author: Identity! message: String! messageIsEmpty: Boolean! @@ -2462,7 +2470,7 @@ type AddCommentTimelineItem implements TimelineItem & Authored { """LabelChangeTimelineItem is a TimelineItem that represent a change in the labels of a bug""" type LabelChangeTimelineItem implements TimelineItem & Authored { """The identifier of the source operation""" - id: String! + id: CombinedId! author: Identity! date: Time! added: [Label!]! @@ -2472,7 +2480,7 @@ type LabelChangeTimelineItem implements TimelineItem & Authored { """SetStatusTimelineItem is a TimelineItem that represent a change in the status of a bug""" type SetStatusTimelineItem implements TimelineItem & Authored { """The identifier of the source operation""" - id: String! + id: CombinedId! author: Identity! date: Time! status: Status! @@ -2481,14 +2489,15 @@ type SetStatusTimelineItem implements TimelineItem & Authored { """LabelChangeTimelineItem is a TimelineItem that represent a change in the title of a bug""" type SetTitleTimelineItem implements TimelineItem & Authored { """The identifier of the source operation""" - id: String! + id: CombinedId! author: Identity! date: Time! title: String! was: String! } `, BuiltIn: false}, - {Name: "../schema/types.graphql", Input: `scalar Time + {Name: "../schema/types.graphql", Input: `scalar CombinedId +scalar Time scalar Hash """Defines a color by red, green and blue components.""" diff --git a/api/graphql/graph/timeline.generated.go b/api/graphql/graph/timeline.generated.go index 9ad32e0b..4833e274 100644 --- a/api/graphql/graph/timeline.generated.go +++ b/api/graphql/graph/timeline.generated.go @@ -15,6 +15,7 @@ import ( "github.com/MichaelMure/git-bug/api/graphql/models" "github.com/MichaelMure/git-bug/entities/bug" "github.com/MichaelMure/git-bug/entities/common" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/repository" "github.com/vektah/gqlparser/v2/ast" ) @@ -22,7 +23,7 @@ import ( // region ************************** generated!.gotpl ************************** type AddCommentTimelineItemResolver interface { - ID(ctx context.Context, obj *bug.AddCommentTimelineItem) (string, error) + ID(ctx context.Context, obj *bug.AddCommentTimelineItem) (entity.CombinedId, error) Author(ctx context.Context, obj *bug.AddCommentTimelineItem) (models.IdentityWrapper, error) CreatedAt(ctx context.Context, obj *bug.AddCommentTimelineItem) (*time.Time, error) @@ -32,24 +33,24 @@ type CommentHistoryStepResolver interface { Date(ctx context.Context, obj *bug.CommentHistoryStep) (*time.Time, error) } type CreateTimelineItemResolver interface { - ID(ctx context.Context, obj *bug.CreateTimelineItem) (string, error) + ID(ctx context.Context, obj *bug.CreateTimelineItem) (entity.CombinedId, error) Author(ctx context.Context, obj *bug.CreateTimelineItem) (models.IdentityWrapper, error) CreatedAt(ctx context.Context, obj *bug.CreateTimelineItem) (*time.Time, error) LastEdit(ctx context.Context, obj *bug.CreateTimelineItem) (*time.Time, error) } type LabelChangeTimelineItemResolver interface { - ID(ctx context.Context, obj *bug.LabelChangeTimelineItem) (string, error) + ID(ctx context.Context, obj *bug.LabelChangeTimelineItem) (entity.CombinedId, error) Author(ctx context.Context, obj *bug.LabelChangeTimelineItem) (models.IdentityWrapper, error) Date(ctx context.Context, obj *bug.LabelChangeTimelineItem) (*time.Time, error) } type SetStatusTimelineItemResolver interface { - ID(ctx context.Context, obj *bug.SetStatusTimelineItem) (string, error) + ID(ctx context.Context, obj *bug.SetStatusTimelineItem) (entity.CombinedId, error) Author(ctx context.Context, obj *bug.SetStatusTimelineItem) (models.IdentityWrapper, error) Date(ctx context.Context, obj *bug.SetStatusTimelineItem) (*time.Time, error) } type SetTitleTimelineItemResolver interface { - ID(ctx context.Context, obj *bug.SetTitleTimelineItem) (string, error) + ID(ctx context.Context, obj *bug.SetTitleTimelineItem) (entity.CombinedId, error) Author(ctx context.Context, obj *bug.SetTitleTimelineItem) (models.IdentityWrapper, error) Date(ctx context.Context, obj *bug.SetTitleTimelineItem) (*time.Time, error) } @@ -92,9 +93,9 @@ func (ec *executionContext) _AddCommentTimelineItem_id(ctx context.Context, fiel } return graphql.Null } - res := resTmp.(string) + res := resTmp.(entity.CombinedId) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNCombinedId2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐCombinedId(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_AddCommentTimelineItem_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -104,7 +105,7 @@ func (ec *executionContext) fieldContext_AddCommentTimelineItem_id(ctx context.C 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 nil, errors.New("field of type CombinedId does not have child fields") }, } return fc, nil @@ -600,9 +601,9 @@ func (ec *executionContext) _CreateTimelineItem_id(ctx context.Context, field gr } return graphql.Null } - res := resTmp.(string) + res := resTmp.(entity.CombinedId) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNCombinedId2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐCombinedId(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_CreateTimelineItem_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -612,7 +613,7 @@ func (ec *executionContext) fieldContext_CreateTimelineItem_id(ctx context.Conte 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 nil, errors.New("field of type CombinedId does not have child fields") }, } return fc, nil @@ -1020,9 +1021,9 @@ func (ec *executionContext) _LabelChangeTimelineItem_id(ctx context.Context, fie } return graphql.Null } - res := resTmp.(string) + res := resTmp.(entity.CombinedId) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNCombinedId2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐCombinedId(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_LabelChangeTimelineItem_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -1032,7 +1033,7 @@ func (ec *executionContext) fieldContext_LabelChangeTimelineItem_id(ctx context. 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 nil, errors.New("field of type CombinedId does not have child fields") }, } return fc, nil @@ -1270,9 +1271,9 @@ func (ec *executionContext) _SetStatusTimelineItem_id(ctx context.Context, field } return graphql.Null } - res := resTmp.(string) + res := resTmp.(entity.CombinedId) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNCombinedId2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐCombinedId(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_SetStatusTimelineItem_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -1282,7 +1283,7 @@ func (ec *executionContext) fieldContext_SetStatusTimelineItem_id(ctx context.Co 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 nil, errors.New("field of type CombinedId does not have child fields") }, } return fc, nil @@ -1464,9 +1465,9 @@ func (ec *executionContext) _SetTitleTimelineItem_id(ctx context.Context, field } return graphql.Null } - res := resTmp.(string) + res := resTmp.(entity.CombinedId) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNCombinedId2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐCombinedId(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_SetTitleTimelineItem_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -1476,7 +1477,7 @@ func (ec *executionContext) fieldContext_SetTitleTimelineItem_id(ctx context.Con 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 nil, errors.New("field of type CombinedId does not have child fields") }, } return fc, nil diff --git a/api/graphql/graph/types.generated.go b/api/graphql/graph/types.generated.go index 9095c7ac..b75604ab 100644 --- a/api/graphql/graph/types.generated.go +++ b/api/graphql/graph/types.generated.go @@ -14,6 +14,7 @@ import ( "github.com/99designs/gqlgen/graphql" "github.com/MichaelMure/git-bug/api/graphql/models" "github.com/MichaelMure/git-bug/entities/bug" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/repository" "github.com/vektah/gqlparser/v2/ast" ) @@ -410,22 +411,16 @@ func (ec *executionContext) _Authored(ctx context.Context, sel ast.SelectionSet, return graphql.Null } return ec._AddCommentTimelineItem(ctx, sel, obj) - case bug.LabelChangeTimelineItem: - return ec._LabelChangeTimelineItem(ctx, sel, &obj) case *bug.LabelChangeTimelineItem: if obj == nil { return graphql.Null } return ec._LabelChangeTimelineItem(ctx, sel, obj) - case bug.SetStatusTimelineItem: - return ec._SetStatusTimelineItem(ctx, sel, &obj) case *bug.SetStatusTimelineItem: if obj == nil { return graphql.Null } return ec._SetStatusTimelineItem(ctx, sel, obj) - case bug.SetTitleTimelineItem: - return ec._SetTitleTimelineItem(ctx, sel, &obj) case *bug.SetTitleTimelineItem: if obj == nil { return graphql.Null @@ -588,6 +583,16 @@ func (ec *executionContext) marshalNColor2ᚖimageᚋcolorᚐRGBA(ctx context.Co return ec._Color(ctx, sel, v) } +func (ec *executionContext) unmarshalNCombinedId2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐCombinedId(ctx context.Context, v interface{}) (entity.CombinedId, error) { + var res entity.CombinedId + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNCombinedId2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋentityᚐCombinedId(ctx context.Context, sel ast.SelectionSet, v entity.CombinedId) graphql.Marshaler { + return v +} + func (ec *executionContext) unmarshalNHash2githubᚗcomᚋMichaelMureᚋgitᚑbugᚋrepositoryᚐHash(ctx context.Context, v interface{}) (repository.Hash, error) { var res repository.Hash err := res.UnmarshalGQL(v) diff --git a/api/graphql/handler.go b/api/graphql/handler.go index 03dc32e9..00141f01 100644 --- a/api/graphql/handler.go +++ b/api/graphql/handler.go @@ -1,4 +1,4 @@ -//go:generate go run gen_graphql.go +//go:generate go run github.com/99designs/gqlgen generate // Package graphql contains the root GraphQL http handler package graphql diff --git a/api/graphql/models/gen_models.go b/api/graphql/models/gen_models.go index c4e40cba..d75b3d27 100644 --- a/api/graphql/models/gen_models.go +++ b/api/graphql/models/gen_models.go @@ -161,10 +161,8 @@ type EditCommentInput struct { ClientMutationID *string `json:"clientMutationId"` // The name of the repository. If not set, the default repository is used. RepoRef *string `json:"repoRef"` - // The bug ID's prefix. - Prefix string `json:"prefix"` - // The ID of the comment to be changed. - Target string `json:"target"` + // A prefix of the CombinedId of the comment to be changed. + TargetPrefix string `json:"targetPrefix"` // The new message to be set. Message string `json:"message"` // The collection of file's hash required for the first message. diff --git a/api/graphql/resolvers/bug.go b/api/graphql/resolvers/bug.go index d17a4469..c40949fa 100644 --- a/api/graphql/resolvers/bug.go +++ b/api/graphql/resolvers/bug.go @@ -14,10 +14,6 @@ var _ graph.BugResolver = &bugResolver{} type bugResolver struct{} -func (bugResolver) ID(_ context.Context, obj models.BugWrapper) (string, error) { - return obj.Id().String(), nil -} - func (bugResolver) HumanID(_ context.Context, obj models.BugWrapper) (string, error) { return obj.Id().Human(), nil } diff --git a/api/graphql/resolvers/comment.go b/api/graphql/resolvers/comment.go index 78548156..7dddc3c8 100644 --- a/api/graphql/resolvers/comment.go +++ b/api/graphql/resolvers/comment.go @@ -6,12 +6,17 @@ import ( "github.com/MichaelMure/git-bug/api/graphql/graph" "github.com/MichaelMure/git-bug/api/graphql/models" "github.com/MichaelMure/git-bug/entities/bug" + "github.com/MichaelMure/git-bug/entity" ) var _ graph.CommentResolver = &commentResolver{} type commentResolver struct{} +func (c commentResolver) ID(ctx context.Context, obj *bug.Comment) (entity.CombinedId, error) { + return obj.CombinedId(), nil +} + func (c commentResolver) Author(_ context.Context, obj *bug.Comment) (models.IdentityWrapper, error) { return models.NewLoadedIdentity(obj.Author), nil } diff --git a/api/graphql/resolvers/mutation.go b/api/graphql/resolvers/mutation.go index 6ad81db4..f6296d63 100644 --- a/api/graphql/resolvers/mutation.go +++ b/api/graphql/resolvers/mutation.go @@ -9,7 +9,6 @@ import ( "github.com/MichaelMure/git-bug/api/graphql/models" "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/entities/bug" - "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/util/text" ) @@ -177,7 +176,12 @@ func (r mutationResolver) AddCommentAndReopen(ctx context.Context, input models. } func (r mutationResolver) EditComment(ctx context.Context, input models.EditCommentInput) (*models.EditCommentPayload, error) { - repo, b, err := r.getBug(input.RepoRef, input.Prefix) + repo, err := r.getRepo(input.RepoRef) + if err != nil { + return nil, err + } + + b, target, err := repo.ResolveComment(input.TargetPrefix) if err != nil { return nil, err } @@ -190,7 +194,7 @@ func (r mutationResolver) EditComment(ctx context.Context, input models.EditComm op, err := b.EditCommentRaw( author, time.Now().Unix(), - entity.Id(input.Target), + target, text.Cleanup(input.Message), nil, ) diff --git a/api/graphql/resolvers/operations.go b/api/graphql/resolvers/operations.go index 53c3c0bc..91194213 100644 --- a/api/graphql/resolvers/operations.go +++ b/api/graphql/resolvers/operations.go @@ -13,10 +13,6 @@ var _ graph.CreateOperationResolver = createOperationResolver{} type createOperationResolver struct{} -func (createOperationResolver) ID(_ context.Context, obj *bug.CreateOperation) (string, error) { - return obj.Id().String(), nil -} - func (createOperationResolver) Author(_ context.Context, obj *bug.CreateOperation) (models.IdentityWrapper, error) { return models.NewLoadedIdentity(obj.Author()), nil } @@ -30,10 +26,6 @@ var _ graph.AddCommentOperationResolver = addCommentOperationResolver{} type addCommentOperationResolver struct{} -func (addCommentOperationResolver) ID(_ context.Context, obj *bug.AddCommentOperation) (string, error) { - return obj.Id().String(), nil -} - func (addCommentOperationResolver) Author(_ context.Context, obj *bug.AddCommentOperation) (models.IdentityWrapper, error) { return models.NewLoadedIdentity(obj.Author()), nil } @@ -47,10 +39,6 @@ var _ graph.EditCommentOperationResolver = editCommentOperationResolver{} type editCommentOperationResolver struct{} -func (editCommentOperationResolver) ID(_ context.Context, obj *bug.EditCommentOperation) (string, error) { - return obj.Id().String(), nil -} - func (editCommentOperationResolver) Target(_ context.Context, obj *bug.EditCommentOperation) (string, error) { return obj.Target.String(), nil } @@ -68,10 +56,6 @@ var _ graph.LabelChangeOperationResolver = labelChangeOperationResolver{} type labelChangeOperationResolver struct{} -func (labelChangeOperationResolver) ID(_ context.Context, obj *bug.LabelChangeOperation) (string, error) { - return obj.Id().String(), nil -} - func (labelChangeOperationResolver) Author(_ context.Context, obj *bug.LabelChangeOperation) (models.IdentityWrapper, error) { return models.NewLoadedIdentity(obj.Author()), nil } @@ -85,10 +69,6 @@ var _ graph.SetStatusOperationResolver = setStatusOperationResolver{} type setStatusOperationResolver struct{} -func (setStatusOperationResolver) ID(_ context.Context, obj *bug.SetStatusOperation) (string, error) { - return obj.Id().String(), nil -} - func (setStatusOperationResolver) Author(_ context.Context, obj *bug.SetStatusOperation) (models.IdentityWrapper, error) { return models.NewLoadedIdentity(obj.Author()), nil } @@ -102,10 +82,6 @@ var _ graph.SetTitleOperationResolver = setTitleOperationResolver{} type setTitleOperationResolver struct{} -func (setTitleOperationResolver) ID(_ context.Context, obj *bug.SetTitleOperation) (string, error) { - return obj.Id().String(), nil -} - func (setTitleOperationResolver) Author(_ context.Context, obj *bug.SetTitleOperation) (models.IdentityWrapper, error) { return models.NewLoadedIdentity(obj.Author()), nil } diff --git a/api/graphql/resolvers/timeline.go b/api/graphql/resolvers/timeline.go index 2481784e..2d691173 100644 --- a/api/graphql/resolvers/timeline.go +++ b/api/graphql/resolvers/timeline.go @@ -7,6 +7,7 @@ import ( "github.com/MichaelMure/git-bug/api/graphql/graph" "github.com/MichaelMure/git-bug/api/graphql/models" "github.com/MichaelMure/git-bug/entities/bug" + "github.com/MichaelMure/git-bug/entity" ) var _ graph.CommentHistoryStepResolver = commentHistoryStepResolver{} @@ -22,8 +23,8 @@ var _ graph.AddCommentTimelineItemResolver = addCommentTimelineItemResolver{} type addCommentTimelineItemResolver struct{} -func (addCommentTimelineItemResolver) ID(_ context.Context, obj *bug.AddCommentTimelineItem) (string, error) { - return obj.Id().String(), nil +func (addCommentTimelineItemResolver) ID(_ context.Context, obj *bug.AddCommentTimelineItem) (entity.CombinedId, error) { + return obj.CombinedId(), nil } func (addCommentTimelineItemResolver) Author(_ context.Context, obj *bug.AddCommentTimelineItem) (models.IdentityWrapper, error) { @@ -44,8 +45,8 @@ var _ graph.CreateTimelineItemResolver = createTimelineItemResolver{} type createTimelineItemResolver struct{} -func (createTimelineItemResolver) ID(_ context.Context, obj *bug.CreateTimelineItem) (string, error) { - return obj.Id().String(), nil +func (createTimelineItemResolver) ID(_ context.Context, obj *bug.CreateTimelineItem) (entity.CombinedId, error) { + return obj.CombinedId(), nil } func (r createTimelineItemResolver) Author(_ context.Context, obj *bug.CreateTimelineItem) (models.IdentityWrapper, error) { @@ -66,8 +67,8 @@ var _ graph.LabelChangeTimelineItemResolver = labelChangeTimelineItem{} type labelChangeTimelineItem struct{} -func (labelChangeTimelineItem) ID(_ context.Context, obj *bug.LabelChangeTimelineItem) (string, error) { - return obj.Id().String(), nil +func (labelChangeTimelineItem) ID(_ context.Context, obj *bug.LabelChangeTimelineItem) (entity.CombinedId, error) { + return obj.CombinedId(), nil } func (i labelChangeTimelineItem) Author(_ context.Context, obj *bug.LabelChangeTimelineItem) (models.IdentityWrapper, error) { @@ -83,8 +84,8 @@ var _ graph.SetStatusTimelineItemResolver = setStatusTimelineItem{} type setStatusTimelineItem struct{} -func (setStatusTimelineItem) ID(_ context.Context, obj *bug.SetStatusTimelineItem) (string, error) { - return obj.Id().String(), nil +func (setStatusTimelineItem) ID(_ context.Context, obj *bug.SetStatusTimelineItem) (entity.CombinedId, error) { + return obj.CombinedId(), nil } func (i setStatusTimelineItem) Author(_ context.Context, obj *bug.SetStatusTimelineItem) (models.IdentityWrapper, error) { @@ -100,8 +101,8 @@ var _ graph.SetTitleTimelineItemResolver = setTitleTimelineItem{} type setTitleTimelineItem struct{} -func (setTitleTimelineItem) ID(_ context.Context, obj *bug.SetTitleTimelineItem) (string, error) { - return obj.Id().String(), nil +func (setTitleTimelineItem) ID(_ context.Context, obj *bug.SetTitleTimelineItem) (entity.CombinedId, error) { + return obj.CombinedId(), nil } func (i setTitleTimelineItem) Author(_ context.Context, obj *bug.SetTitleTimelineItem) (models.IdentityWrapper, error) { diff --git a/api/graphql/schema/bug.graphql b/api/graphql/schema/bug.graphql index 03aa95b8..17d3a897 100644 --- a/api/graphql/schema/bug.graphql +++ b/api/graphql/schema/bug.graphql @@ -1,5 +1,7 @@ """Represents a comment on a bug.""" type Comment implements Authored { + id: CombinedId! + """The author of this comment.""" author: Identity! @@ -29,7 +31,7 @@ enum Status { type Bug implements Authored { """The identifier for this bug""" - id: String! + id: ID! """The human version (truncated) identifier for this bug""" humanId: String! status: Status! diff --git a/api/graphql/schema/identity.graphql b/api/graphql/schema/identity.graphql index 93154a90..c910ea55 100644 --- a/api/graphql/schema/identity.graphql +++ b/api/graphql/schema/identity.graphql @@ -1,7 +1,7 @@ """Represents an identity""" type Identity { """The identifier for this identity""" - id: String! + id: ID! """The human version (truncated) identifier for this identity""" humanId: String! """The name of the person, if known.""" diff --git a/api/graphql/schema/mutations.graphql b/api/graphql/schema/mutations.graphql index 078dc214..be6a0115 100644 --- a/api/graphql/schema/mutations.graphql +++ b/api/graphql/schema/mutations.graphql @@ -95,10 +95,8 @@ input EditCommentInput { clientMutationId: String """The name of the repository. If not set, the default repository is used.""" repoRef: String - """The bug ID's prefix.""" - prefix: String! - """The ID of the comment to be changed.""" - target: String! + """A prefix of the CombinedId of the comment to be changed.""" + targetPrefix: String! """The new message to be set.""" message: String! """The collection of file's hash required for the first message.""" diff --git a/api/graphql/schema/operations.graphql b/api/graphql/schema/operations.graphql index 18e0929c..8e198753 100644 --- a/api/graphql/schema/operations.graphql +++ b/api/graphql/schema/operations.graphql @@ -1,7 +1,7 @@ """An operation applied to a bug.""" interface Operation { """The identifier of the operation""" - id: String! + id: ID! """The operations author.""" author: Identity! """The datetime when this operation was issued.""" @@ -28,7 +28,7 @@ type OperationEdge { type CreateOperation implements Operation & Authored { """The identifier of the operation""" - id: String! + id: ID! """The author of this object.""" author: Identity! """The datetime when this operation was issued.""" @@ -41,7 +41,7 @@ type CreateOperation implements Operation & Authored { type SetTitleOperation implements Operation & Authored { """The identifier of the operation""" - id: String! + id: ID! """The author of this object.""" author: Identity! """The datetime when this operation was issued.""" @@ -53,7 +53,7 @@ type SetTitleOperation implements Operation & Authored { type AddCommentOperation implements Operation & Authored { """The identifier of the operation""" - id: String! + id: ID! """The author of this object.""" author: Identity! """The datetime when this operation was issued.""" @@ -65,7 +65,7 @@ type AddCommentOperation implements Operation & Authored { type EditCommentOperation implements Operation & Authored { """The identifier of the operation""" - id: String! + id: ID! """The author of this object.""" author: Identity! """The datetime when this operation was issued.""" @@ -78,7 +78,7 @@ type EditCommentOperation implements Operation & Authored { type SetStatusOperation implements Operation & Authored { """The identifier of the operation""" - id: String! + id: ID! """The author of this object.""" author: Identity! """The datetime when this operation was issued.""" @@ -89,7 +89,7 @@ type SetStatusOperation implements Operation & Authored { type LabelChangeOperation implements Operation & Authored { """The identifier of the operation""" - id: String! + id: ID! """The author of this object.""" author: Identity! """The datetime when this operation was issued.""" diff --git a/api/graphql/schema/timeline.graphql b/api/graphql/schema/timeline.graphql index 12462aa3..b7ab5ca8 100644 --- a/api/graphql/schema/timeline.graphql +++ b/api/graphql/schema/timeline.graphql @@ -1,7 +1,7 @@ """An item in the timeline of events""" interface TimelineItem { """The identifier of the source operation""" - id: String! + id: CombinedId! } """CommentHistoryStep hold one version of a message in the history""" @@ -31,7 +31,7 @@ type TimelineItemEdge { """CreateTimelineItem is a TimelineItem that represent the creation of a bug and its message edition history""" type CreateTimelineItem implements TimelineItem & Authored { """The identifier of the source operation""" - id: String! + id: CombinedId! author: Identity! message: String! messageIsEmpty: Boolean! @@ -45,7 +45,7 @@ type CreateTimelineItem implements TimelineItem & Authored { """AddCommentTimelineItem is a TimelineItem that represent a Comment and its edition history""" type AddCommentTimelineItem implements TimelineItem & Authored { """The identifier of the source operation""" - id: String! + id: CombinedId! author: Identity! message: String! messageIsEmpty: Boolean! @@ -59,7 +59,7 @@ type AddCommentTimelineItem implements TimelineItem & Authored { """LabelChangeTimelineItem is a TimelineItem that represent a change in the labels of a bug""" type LabelChangeTimelineItem implements TimelineItem & Authored { """The identifier of the source operation""" - id: String! + id: CombinedId! author: Identity! date: Time! added: [Label!]! @@ -69,7 +69,7 @@ type LabelChangeTimelineItem implements TimelineItem & Authored { """SetStatusTimelineItem is a TimelineItem that represent a change in the status of a bug""" type SetStatusTimelineItem implements TimelineItem & Authored { """The identifier of the source operation""" - id: String! + id: CombinedId! author: Identity! date: Time! status: Status! @@ -78,7 +78,7 @@ type SetStatusTimelineItem implements TimelineItem & Authored { """LabelChangeTimelineItem is a TimelineItem that represent a change in the title of a bug""" type SetTitleTimelineItem implements TimelineItem & Authored { """The identifier of the source operation""" - id: String! + id: CombinedId! author: Identity! date: Time! title: String! diff --git a/api/graphql/schema/types.graphql b/api/graphql/schema/types.graphql index 0182885e..f4284b2d 100644 --- a/api/graphql/schema/types.graphql +++ b/api/graphql/schema/types.graphql @@ -1,3 +1,4 @@ +scalar CombinedId scalar Time scalar Hash diff --git a/api/graphql/tools.go b/api/graphql/tools.go new file mode 100644 index 00000000..863672ec --- /dev/null +++ b/api/graphql/tools.go @@ -0,0 +1,8 @@ +//go:build tools +// +build tools + +package graphql + +import ( + _ "github.com/99designs/gqlgen" +) diff --git a/api/http/git_file_handler.go b/api/http/git_file_handler.go index 0bc0fd0c..b5676970 100644 --- a/api/http/git_file_handler.go +++ b/api/http/git_file_handler.go @@ -47,7 +47,7 @@ func (gfh *gitFileHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { return } - // TODO: this mean that the whole file will he buffered in memory + // TODO: this mean that the whole file will be buffered in memory // This can be a problem for big files. There might be a way around // that by implementing a io.ReadSeeker that would read and discard // data when a seek is called. |