diff --git a/api4/resolver_channel.go b/api4/resolver_channel.go index 3cf4d28893..4e9a59da38 100644 --- a/api4/resolver_channel.go +++ b/api4/resolver_channel.go @@ -87,12 +87,18 @@ func postProcessChannels(c *web.Context, channels []*model.Channel) ([]*channel, // This approach becomes effectively similar to a dataloader if the displayName computation // were to be done at the field level per channel. - // Get DM/GM channelIDs + // Get DM/GM channelIDs and set empty maps as well. var channelIDs []string for _, ch := range channels { if ch.IsGroupOrDirect() { channelIDs = append(channelIDs, ch.Id) } + + // This is needed to avoid sending null, which + // does not match with the schema since props is not nullable. + // And making it nullable would mean taking pointer of a map, + // which is not very idiomatic. + ch.MakeNonNil() } var nameFormat string diff --git a/api4/resolver_channel_test.go b/api4/resolver_channel_test.go index 627706bd48..36c7989ec1 100644 --- a/api4/resolver_channel_test.go +++ b/api4/resolver_channel_test.go @@ -43,6 +43,7 @@ func TestGraphQLChannels(t *testing.T) { TotalMsgCountRoot float64 `json:"totalMsgCountRoot"` LastRootPostAt float64 `json:"lastRootPostAt"` Cursor string `json:"cursor"` + Props map[string]any `json:"props"` Team struct { ID string `json:"id"` DisplayName string `json:"displayName"` @@ -75,6 +76,7 @@ func TestGraphQLChannels(t *testing.T) { totalMsgCountRoot lastRootPostAt cursor + props } } `, @@ -97,6 +99,7 @@ func TestGraphQLChannels(t *testing.T) { assert.NotEmpty(t, ch.PrettyDisplayName) assert.NotEmpty(t, ch.CreateAt) assert.NotEmpty(t, ch.UpdateAt) + assert.NotNil(t, ch.Props) if ch.Type == model.ChannelTypeOpen { numPublic++ } else if ch.Type == model.ChannelTypePrivate { diff --git a/model/utils.go b/model/utils.go index 0b89e03606..75e34c7d29 100644 --- a/model/utils.go +++ b/model/utils.go @@ -190,6 +190,10 @@ func (StringInterface) ImplementsGraphQLType(name string) bool { return name == "StringInterface" } +func (si StringInterface) MarshalJSON() ([]byte, error) { + return json.Marshal((map[string]any)(si)) +} + func (si *StringInterface) UnmarshalGraphQL(input any) error { json, ok := input.(map[string]any) if !ok {