Skip to content

Latest commit

 

History

History
43 lines (37 loc) · 757 Bytes

05.date.md

File metadata and controls

43 lines (37 loc) · 757 Bytes

Date

a schema that can resolve time.Time values.

Example: we can use the gq.Date schema to resolve time.Time or *time.Time values.

type User struct {
	ID 	 	 	string 		`json:"id,omitempty"`
	Name 	 	string 		`json:"name,omitempty"`
	CreatedAt 	*time.Time	`json:"created_at,omitempty"`
}

schema := gq.Object[User]{
	Name:        "User",
	Description: "...",
	Fields: gq.Fields{
		"id": gq.Field{
			Type: gq.String{},
		},
		"name": gq.Field{
			Type: gq.String{},
		},
		"created_at": gq.Field{
			Type: gq.Date{},
		},
	},
}

now := time.Now()
res := schema.Do(&gq.DoParams{
	Query: "{id,name,created_at}",
	Value: User{
		ID: 	  	"1",
		Name: 	  	"test",
		CreatedAt: 	&now,
	},
})

if res.Error != nil {
	panic(res.Error)
}