我正在嘗試使用此客戶端在 go 中查詢 wikiJS Graphql API,但我在類型轉(zhuǎn)換方面遇到了一點(diǎn)問題(可能是因?yàn)槲胰狈?go 和 graphql 技能)。我有這個(gè)結(jié)構(gòu)類型:var query struct{ Pages struct{ List struct{ id graphql.Int }`graphql:"list(tags: $tags)"` }}variables := map[string]interface{}{ "tags": graphql.String(tag),}其中標(biāo)記是普通字符串,當(dāng)我發(fā)送請(qǐng)求時(shí)出現(xiàn)以下錯(cuò)誤: "GraphQLError: Variable "$tags" of type "String!" used in position expecting type "[String!]".",所以我的問題是,如何將 a 轉(zhuǎn)換String!為 a [String!]?
1 回答

偶然的你
TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊
[String!]是(非可選)字符串的可選數(shù)組。您可以將字符串切片用于數(shù)組,將指向字符串切片的指針用于可選數(shù)組。
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 關(guān)注
- 103 瀏覽
添加回答
舉報(bào)
0/150
提交
取消