當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Resource.Schema方法代碼示例

本文整理匯總了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),
		})
	}
}
開發者ID:rs,項目名稱:rest-layer,代碼行數:28,代碼來源:types.go

示例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
}
開發者ID:rs,項目名稱:rest-layer,代碼行數:16,代碼來源:types.go


注:本文中的github.com/rs/rest-layer/resource.Resource.Schema方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。