Go - Graphql:转换字符串!在[字符串!]

Go - Graphql : Convert String! in [String!]

我正在尝试使用 this client 在 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!]".",

所以我的问题是,如何将 String! 转换为 [String!]

[String!] 是一个可选的(非可选)字符串数组。您可以将一段字符串用作数组,将指向一段字符串的指针用作可选数组。

x := []graphql.String{graphql.String(tag)} // This would be good for "[String!]!"

variables := map[string]interface{}{
    "tags": &x, // &x is good for "[String!]"
}