Documentation ¶
Index ¶
Constants ¶
View Source
const (
StructDirectiveTypeDef = `` /* 181-byte string literal not displayed */
)
Struct directive
Variables ¶
View Source
var RegistryKey registryKey = "directive_struct_registry"
Actual registry key
View Source
var StructDirective = graphql.NewDirective(graphql.DirectiveConfig{ Name: structDirectiveName, Description: "A directive to define struct types", Locations: []string{ graphql.DirectiveLocationFieldDefinition, graphql.DirectiveLocationObject, }, Args: graphql.FieldConfigArgument{ "is_root": &graphql.ArgumentConfig{ Type: graphql.Boolean, DefaultValue: false, }, "private": &graphql.ArgumentConfig{ Type: graphql.Boolean, DefaultValue: false, }, "omit": &graphql.ArgumentConfig{ Type: graphql.Boolean, DefaultValue: false, }, "name": &graphql.ArgumentConfig{ Type: graphql.String, }, "service": &graphql.ArgumentConfig{ Type: graphql.String, }, "type": &graphql.ArgumentConfig{ Type: graphql.String, }, "prototype": &graphql.ArgumentConfig{ Type: graphql.String, }, "tags": &graphql.ArgumentConfig{ Type: graphql.NewList( graphql.NewNonNull( graphql.String, ), ), }, }, })
Struct direcrtive
View Source
var StructDirectiveVisitor = &tools.SchemaDirectiveVisitor{ VisitObject: func(p tools.VisitObjectParams) { def := tools.MergeExtensions(p.Node, p.Extensions...) reg := p.Context.Value(RegistryKey) registry := reg.(*Registry) args := &Args{} if err := mapProto(p.Args, args); err != nil { fmt.Printf("Failed to map arguments: %v\n", err) return } name := p.Config.Name obj, found := registry.Structs[name] if !found { obj = &Def{ Name: name, Fields: map[string]*FieldDef{}, Private: args.Private, ExplicitName: args.Name, } registry.Structs[name] = obj } for _, field := range def.Fields { args, err := getDirectiveConfig(field.Directives) if err != nil { fmt.Printf("Failed to get field directive args: %v\n", err) return } if args.Service != "" { svc, found := registry.Services[args.Service] if !found { svc = &Service{ Name: args.Service, Methods: map[string]*ServiceMethod{}, } registry.Services[args.Service] = svc } methodName := strcase.ToCamel(field.Name.Value) method, found := svc.Methods[methodName] if !found { method = &ServiceMethod{ Name: methodName, Response: field.Type.(*ast.Named).Name.Value, } } svc.Methods[methodName] = method } if args.Omit { continue } fieldName := field.Name.Value ft := getFieldType(registry, field.Type, nil) def := &FieldDef{ Ref: fieldName, Name: fieldName, GqlType: ft.gqltype, GoType: ft.String(), Prototype: ft.prototype, Private: args.Private, ExplicitName: args.Name, Tags: args.Tags, } if args.Type != "" { def.GoType = args.Type } if args.Prototype != "" { def.Prototype = args.Prototype } obj.Fields[fieldName] = def } }, }
Functions ¶
Types ¶
type Args ¶
type Args struct { Private bool `json:"private"` Omit bool `json:"omit"` Name string `json:"name"` Service string `json:"service"` Type string `json:"type"` Prototype string `json:"prototype"` Tags []string `json:"tags"` }
Args arguments
type FieldDef ¶
type FieldDef struct { Ref string `json:"ref"` Name string `json:"name"` GoType string `json:"gotype"` GqlType string `json:"gqltype"` Prototype string `json:"prototype"` ProtoIndex int `json:"proto_index"` Tags []string `json:"tags"` Private bool `json:"private"` ExplicitName string `json:"explicit_name"` }
type Service ¶
type Service struct { Name string `json:"name"` Methods map[string]*ServiceMethod }
type ServiceMethod ¶
type ServiceMethods ¶
type ServiceMethods []*ServiceMethod
ServiceMethods list of methods
func (ServiceMethods) Len ¶
func (f ServiceMethods) Len() int
func (ServiceMethods) Less ¶
func (f ServiceMethods) Less(i, j int) bool
func (ServiceMethods) Swap ¶
func (f ServiceMethods) Swap(i, j int)
Click to show internal directories.
Click to hide internal directories.