亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用列表作為參數變量(GRAPHQL)的Golang突變

使用列表作為參數變量(GRAPHQL)的Golang突變

Go
一只斗牛犬 2021-04-03 22:19:31
基本上我想做的是將一個字符串ex的列表發送: [“ aa”,“ bb”,“ vv”]到graphql Mutation字段中,當前這是我的Mutation Schema"listTest": &graphql.Field{            Type: QueryMessageType,            Args: graphql.FieldConfigArgument{                "listNew": &graphql.ArgumentConfig{                    Description: "Example List of Json String",                    Type:        graphql.NewList(graphql.NewNonNull(graphql.String)),                },            },            Resolve: func(p graphql.ResolveParams) (interface{}, error) {                list := p.Args["listTest"].([]string)                return listTest(list)            },        },和方法listTestfunc listTest(testing[]string) (*QueryMessage, error) {    fmt.Println(testing)    return &QueryMessage{        QueryBody: "nothing to do here",    }, nil}但是,當我在INSOMNIA中執行請求時,響應為:{    "data": {        "listTest": null    },    "errors": [        {            "message": "interface conversion: interface {} is []interface {}, not []string",            "locations": []        }    ]}請求是這樣的:mutation{    listTest(listNew: ["aa","bb","vv"]){        querybody    }}誰能告訴我如何在Go Server中接收字符串列表。謝謝!:)更新 當我調用fmt.Println(p.Args [“ listTest”])結果是:[aa bb vv]解決了按照投票答案的指示,腳本現在可以完成工作。這是最終結果:Resolve: func(p graphql.ResolveParams) (interface{}, error) {                var groupIDs []string                for _, gid := range p.Args["list"].([]interface{}) {                    groupIDs = append(groupIDs, gid.(string))                }                for _, final := range groupIDs {                    fmt.Println(final)                }                return listTest(groupIDs)            },在控制臺中,我得到了這個:aabbvv
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 348 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號