2

I'm trying to query wikiJS Graphql API in go using this client and I have a little problem of type conversion (maybe because of my lack of skills in go and graphql).

I have this struct type :

var query struct{
    Pages struct{
        List struct{
            id graphql.Int
        }`graphql:"list(tags: $tags)"`
    }
}

variables := map[string]interface{}{
    "tags": graphql.String(tag),
}

where tag is a normal string and when I send the request i have the following error : "GraphQLError: Variable "$tags" of type "String!" used in position expecting type "[String!]".",

So My question is, how to convert a String! into a [String!] ?

icza
  • 389,944
  • 63
  • 907
  • 827

1 Answers1

1

[String!] is an optional array of (non-optional) strings. You may use a slice of strings for an array, and a pointer to a slice of string for an optional array.

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

variables := map[string]interface{}{
    "tags": &x, // &x is good for "[String!]"
}
icza
  • 389,944
  • 63
  • 907
  • 827