我一直在尝试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
type Payload struct {
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
Value int `json:"value,omitempty"`
Nonce int `json:"nonce,omitempty"`
Data string `json:"data,omitempty"`
Time int `json:"time,omitempty"`
Signature string `json:"signature,omitempty"`
}
var blk = []Blk{
{Header: Header{
Parent: "0000000000000000000000000000000000000000000000000000000000000000",
Number: 0,
Nonce: 1548399560,
Time: 1609374088,
Miner: "0x699ecb24665b9734c420db0f75ed9677a8615eb1",
米琪卡哇伊
相关分类