本文整理匯總了Golang中github.com/rs/rest-layer/resource.Resource.Find方法的典型用法代碼示例。如果您正苦於以下問題:Golang Resource.Find方法的具體用法?Golang Resource.Find怎麽用?Golang Resource.Find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/rs/rest-layer/resource.Resource
的用法示例。
在下文中一共展示了Resource.Find方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getSubResourceResolver
func getSubResourceResolver(r *resource.Resource) graphql.FieldResolveFn {
return func(p graphql.ResolveParams) (interface{}, error) {
parent, ok := p.Source.(map[string]interface{})
if !ok {
return nil, nil
}
lookup, page, perPage, err := listParamResolver(r, p, nil)
if err != nil {
return nil, err
}
// Limit the connection to parent's owned
lookup.AddQuery(schema.Query{
schema.Equal{
Field: r.ParentField(),
Value: parent["id"],
},
})
list, err := r.Find(p.Context, lookup, page, perPage)
if err != nil {
return nil, err
}
result := make([]map[string]interface{}, len(list.Items))
for i, item := range list.Items {
result[i] = item.Payload
}
return result, nil
}
}
示例2: getListQuery
func (t types) getListQuery(idx resource.Index, r *resource.Resource, params url.Values) *graphql.Field {
return &graphql.Field{
Description: fmt.Sprintf("Get a list of %s", r.Name()),
Type: graphql.NewList(t.getObjectType(idx, r)),
Args: listArgs,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
lookup, page, perPage, err := listParamResolver(r, p, params)
if err != nil {
return nil, err
}
list, err := r.Find(p.Context, lookup, page, perPage)
if err != nil {
return nil, err
}
result := make([]map[string]interface{}, len(list.Items))
for i, item := range list.Items {
result[i] = item.Payload
}
return result, nil
},
}
}