项目详情
由
分享


HelloGitHub 评分
0 人评分
开源•MIT
认领
讨论
收藏
分享
1.6k
星数
否
中文
JavaScript
主语言
否
活跃
38
贡献者
131
Issues
是
组织
无
最新版本
115
Forks
MIT
协议
更多
Facebook GraphQL 协议的 Go 语言版本。相比之前的其它 GraphQL 库,通过反射结构体的 tag 可以自动生成 schema 给前端,更加便于开发。示例代码:
```go
// Friend is a small struct representing a person.
type Friend struct {
FirstName string
Last string `graphql:"lastName"` // use a custom name
Added time.Date `graphql:"-"` // don't expose over graphql
}
// FullName builds a friend's full name.
func (f *Friend) FullName() string {
return fmt.Sprintf("%s %s", f.FirstName, f.Last)
}
// registerFriend registers custom resolvers on the Friend type.
//
// Note: registerFriend wouldn't be necessary if the type only
// had the default struct field resolvers above.
func registerFriend(schema *schemabuilder.Schema) {
object := schema.Object("Friend", Friend{})
// fullName is a computed field on the Friend{} object.
object.FieldFunc("fullName", Friend.FullName)
}
```
收录于:
第 31 期
评论
评分:
暂无精选评论