From 1c2ee10ce7a32df892604846279c7e199ce0ccea Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Wed, 22 May 2019 21:46:43 +0200 Subject: [PATCH] graphql: Implement `Authored` whenever possible webui: Use a fragment for Authored nodes --- bug/bug.go | 3 +++ bug/op_add_comment.go | 3 +++ bug/op_create.go | 3 +++ bug/op_label_change.go | 3 +++ bug/op_set_status.go | 3 +++ bug/op_set_title.go | 3 +++ bug/snapshot.go | 3 +++ graphql/graph/gen_graph.go | 40 +++++++++++++++++++++------------ graphql/schema/bug.graphql | 3 +-- graphql/schema/timeline.graphql | 10 ++++----- graphql/schema/types.graphql | 2 +- webui/src/Author.js | 12 ++++++++++ webui/src/bug/Bug.js | 7 ++---- webui/src/bug/LabelChange.js | 8 +++---- webui/src/bug/Message.js | 18 +++++---------- webui/src/bug/SetStatus.js | 8 +++---- webui/src/bug/SetTitle.js | 8 +++---- webui/src/list/BugRow.js | 8 +++---- 18 files changed, 87 insertions(+), 58 deletions(-) diff --git a/bug/bug.go b/bug/bug.go index f1bd1114ca9fca0b6beb1aa00f1b69a5a411c887..0604d11d4b47d10248f43e50eb819da220d0fd1e 100644 --- a/bug/bug.go +++ b/bug/bug.go @@ -681,3 +681,6 @@ func (bug *Bug) Compile() Snapshot { return snap } + +// Sign post method for gqlgen +func (bug *Bug) IsAuthored() {} diff --git a/bug/op_add_comment.go b/bug/op_add_comment.go index 8cde20e8d3f095c425b1c56b0621c02d7942a683..59ea08e09c58cce1287e28b339eb5a15ff9b97e4 100644 --- a/bug/op_add_comment.go +++ b/bug/op_add_comment.go @@ -149,3 +149,6 @@ func AddCommentWithFiles(b Interface, author identity.Interface, unixTime int64, b.Append(addCommentOp) return addCommentOp, nil } + +// Sign post method for gqlgen +func (item *AddCommentTimelineItem) IsAuthored() {} diff --git a/bug/op_create.go b/bug/op_create.go index f3757f896226b80cf95050f3e2a9ed0e43e459cc..e0e8154b13ac14dc8217e9cf9d27f0293d783b48 100644 --- a/bug/op_create.go +++ b/bug/op_create.go @@ -173,3 +173,6 @@ func CreateWithFiles(author identity.Interface, unixTime int64, title, message s return newBug, createOp, nil } + +// Sign post method for gqlgen +func (item *CreateTimelineItem) IsAuthored() {} diff --git a/bug/op_label_change.go b/bug/op_label_change.go index 0e7929b76bf3e6a095048ae9141e30cbd850cd48..c5b3765d2b1df4286ed06e7378f44a721abbcd32 100644 --- a/bug/op_label_change.go +++ b/bug/op_label_change.go @@ -303,3 +303,6 @@ func (l LabelChangeResult) String() string { panic(fmt.Sprintf("unknown label change status %v", l.Status)) } } + +// Sign post method for gqlgen +func (item *LabelChangeTimelineItem) IsAuthored() {} diff --git a/bug/op_set_status.go b/bug/op_set_status.go index 57d4cf22abc3afe05966a174cbe3f7f771583773..de7b85266ff58737849c7980163ff5b55294c71c 100644 --- a/bug/op_set_status.go +++ b/bug/op_set_status.go @@ -143,3 +143,6 @@ func Close(b Interface, author identity.Interface, unixTime int64) (*SetStatusOp b.Append(op) return op, nil } + +// Sign post method for gqlgen +func (item *SetStatusTimelineItem) IsAuthored() {} diff --git a/bug/op_set_title.go b/bug/op_set_title.go index ca27adee0af39ccba05209258ab4c82cb4083bbf..dce060148d443f6517ed9b6959596ac7ae6f4700 100644 --- a/bug/op_set_title.go +++ b/bug/op_set_title.go @@ -178,3 +178,6 @@ func SetTitle(b Interface, author identity.Interface, unixTime int64, title stri b.Append(setTitleOp) return setTitleOp, nil } + +// Sign post method for gqlgen +func (item *SetTitleTimelineItem) IsAuthored() {} diff --git a/bug/snapshot.go b/bug/snapshot.go index 53f6873ab2c9ec1221dc98a1c62482fff3f9f610..a4661b14928c90308ad71dc2a8dfa16adf8d09f2 100644 --- a/bug/snapshot.go +++ b/bug/snapshot.go @@ -86,3 +86,6 @@ func (snap *Snapshot) addParticipant(participant identity.Interface) { snap.Participants = append(snap.Participants, participant) } + +// Sign post method for gqlgen +func (snap *Snapshot) IsAuthored() {} diff --git a/graphql/graph/gen_graph.go b/graphql/graph/gen_graph.go index 6365d597eec4faa09b20b5335e0a48efb08df069..8b9221da137f5cdfb36f9116568964eb4ce050e0 100644 --- a/graphql/graph/gen_graph.go +++ b/graphql/graph/gen_graph.go @@ -1601,7 +1601,7 @@ enum Status { CLOSED } -type Bug { +type Bug implements Authored { """The identifier for this bug""" id: String! """The human version (truncated) identifier for this bug""" @@ -1690,7 +1690,6 @@ type BugEdge { """The item at the end of the edge.""" node: Bug! } - `}, &ast.Source{Name: "schema/identity.graphql", Input: `"""Represents an identity""" type Identity { @@ -1911,7 +1910,7 @@ type TimelineItemEdge { # Items """CreateTimelineItem is a TimelineItem that represent the creation of a bug and its message edition history""" -type CreateTimelineItem implements TimelineItem { +type CreateTimelineItem implements TimelineItem & Authored { """The hash of the source operation""" hash: Hash! author: Identity! @@ -1925,7 +1924,7 @@ type CreateTimelineItem implements TimelineItem { } """AddCommentTimelineItem is a TimelineItem that represent a Comment and its edition history""" -type AddCommentTimelineItem implements TimelineItem { +type AddCommentTimelineItem implements TimelineItem & Authored { """The hash of the source operation""" hash: Hash! author: Identity! @@ -1939,7 +1938,7 @@ type AddCommentTimelineItem implements TimelineItem { } """LabelChangeTimelineItem is a TimelineItem that represent a change in the labels of a bug""" -type LabelChangeTimelineItem implements TimelineItem { +type LabelChangeTimelineItem implements TimelineItem & Authored { """The hash of the source operation""" hash: Hash! author: Identity! @@ -1949,7 +1948,7 @@ type LabelChangeTimelineItem implements TimelineItem { } """SetStatusTimelineItem is a TimelineItem that represent a change in the status of a bug""" -type SetStatusTimelineItem implements TimelineItem { +type SetStatusTimelineItem implements TimelineItem & Authored { """The hash of the source operation""" hash: Hash! author: Identity! @@ -1958,7 +1957,7 @@ type SetStatusTimelineItem implements TimelineItem { } """LabelChangeTimelineItem is a TimelineItem that represent a change in the title of a bug""" -type SetTitleTimelineItem implements TimelineItem { +type SetTitleTimelineItem implements TimelineItem & Authored { """The hash of the source operation""" hash: Hash! author: Identity! @@ -2004,7 +2003,8 @@ type PageInfo { interface Authored { """The author of this object.""" author: Identity! -}`}, +} +`}, ) // endregion ************************** generated!.gotpl ************************** @@ -7434,6 +7434,8 @@ func (ec *executionContext) _Authored(ctx context.Context, sel ast.SelectionSet, return ec._Comment(ctx, sel, &obj) case *bug.Comment: return ec._Comment(ctx, sel, obj) + case *bug.Snapshot: + return ec._Bug(ctx, sel, obj) case *bug.CreateOperation: return ec._CreateOperation(ctx, sel, obj) case *bug.SetTitleOperation: @@ -7446,6 +7448,16 @@ func (ec *executionContext) _Authored(ctx context.Context, sel ast.SelectionSet, return ec._SetStatusOperation(ctx, sel, obj) case *bug.LabelChangeOperation: return ec._LabelChangeOperation(ctx, sel, obj) + case *bug.CreateTimelineItem: + return ec._CreateTimelineItem(ctx, sel, obj) + case *bug.AddCommentTimelineItem: + return ec._AddCommentTimelineItem(ctx, sel, obj) + case *bug.LabelChangeTimelineItem: + return ec._LabelChangeTimelineItem(ctx, sel, obj) + case *bug.SetStatusTimelineItem: + return ec._SetStatusTimelineItem(ctx, sel, obj) + case *bug.SetTitleTimelineItem: + return ec._SetTitleTimelineItem(ctx, sel, obj) default: panic(fmt.Errorf("unexpected type %T", obj)) } @@ -7557,7 +7569,7 @@ func (ec *executionContext) _AddCommentOperation(ctx context.Context, sel ast.Se return out } -var addCommentTimelineItemImplementors = []string{"AddCommentTimelineItem", "TimelineItem"} +var addCommentTimelineItemImplementors = []string{"AddCommentTimelineItem", "TimelineItem", "Authored"} func (ec *executionContext) _AddCommentTimelineItem(ctx context.Context, sel ast.SelectionSet, obj *bug.AddCommentTimelineItem) graphql.Marshaler { fields := graphql.CollectFields(ec.RequestContext, sel, addCommentTimelineItemImplementors) @@ -7642,7 +7654,7 @@ func (ec *executionContext) _AddCommentTimelineItem(ctx context.Context, sel ast return out } -var bugImplementors = []string{"Bug"} +var bugImplementors = []string{"Bug", "Authored"} func (ec *executionContext) _Bug(ctx context.Context, sel ast.SelectionSet, obj *bug.Snapshot) graphql.Marshaler { fields := graphql.CollectFields(ec.RequestContext, sel, bugImplementors) @@ -8143,7 +8155,7 @@ func (ec *executionContext) _CreateOperation(ctx context.Context, sel ast.Select return out } -var createTimelineItemImplementors = []string{"CreateTimelineItem", "TimelineItem"} +var createTimelineItemImplementors = []string{"CreateTimelineItem", "TimelineItem", "Authored"} func (ec *executionContext) _CreateTimelineItem(ctx context.Context, sel ast.SelectionSet, obj *bug.CreateTimelineItem) graphql.Marshaler { fields := graphql.CollectFields(ec.RequestContext, sel, createTimelineItemImplementors) @@ -8591,7 +8603,7 @@ func (ec *executionContext) _LabelChangeOperation(ctx context.Context, sel ast.S return out } -var labelChangeTimelineItemImplementors = []string{"LabelChangeTimelineItem", "TimelineItem"} +var labelChangeTimelineItemImplementors = []string{"LabelChangeTimelineItem", "TimelineItem", "Authored"} func (ec *executionContext) _LabelChangeTimelineItem(ctx context.Context, sel ast.SelectionSet, obj *bug.LabelChangeTimelineItem) graphql.Marshaler { fields := graphql.CollectFields(ec.RequestContext, sel, labelChangeTimelineItemImplementors) @@ -9033,7 +9045,7 @@ func (ec *executionContext) _SetStatusOperation(ctx context.Context, sel ast.Sel return out } -var setStatusTimelineItemImplementors = []string{"SetStatusTimelineItem", "TimelineItem"} +var setStatusTimelineItemImplementors = []string{"SetStatusTimelineItem", "TimelineItem", "Authored"} func (ec *executionContext) _SetStatusTimelineItem(ctx context.Context, sel ast.SelectionSet, obj *bug.SetStatusTimelineItem) graphql.Marshaler { fields := graphql.CollectFields(ec.RequestContext, sel, setStatusTimelineItemImplementors) @@ -9149,7 +9161,7 @@ func (ec *executionContext) _SetTitleOperation(ctx context.Context, sel ast.Sele return out } -var setTitleTimelineItemImplementors = []string{"SetTitleTimelineItem", "TimelineItem"} +var setTitleTimelineItemImplementors = []string{"SetTitleTimelineItem", "TimelineItem", "Authored"} func (ec *executionContext) _SetTitleTimelineItem(ctx context.Context, sel ast.SelectionSet, obj *bug.SetTitleTimelineItem) graphql.Marshaler { fields := graphql.CollectFields(ec.RequestContext, sel, setTitleTimelineItemImplementors) diff --git a/graphql/schema/bug.graphql b/graphql/schema/bug.graphql index 8e058ed7222e38b03cd01acd42f0ebac36719d22..03aa95b85da1d7e328adc5abb9824afc5501650a 100644 --- a/graphql/schema/bug.graphql +++ b/graphql/schema/bug.graphql @@ -27,7 +27,7 @@ enum Status { CLOSED } -type Bug { +type Bug implements Authored { """The identifier for this bug""" id: String! """The human version (truncated) identifier for this bug""" @@ -116,4 +116,3 @@ type BugEdge { """The item at the end of the edge.""" node: Bug! } - diff --git a/graphql/schema/timeline.graphql b/graphql/schema/timeline.graphql index 35bb88bf27a633dc6b2a06a3dd91d58c4e7340c0..ccc89b876f9ca3a43a4cfc24c7b16401bc05ff35 100644 --- a/graphql/schema/timeline.graphql +++ b/graphql/schema/timeline.graphql @@ -29,7 +29,7 @@ type TimelineItemEdge { # Items """CreateTimelineItem is a TimelineItem that represent the creation of a bug and its message edition history""" -type CreateTimelineItem implements TimelineItem { +type CreateTimelineItem implements TimelineItem & Authored { """The hash of the source operation""" hash: Hash! author: Identity! @@ -43,7 +43,7 @@ type CreateTimelineItem implements TimelineItem { } """AddCommentTimelineItem is a TimelineItem that represent a Comment and its edition history""" -type AddCommentTimelineItem implements TimelineItem { +type AddCommentTimelineItem implements TimelineItem & Authored { """The hash of the source operation""" hash: Hash! author: Identity! @@ -57,7 +57,7 @@ type AddCommentTimelineItem implements TimelineItem { } """LabelChangeTimelineItem is a TimelineItem that represent a change in the labels of a bug""" -type LabelChangeTimelineItem implements TimelineItem { +type LabelChangeTimelineItem implements TimelineItem & Authored { """The hash of the source operation""" hash: Hash! author: Identity! @@ -67,7 +67,7 @@ type LabelChangeTimelineItem implements TimelineItem { } """SetStatusTimelineItem is a TimelineItem that represent a change in the status of a bug""" -type SetStatusTimelineItem implements TimelineItem { +type SetStatusTimelineItem implements TimelineItem & Authored { """The hash of the source operation""" hash: Hash! author: Identity! @@ -76,7 +76,7 @@ type SetStatusTimelineItem implements TimelineItem { } """LabelChangeTimelineItem is a TimelineItem that represent a change in the title of a bug""" -type SetTitleTimelineItem implements TimelineItem { +type SetTitleTimelineItem implements TimelineItem & Authored { """The hash of the source operation""" hash: Hash! author: Identity! diff --git a/graphql/schema/types.graphql b/graphql/schema/types.graphql index 22447aae6892ffd58931dc87511b01698957b63f..fb94d1e8bd3d307cd1ebb2b80b91286acfb4856e 100644 --- a/graphql/schema/types.graphql +++ b/graphql/schema/types.graphql @@ -35,4 +35,4 @@ type PageInfo { interface Authored { """The author of this object.""" author: Identity! -} \ No newline at end of file +} diff --git a/webui/src/Author.js b/webui/src/Author.js index 7bb1bf3ca7402af163c34d8e7f0021a0549e8ee0..237a79569fd77c65e867ee22c095cbf648ff9d93 100644 --- a/webui/src/Author.js +++ b/webui/src/Author.js @@ -1,3 +1,4 @@ +import gql from 'graphql-tag'; import Tooltip from '@material-ui/core/Tooltip/Tooltip'; import MAvatar from '@material-ui/core/Avatar'; import React from 'react'; @@ -14,6 +15,17 @@ const Author = ({ author, ...props }) => { ); }; +Author.fragment = gql` + fragment authored on Authored { + author { + name + email + displayName + avatarUrl + } + } +`; + export const Avatar = ({ author, ...props }) => { if (author.avatarUrl) { return ; diff --git a/webui/src/bug/Bug.js b/webui/src/bug/Bug.js index 1b19149d5db2624ea91a1ecef50c6ab006d2999b..ff57dfa91c9b5766931f3224eebe38aabb3d5659 100644 --- a/webui/src/bug/Bug.js +++ b/webui/src/bug/Bug.js @@ -94,13 +94,10 @@ Bug.fragment = gql` ...Label } createdAt - author { - email - name - displayName - } + ...authored } ${Label.fragment} + ${Author.fragment} `; export default Bug; diff --git a/webui/src/bug/LabelChange.js b/webui/src/bug/LabelChange.js index 1e05b4a6fed2b95691e71c6f40c1021bbdc29829..2405fdb5acdb0e38bbd579c9907b4608f46275f1 100644 --- a/webui/src/bug/LabelChange.js +++ b/webui/src/bug/LabelChange.js @@ -44,11 +44,7 @@ LabelChange.fragment = gql` fragment LabelChange on TimelineItem { ... on LabelChangeTimelineItem { date - author { - name - email - displayName - } + ...authored added { ...Label } @@ -57,7 +53,9 @@ LabelChange.fragment = gql` } } } + ${Label.fragment} + ${Author.fragment} `; export default LabelChange; diff --git a/webui/src/bug/Message.js b/webui/src/bug/Message.js index ff03944496461095c7af154b00e8a0247c22f5a9..8a6cac09d4987439ff9dda3f86ed6bb26db654f7 100644 --- a/webui/src/bug/Message.js +++ b/webui/src/bug/Message.js @@ -70,32 +70,26 @@ Message.createFragment = gql` fragment Create on TimelineItem { ... on CreateTimelineItem { createdAt - author { - name - email - displayName - avatarUrl - } + ...authored edited message } } + + ${Author.fragment} `; Message.commentFragment = gql` fragment AddComment on TimelineItem { ... on AddCommentTimelineItem { createdAt - author { - name - email - displayName - avatarUrl - } + ...authored edited message } } + + ${Author.fragment} `; export default Message; diff --git a/webui/src/bug/SetStatus.js b/webui/src/bug/SetStatus.js index ab591038e3f4ce21fd7da6dc47a6f8ff203db5ec..eeff1a7b05c5b0add81e90e0143ef9ad0845cb60 100644 --- a/webui/src/bug/SetStatus.js +++ b/webui/src/bug/SetStatus.js @@ -26,14 +26,12 @@ SetStatus.fragment = gql` fragment SetStatus on TimelineItem { ... on SetStatusTimelineItem { date - author { - name - email - displayName - } + ...authored status } } + + ${Author.fragment} `; export default SetStatus; diff --git a/webui/src/bug/SetTitle.js b/webui/src/bug/SetTitle.js index d9a09ad54d73e446daf6e2a393a70af3e194f4fe..9ba5a76e4a12186ea45bf7b5da16e544db700571 100644 --- a/webui/src/bug/SetTitle.js +++ b/webui/src/bug/SetTitle.js @@ -32,15 +32,13 @@ SetTitle.fragment = gql` fragment SetTitle on TimelineItem { ... on SetTitleTimelineItem { date - author { - name - email - displayName - } + ...authored title was } } + + ${Author.fragment} `; export default SetTitle; diff --git a/webui/src/list/BugRow.js b/webui/src/list/BugRow.js index cfac461691a91e2c6cacf4dd1ac2445ad1c222a0..c5fc76476bca9f33bf2c128a4af2c7a7fb81953f 100644 --- a/webui/src/list/BugRow.js +++ b/webui/src/list/BugRow.js @@ -9,6 +9,7 @@ import React from 'react'; import { Link } from 'react-router-dom'; import Date from '../Date'; import Label from '../Label'; +import Author from '../Author'; const Open = ({ className }) => ( @@ -97,12 +98,11 @@ BugRow.fragment = gql` labels { ...Label } - author { - name - displayName - } + ...authored } + ${Label.fragment} + ${Author.fragment} `; export default BugRow;