如何使用GoLang过滤GraphQL中的数组值

时间:2019-09-13 10:16:25

标签: go graphql

在GraphQL查询中,我想传递$ filter来从用GoLang编写的数组中获取值。输出如下所示。

示例代码-

if args.Filter != "" && args.Filter != Relay.NILQUERY {
                        var err error
                        val := reflect.Indirect(reflect.ValueOf(&Summary{}))
                        arrResData, err = Relay.Filter(string(args.Filter), val, arrResData)
                        if err != nil {
                            return nil, err
                        }
                    }

Sample output-
{
                        "node": {
                            "AvailablityStatus": "",
                            "Hierarchies": [
                                {
                                    "ID": "1100000",
                                    "Level": "2",
                                    "Name": "Test1",
                                    "Title": "subscription"
                                },
                                {
                                    "ID": "PHARESH",
                                    "Level": "3",
                                    "Name": "PHARESH",
                                    "Title": "resourcegroup"
                                }
                            ],
                            "ID": "11000001",
                            "Location": "eastus",
                            "Name": "Test2",
                            "ServiceType": "disks"
                        }
                    },
                    {
                        "node": {
                            "AvailablityStatus": "",
                            "Hierarchies": [
                                {
                                    "ID": "220000",
                                    "Level": "2",
                                    "Name": "Engg",
                                    "Title": "subscription"
                                },
                                {
                                    "ID": "AzureBackupRG_centralus_1",
                                    "Level": "3",
                                    "Name": "AzureBackupRG_centralus_1",
                                    "Title": "resourcegroup"
                                }
                            ],
                            "ID": "220001",
                            "Location": "centralus",
                            "Name": "testVM20192_OsDisk_1_566cb9dcdfd042b3808ad346ee08aaa0",
                            "ServiceType": "disks"
                        }
                    }

我的GraphQL查询-

{"query": "query Data { List(clientid: \"1111\", hierarchyid: \"ALL\", refresh: false, servicetype:\"\") { Resources( filter:\"{key:[{\"Name\": \"Engineering-Continuum\"}],column:Hierarchies, op:===}\"){edges{node{ ID Name ServiceType Location AvailablityStatus Hierarchies{ Title Name ID Level }}}}}}"}

这里我想根据Title和Name获取Hierarchies数组的值,它应该返回该特定节点下的结果集。

0 个答案:

没有答案