我正在尝试使用此客户端在 go 中查询 wikiJS Graphql API,但我在类型转换方面遇到了一点问题(可能是因为我缺乏 go 和 graphql 技能)。我有这个结构类型:var query struct{    Pages struct{        List struct{            id graphql.Int        }`graphql:"list(tags: $tags)"`    }}variables := map[string]interface{}{    "tags": graphql.String(tag),}其中标记是普通字符串,当我发送请求时出现以下错误:  "GraphQLError: Variable "$tags" of type "String!" used in position expecting type "[String!]".",所以我的问题是,如何将 a 转换String!为 a [String!]?
                    
                    
                1 回答
 
                    
                    
                            偶然的你
                            
                                
                            
                        
                        
                                                
                    TA贡献1841条经验 获得超3个赞
[String!]是(非可选)字符串的可选数组。您可以将字符串切片用于数组,将指向字符串切片的指针用于可选数组。
x := []graphql.String{graphql.String(tag)} // This would be good for "[String!]!"
variables := map[string]interface{}{
"tags": &x, // &x is good for "[String!]"
}
- 1 回答
- 0 关注
- 117 浏览
添加回答
举报
0/150
	提交
		取消
	