generator

package
v0.8.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Mutation     rootName = "Mutation"
	Query        rootName = "Query"
	Subscription rootName = "Subscription"
)
View Source
const (
	ScalarInt     = "Int"
	ScalarFloat   = "Float"
	ScalarString  = "String"
	ScalarBoolean = "Boolean"
	ScalarID      = "ID"
)
View Source
const (
	DefaultExtension = "graphql"
)

Variables

This section is empty.

Functions

func CamelCase

func CamelCase(s string) string

CamelCase returns the CamelCased name. If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case. There is a remote possibility of this rewrite causing a name collision, but it's so remote we're prepared to pretend it's nonexistent - since the C++ generator lowercases names, it's extremely unlikely to have two fields with different capitalizations. In short, _my_field_name_2 becomes XMyFieldName_2.

func CamelCaseSlice

func CamelCaseSlice(elem []string) string

CamelCaseSlice is like CamelCase, but the argument is a slice of strings to be joined with "_".

func CreateDescriptorsFromProto

func CreateDescriptorsFromProto(req *pluginpb.CodeGeneratorRequest) (descs []*desc.FileDescriptor, err error)

func GetRequestType

func GetRequestType(rpcOpts *gqlpb.Rpc, svcOpts *gqlpb.Svc) gqlpb.Type

func GoCamelCase

func GoCamelCase(s string) string

GoCamelCase camel-cases a protobuf name for use as a Go identifier.

If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case.

func GraphqlFieldOptions

func GraphqlFieldOptions(opts proto.Message) *gqlpb.Field

func GraphqlMethodOptions

func GraphqlMethodOptions(opts proto.Message) *gqlpb.Rpc

func GraphqlOneofOptions

func GraphqlOneofOptions(opts proto.Message) *gqlpb.Oneof

func GraphqlServiceOptions

func GraphqlServiceOptions(opts proto.Message) *gqlpb.Svc

func IsAny

func IsAny(o *desc.MessageDescriptor) bool

TODO maybe not compare by strings

func IsEmpty

func IsEmpty(o *desc.MessageDescriptor) bool

same isEmpty but for mortals

func SplitCamelCase

func SplitCamelCase(src string) (entries []string)

Split splits the camelcase word and returns a list of words. It also supports digits. Both lower camel case and upper camel case are supported. For more info please check: http://en.wikipedia.org/wiki/CamelCase

Examples

"" =>                     [""]
"lowercase" =>            ["lowercase"]
"Class" =>                ["Class"]
"MyClass" =>              ["My", "Class"]
"MyC" =>                  ["My", "C"]
"HTML" =>                 ["HTML"]
"PDFLoader" =>            ["PDF", "Loader"]
"AString" =>              ["A", "String"]
"SimpleXMLParser" =>      ["Simple", "XML", "Parser"]
"vimRPCPlugin" =>         ["vim", "RPC", "Plugin"]
"GL11Version" =>          ["GL", "11", "Version"]
"99Bottles" =>            ["99", "Bottles"]
"May5" =>                 ["May", "5"]
"BFG9000" =>              ["BFG", "9000"]
"BöseÜberraschung" =>     ["Böse", "Überraschung"]
"Two  spaces" =>          ["Two", "  ", "spaces"]
"BadUTF8\xe2\xe2\xa1" =>  ["BadUTF8\xe2\xe2\xa1"]

Splitting rules

  1. If string is not valid UTF-8, return it without splitting as single item array.
  2. Assign all unicode characters into one of 4 sets: lower case letters, upper case letters, numbers, and all other characters.
  3. Iterate through characters of string, introducing splits between adjacent characters that belong to different sets.
  4. Iterate through array of split strings, and if a given string is upper case: if subsequent string is lower case: move last character of upper case string to beginning of lower case string

func ToLowerFirst

func ToLowerFirst(s string) string

Types

type Callstack

type Callstack interface {
	Push(entry interface{})
	Pop(entry interface{})
	Has(entry interface{}) bool
	Free()
	Len() int
}

func NewCallstack

func NewCallstack() Callstack

type FieldDescriptor

type FieldDescriptor struct {
	*ast.FieldDefinition
	*desc.FieldDescriptor
	// contains filtered or unexported fields
}

func (*FieldDescriptor) GetType

func (f *FieldDescriptor) GetType() *ObjectDescriptor

type FieldDescriptorList

type FieldDescriptorList []*FieldDescriptor

func (FieldDescriptorList) AsGraphql

func (fl FieldDescriptorList) AsGraphql() (dl []*ast.FieldDefinition)

type GoRef

type GoRef interface {
	FindGoField(field string) *protogen.Field
}

func NewGoRef

func NewGoRef(req *pluginpb.CodeGeneratorRequest) (GoRef, error)

type MethodDescriptor

type MethodDescriptor struct {
	*desc.ServiceDescriptor
	*desc.MethodDescriptor

	*ast.FieldDefinition
	// contains filtered or unexported fields
}

func (*MethodDescriptor) AsGraphql

func (m *MethodDescriptor) AsGraphql() *ast.FieldDefinition

func (*MethodDescriptor) GetInput

func (m *MethodDescriptor) GetInput() *ObjectDescriptor

func (*MethodDescriptor) GetOutput

func (m *MethodDescriptor) GetOutput() *ObjectDescriptor

type ObjectDescriptor

type ObjectDescriptor struct {
	*ast.Definition
	desc.Descriptor
	// contains filtered or unexported fields
}

func (*ObjectDescriptor) AsGraphql

func (o *ObjectDescriptor) AsGraphql() *ast.Definition

func (*ObjectDescriptor) GetFields

func (o *ObjectDescriptor) GetFields() []*FieldDescriptor

func (*ObjectDescriptor) IsInput

func (o *ObjectDescriptor) IsInput() bool

func (*ObjectDescriptor) IsMessage

func (o *ObjectDescriptor) IsMessage() bool

type Registry

type Registry interface {
	FindMethodByName(name string) *desc.MethodDescriptor
	FindObjectByName(name string) *desc.MessageDescriptor

	// Todo maybe find a better way to get ast definition
	FindObjectByFullyQualifiedName(fqn string) (*desc.MessageDescriptor, *ast.Definition)
	FindFieldByName(msg desc.Descriptor, name string) *desc.FieldDescriptor
}

func NewRegistry

func NewRegistry(files SchemaDescriptorList) Registry

type RootDefinition

type RootDefinition struct {
	*ast.Definition

	Parent *SchemaDescriptor
	// contains filtered or unexported fields
}

func NewRootDefinition

func NewRootDefinition(name rootName, parent *SchemaDescriptor) *RootDefinition

func (*RootDefinition) Methods

func (r *RootDefinition) Methods() []*MethodDescriptor

func (*RootDefinition) UniqueName

type SchemaDescriptor

type SchemaDescriptor struct {
	*ast.Schema

	FileDescriptors []*desc.FileDescriptor
	// contains filtered or unexported fields
}

func NewSchemaDescriptor

func NewSchemaDescriptor(genServiceDesc bool, goref GoRef) *SchemaDescriptor

func (*SchemaDescriptor) AsGraphql

func (s *SchemaDescriptor) AsGraphql() *ast.Schema

func (*SchemaDescriptor) CreateObjects

func (s *SchemaDescriptor) CreateObjects(d desc.Descriptor, input bool) (obj *ObjectDescriptor, err error)

func (*SchemaDescriptor) GetMutation

func (s *SchemaDescriptor) GetMutation() *RootDefinition

func (*SchemaDescriptor) GetQuery

func (s *SchemaDescriptor) GetQuery() *RootDefinition

func (*SchemaDescriptor) GetSubscription

func (s *SchemaDescriptor) GetSubscription() *RootDefinition

func (*SchemaDescriptor) Objects

func (s *SchemaDescriptor) Objects() []*ObjectDescriptor

type SchemaDescriptorList

type SchemaDescriptorList []*SchemaDescriptor

func NewSchemas

func NewSchemas(files []*desc.FileDescriptor, mergeSchemas, genServiceDesc bool, goref GoRef) (schemas SchemaDescriptorList, _ error)

func (SchemaDescriptorList) AsGraphql

func (s SchemaDescriptorList) AsGraphql() (astSchema []*ast.Schema)

func (SchemaDescriptorList) GetForDescriptor

func (s SchemaDescriptorList) GetForDescriptor(file *protogen.File) *SchemaDescriptor

type ServiceAndMethod

type ServiceAndMethod struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL