我一直在尝试使用 go-grapqhql,并且能够成功地创建一些模式,例如:
type Artist struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Type string `json:"type"`
Instrument []Instrument `json:"instrument"`
}
type Instrument struct{
Name string `json:"name"`
}
var artists = []Artist{
{
ID: "1",
Name: "Taylor Swift",
Type: "artist",
Instrument: []Instrument{
{Name:"violin"},
},
},
}
var instrumentType = graphql.NewObject(graphql.ObjectConfig{
Name: "Instrument",
Fields: graphql.Fields{
"name": &graphql.Field{
Type: graphql.String,
},
},
})
var artistType = graphql.NewObject(graphql.ObjectConfig{
Name: "Artist",
Fields: graphql.Fields{
"id": &graphql.Field{
Type: graphql.String,
},
"name": &graphql.Field{
Type: graphql.String,
},
"type": &graphql.Field{
Type: graphql.String,
},
"instrument": &graphql.Field{
Type: graphql.NewList(instrumentType),
},
},
})
但是,当我尝试使用类似的结构做同样的事情时......
type Blk struct {
Header Header `json:"header,omitempty"`
Payload []Payload `json:"payload,omitempty"`
}
type Header struct {
Parent string `json:"parent,omitempty"`
Number int `json:"number,omitempty"`
Nonce int `json:"nonce,omitempty"`
Time int `json:"time,omitempty"`
Miner string `json:"miner,omitempty"`
}
type Payloads []Payloads
这不是很好。我一直在尝试不同的事情,例如将所有字段设为字符串,但没有任何效果。
HUH函数
相关分类