graphql

package
v0.0.0-...-7c7107e Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RootQueryObjectName    = "Query"
	RootMutationObjectName = "Mutation"
)
View Source
const (
	BasicTypeID      = "ID"
	BasicTypeString  = "String"
	BasicTypeInteger = "Int"
	BasicTypeFloat   = "Float"
	BasicTypeBoolean = "Boolean"

	BuiltInTypeAny  = "Any"
	BuiltInTypeMap  = "Map"
	BuiltInTypeTime = "Time"
)
View Source
const (
	GraphQLObjectTypeType      = GraphQLObjectType("type")
	GraphQLObjectTypeInterface = GraphQLObjectType("interface")
	GraphQLObjectTypeInput     = GraphQLObjectType("input")
	GraphQLObjectTypeScalar    = GraphQLObjectType("scalar")
	GraphQLObjectTypeEnum      = GraphQLObjectType("enum")
)

Variables

View Source
var (
	ErrNoQuery = fmt.Errorf("no graphql root Query is found. type Query struct {...} is required")
	ErrSyntax  = fmt.Errorf("cannot parse package")
)
View Source
var (
	ErrNoMethodsInQuery        = fmt.Errorf("root Query struct doesn't have any methods")
	ErrFirstParamMustBeContext = fmt.Errorf("the first parameter must be context.Context")
	ErrInvalidReturnSignature  = fmt.Errorf("the return signature should be (something, error)")
	ErrSecondReturnMustBeError = fmt.Errorf("the second return value must be error")
)
View Source
var (
	ErrGoModNotFound = errors.New("go.mod file is not found in the directory and it's parents")
)
View Source
var (
	ErrUnsupportedType = fmt.Errorf("unsupported type")
)

Functions

func Generate

func Generate(dir string, g Generator, options ...Option) error

func IsCustomType

func IsCustomType(typeName string) bool

Types

type Dependency

type Dependency interface {
	ToGraphQLObject(helper TypeHelper) (*GraphQLObject, []Dependency, error)
	IsCustomType() bool
}

Dependency is an object to identify a dependency on types used in target package and it is a source of truth for the corresponding GraphQL object

type Generator

type Generator interface {
	Generate([]GraphQLObject) error
}

type GraphQLObject

type GraphQLObject struct {
	Name       string
	IsNode     bool
	GoModel    string
	ObjectType GraphQLObjectType // type, input, scalar, enum
	Fields     []GraphQLObjectField
	Methods    []GraphQLObjectMethod
	Values     []string // enum
}

GraphQLObject represents type Name {...}

func Build

func Build(src string, options ...Option) ([]GraphQLObject, error)

Build analyzes the src package and returns a list of GraphQLObject

type GraphQLObjectField

type GraphQLObjectField struct {
	Name            string
	Type            string
	Nullable        bool
	IsArray         bool
	ElementNullable bool
	NestDepth       int
	IsCustomType    bool
}

GraphQLObjectField represents a field in GraphQLObject

type GraphQLObjectMethod

type GraphQLObjectMethod struct {
	Name        string
	Parameters  []GraphQLObjectField
	ReturnValue GraphQLObjectField
}

GraphQLObjectMethod represents a method in GraphQLType

type GraphQLObjectType

type GraphQLObjectType string

type InputDependency

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

InputDependency is a wrapper of dependencies derived from function parameters It will generate `input MyTypeInput {}` instead of `type MyType {...}` and mark all the dependencies underlying this depedency as InputDependency

func (*InputDependency) IsCustomType

func (d *InputDependency) IsCustomType() bool

func (*InputDependency) String

func (d *InputDependency) String() string

func (*InputDependency) ToGraphQLObject

func (d *InputDependency) ToGraphQLObject(helper TypeHelper) (*GraphQLObject, []Dependency, error)

type InterfaceDependency

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

InterfaceDependency is an implementation of Dependency of `type X interface {...}`

func (*InterfaceDependency) IsCustomType

func (d *InterfaceDependency) IsCustomType() bool

func (*InterfaceDependency) String

func (d *InterfaceDependency) String() string

func (*InterfaceDependency) ToGraphQLObject

func (d *InterfaceDependency) ToGraphQLObject(helper TypeHelper) (*GraphQLObject, []Dependency, error)

ToGraphQLObject returns a corresponding &GraphQLObject and extract new dependencies found in the types.

type Option

type Option func(*builder) *builder

func RootQueryName

func RootQueryName(str string) Option

type RootDependency

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

RootDependency is an implementation of a special struct dependency for

`type Query struct {...}` or `type Mutation struct {...}`

func (*RootDependency) IsCustomType

func (d *RootDependency) IsCustomType() bool

func (*RootDependency) String

func (d *RootDependency) String() string

func (*RootDependency) ToGraphQLObject

func (d *RootDependency) ToGraphQLObject(helper TypeHelper) (*GraphQLObject, []Dependency, error)

type ScalarDependency

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

ScalarDependency is an implementation of Dependency of `type X BasicType` where BasicType is one of scalar types. This model genereats:

scalar X @goModel(model: "path.to.package.X")

func (*ScalarDependency) IsCustomType

func (d *ScalarDependency) IsCustomType() bool

func (*ScalarDependency) String

func (d *ScalarDependency) String() string

func (*ScalarDependency) ToGraphQLObject

func (d *ScalarDependency) ToGraphQLObject(helper TypeHelper) (*GraphQLObject, []Dependency, error)

type StructDependency

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

StructDependency is an implementation of Dependency of `type X struct {...}`

func (*StructDependency) IsCustomType

func (d *StructDependency) IsCustomType() bool

func (*StructDependency) String

func (d *StructDependency) String() string

func (*StructDependency) ToGraphQLObject

func (d *StructDependency) ToGraphQLObject(helper TypeHelper) (*GraphQLObject, []Dependency, error)

ToGraphQLObject returns a corresponding &GraphQLObject and extract new dependencies found in the types.

type TypeHelper

type TypeHelper interface {
	IsContext(t types.Type) bool
	IsError(t types.Type) bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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