本文整理汇总了Golang中github.com/rs/rest-layer/resource.Resource.Schema方法的典型用法代码示例。如果您正苦于以下问题:Golang Resource.Schema方法的具体用法?Golang Resource.Schema怎么用?Golang Resource.Schema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/rs/rest-layer/resource.Resource
的用法示例。
在下文中一共展示了Resource.Schema方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addConnections
// addConnections adds connections fields to the object afterward to prevent from dead loops
func (t types) addConnections(o *graphql.Object, idx resource.Index, r *resource.Resource) {
// Add sub field references
for name, def := range r.Schema().Fields {
if ref, ok := def.Validator.(*schema.Reference); ok {
sr, found := idx.GetResource(ref.Path, nil)
if !found {
log.Panicf("resource reference not found: %s", ref.Path)
}
o.AddFieldConfig(name, &graphql.Field{
Description: def.Description,
Type: t.getObjectType(idx, sr),
Args: getFArgs(def.Params),
Resolve: getSubFieldResolver(name, sr, def),
})
}
}
// Add sub resources
for _, sr := range r.GetResources() {
name := sr.Name()
o.AddFieldConfig(name, &graphql.Field{
Description: fmt.Sprintf("Connection to %s", name),
Type: graphql.NewList(t.getObjectType(idx, sr)),
Args: listArgs,
Resolve: getSubResourceResolver(sr),
})
}
}
示例2: getObjectType
// getObjectType returns a graphql object type definition from a REST layer schema
func (t types) getObjectType(idx resource.Index, r *resource.Resource) *graphql.Object {
// Memoize types by their name so we don't create several instance of the same resource
name := r.Name()
o := t[name]
if o == nil {
o = graphql.NewObject(graphql.ObjectConfig{
Name: name,
Description: r.Schema().Description,
Fields: getFields(idx, r.Schema()),
})
t[name] = o
t.addConnections(o, idx, r)
}
return o
}