为了账号安全,请及时绑定邮箱和手机立即绑定

使用列表作为参数变量(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 关注
  • 305 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信