Recently I was trying to an implementation of a Mutation Request using GoLang as a Graphql Server, Basically this is the query that i send: As you can see its an array of object that contains name and an array of strings
mutation{
CellTest(cells:[{name:"lero",child:["1","2"]},{name:"lero2",child:["12","22"]}]){
querybody
}
}
In my Go code I have a type object that is gonna set the values sent
type Cell struct {
name string `json:"name"`
child []string `json:"child"`
}
and a custom array that is gonna be []Cell
type Cells []*Cell
However when the request is received by GO I get this: Note that this is the print of cellsInterface
[map[child:[1 2] name:lero] map[child:[12 22] name:lero2]]
How can i get each value and assign those in my Array Cells something like this:
Cells[0] = {name="first",child={"1","2"}}
Cells[1] = {name="second",child={"hello","good"}}
this is my current attempt:
var resolvedCells Cells
cellsInterface := params.Args["cells"].([]interface{})
cellsByte, err := json.Marshal(cellsInterface)
if err != nil {
fmt.Println("marshal the input json", err)
return resolvedCells, err
}
if err := json.Unmarshal(cellsByte, &resolvedCells); err != nil {
fmt.Println("unmarshal the input json to Data.Cells", err)
return resolvedCells, err
}
for cell := range resolvedCells {
fmt.Println(cellsInterface[cell].([]interface{}))
}
However this only split the cells array into 0 and 1.