refactor getReferences #103
@ -19,6 +19,9 @@ test/
|
|||||||
tests/
|
tests/
|
||||||
*_test.go
|
*_test.go
|
||||||
|
|
||||||
|
# false positive
|
||||||
|
testutil/network/network.go
|
||||||
|
|
||||||
# Semgrep rules folder
|
# Semgrep rules folder
|
||||||
.semgrep
|
.semgrep
|
||||||
|
|
||||||
|
24
gql/util.go
24
gql/util.go
@ -164,24 +164,26 @@ 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) {
|
||||||
|
ids := getIds(r.Attributes)
|
||||||
|
return resolver.GetRecordsByIds(ctx, ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getIds(obj map[string]interface{}) []string {
|
||||||
var ids []string
|
var ids []string
|
||||||
|
|
||||||
// #nosec G705
|
// #nosec G705
|
||||||
for key := range r.Attributes {
|
for key := range obj {
|
||||||
//nolint: all
|
if innerObj, ok := obj[key].(map[string]interface{}); ok {
|
||||||
switch r.Attributes[key].(type) {
|
if _, ok := innerObj["/"]; ok && len(innerObj) == 1 {
|
||||||
case interface{}:
|
if _, ok := innerObj["/"].(string); ok {
|
||||||
if obj, ok := r.Attributes[key].(map[string]interface{}); ok {
|
ids = append(ids, innerObj["/"].(string))
|
||||||
if _, ok := obj["/"]; ok && len(obj) == 1 {
|
|
||||||
if _, ok := obj["/"].(string); ok {
|
|
||||||
ids = append(ids, obj["/"].(string))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ids = append(ids, getIds(innerObj)...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
}
|
}
|
||||||
|
return ids
|
||||||
return resolver.GetRecordsByIds(ctx, ids)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAttributes(r *registrytypes.RecordType) ([]*KeyValue, error) {
|
func getAttributes(r *registrytypes.RecordType) ([]*KeyValue, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user
Can you add few test cases.