2

The object itself inside the object is parsed with an empty field.

input:

{
  Products(search: {limit: 1, filters: {product_id: {gte: 5}}}) {
    data {
      product_id
      product_name
      sales_history{
        total_check
      }
    }
  }
}

output:

{
  "data": {
    "Products": {
      "data": [
        {
          "product_id": 35,
          "product_name": "testpr",
          "sales_history": {}
        }
      ]
    }
  }
}

Product type:

gql.ProductType = graphql.NewObject(graphql.ObjectConfig{
        Name: "Product",
        Fields: graphql.Fields{
            "product_id": &graphql.Field{
                Type: graphql.Int,
            },
            "product_name": &graphql.Field{
                Type: graphql.String,
            },
            "sales_history": &graphql.Field{
                Type: gql.SalesHistoryType,
            },
        },
    })

SalesHistory type:

gql.SalesHistoryType = graphql.NewObject(graphql.ObjectConfig{
    Name: "sales_history",
    Fields: graphql.Fields{
        "total_check": &graphql.Field{
            Type: graphql.Float,
        },
    },
})

In Resolve returning map in interface:

map[data:[map[product_id:35 product_name:testpr sales_history:map[total_check:671.20]]]]

I create the map"sales_history" myself, otherwise opposite the field sales_history - null

1 Answer 1

0

The problem was in the packaging of the final map.

It was wrong:

tmp := make(map[string]interface{}, 0)
tmp["total_check"] = v["total_check"]
v["sales_history"] = tmp

*Some fields are hidden

That`s right:

v["sales_history"] = make(map[string]interface{}, 0)
v["sales_history"].(map[string]interface{})["total_check"] = v["total_check"]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.