refactor getReferences #103

Closed
0xmuralik wants to merge 3 commits from murali/gql into murali/record-attributes
Showing only changes of commit 5b25f5df99 - Show all commits

View File

@ -164,24 +164,24 @@ func GetGQLAuction(auction *auctiontypes.Auction, bids []*auctiontypes.Bid) (*Au
} }
func getReferences(ctx context.Context, resolver QueryResolver, r *registrytypes.RecordType) ([]*Record, error) { func getReferences(ctx context.Context, resolver QueryResolver, r *registrytypes.RecordType) ([]*Record, error) {
var ids []string ids := getIds(r.Attributes)
return resolver.GetRecordsByIds(ctx, ids)
}
// #nosec G705 func getIds(obj map[string]interface{}) []string {
for key := range r.Attributes { var ids []string
//nolint: all for _, val := range obj {
switch r.Attributes[key].(type) { if innerObj, ok := val.(map[string]interface{}); ok {
case interface{}: if _, ok := innerObj["/"]; ok && len(innerObj) == 1 {
if obj, ok := r.Attributes[key].(map[string]interface{}); ok { if _, ok := innerObj["/"].(string); ok {
if _, ok := obj["/"]; ok && len(obj) == 1 { ids = append(ids, innerObj["/"].(string))
if _, ok := obj["/"].(string); ok {
ids = append(ids, obj["/"].(string))
}
} }
} else {
ids = append(ids, getIds(innerObj)...)
} }
} }
} }
return ids
aleem1314 commented 2023-04-03 10:26:38 +00:00 (Migrated from github.com)
Review

Can you add few test cases.

Can you add few test cases.
return resolver.GetRecordsByIds(ctx, ids)
} }
func getAttributes(r *registrytypes.RecordType) ([]*KeyValue, error) { func getAttributes(r *registrytypes.RecordType) ([]*KeyValue, error) {