Documentation ¶
Index ¶
- Constants
- Variables
- func Generate(dir string, g Generator, options ...Option) error
- func IsCustomType(typeName string) bool
- type Dependency
- type Generator
- type GraphQLObject
- type GraphQLObjectField
- type GraphQLObjectMethod
- type GraphQLObjectType
- type InputDependency
- type InterfaceDependency
- type Option
- type RootDependency
- type ScalarDependency
- type StructDependency
- type TypeHelper
Constants ¶
const ( RootQueryObjectName = "Query" RootMutationObjectName = "Mutation" )
const ( BasicTypeID = "ID" BasicTypeString = "String" BasicTypeInteger = "Int" BasicTypeFloat = "Float" BasicTypeBoolean = "Boolean" BuiltInTypeAny = "Any" BuiltInTypeMap = "Map" BuiltInTypeTime = "Time" )
const ( GraphQLObjectTypeType = GraphQLObjectType("type") GraphQLObjectTypeInterface = GraphQLObjectType("interface") GraphQLObjectTypeInput = GraphQLObjectType("input") GraphQLObjectTypeScalar = GraphQLObjectType("scalar") GraphQLObjectTypeEnum = GraphQLObjectType("enum") )
Variables ¶
var ( ErrNoQuery = fmt.Errorf("no graphql root Query is found. type Query struct {...} is required") ErrSyntax = fmt.Errorf("cannot parse package") )
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") )
var (
ErrGoModNotFound = errors.New("go.mod file is not found in the directory and it's parents")
)
var (
ErrUnsupportedType = fmt.Errorf("unsupported type")
)
Functions ¶
func IsCustomType ¶
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 {...}
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 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.