query

package
v0.386.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIs

func APIs(asts []*parser.AST) (res []*parser.APINode)

func ActionSortableFieldNames

func ActionSortableFieldNames(action *parser.ActionNode) ([]string, error)

ActionSortableFieldNames returns the field names of the @sortable attribute. If no @sortable attribute exists, an empty slice is returned.

func AllHasManyRelationFields

func AllHasManyRelationFields(asts []*parser.AST) []*parser.FieldNode

AllHasManyRelationFields provides a list of all the fields in the schema which are of type Model and which are repeated.

func CompositeUniqueFields added in v0.370.0

func CompositeUniqueFields(model *parser.ModelNode, attribute *parser.AttributeNode) []*parser.FieldNode

CompositeUniqueFields returns the model's fields that make up a composite unique attribute

func Enum

func Enum(asts []*parser.AST, name string) *parser.EnumNode

func Enums

func Enums(asts []*parser.AST) (res []*parser.EnumNode)

func ExcludeBuiltInFields

func ExcludeBuiltInFields(f *parser.FieldNode) bool

func ExcludeBuiltInModels

func ExcludeBuiltInModels(m *parser.ModelNode) bool

func Field

func Field(model *parser.ModelNode, name string) *parser.FieldNode

Field provides the field of the given name from the given model. (Or nil).

func FieldGetAttribute

func FieldGetAttribute(field *parser.FieldNode, name string) *parser.AttributeNode

FieldGetAttribute returns the attribute of the given name on the given field, or nil, to signal that it doesn't have one.

func FieldHasAttribute

func FieldHasAttribute(field *parser.FieldNode, name string) bool

func FieldIsInCompositeUnique added in v0.370.0

func FieldIsInCompositeUnique(model *parser.ModelNode, field *parser.FieldNode) bool

FieldIsInCompositeUnique returns true if a field is part of a composite unique attribute

func FieldIsUnique

func FieldIsUnique(field *parser.FieldNode) bool

func FieldsInModelOfType

func FieldsInModelOfType(model *parser.ModelNode, requiredType string) []string

FieldsInModelOfType provides a list of the field names for the fields in the given model, that have the given type name.

func IsBelongsToModelField added in v0.369.1

func IsBelongsToModelField(asts []*parser.AST, model *parser.ModelNode, field *parser.FieldNode) bool

IsBelongsToModelField returns true if the given field refers to a model in which this is in a 1:1 relationship and where the other model owns the relationship. This means the other model's field will have @unique defined and also the other model is where the foreign key will exist.

func IsEnum

func IsEnum(asts []*parser.AST, name string) bool

func IsForeignKey

func IsForeignKey(asts []*parser.AST, model *parser.ModelNode, field *parser.FieldNode) bool

func IsHasManyModelField

func IsHasManyModelField(asts []*parser.AST, field *parser.FieldNode) bool

IsHasManyModelField returns true if the given field can be inferred to be a field that references another model, and is denoted as being REPEATED.

func IsHasOneModelField

func IsHasOneModelField(asts []*parser.AST, field *parser.FieldNode) bool

IsHasOneModelField returns true if the given field can be inferred to be a field that references another model, and is not denoted as being repeated.

func IsIdentityModel

func IsIdentityModel(asts []*parser.AST, name string) bool

func IsMessage

func IsMessage(asts []*parser.AST, name string) bool

func IsModel

func IsModel(asts []*parser.AST, name string) bool

func IsUserDefinedType

func IsUserDefinedType(asts []*parser.AST, name string) bool

func Jobs

func Jobs(asts []*parser.AST) (ret []*parser.JobNode)

func Message

func Message(asts []*parser.AST, name string) *parser.MessageNode

Message finds the message in the schema of the given name. Or nil.

func MessageNames

func MessageNames(asts []*parser.AST) (ret []string)

func Messages

func Messages(asts []*parser.AST) (ret []*parser.MessageNode)

func Model

func Model(asts []*parser.AST, name string) *parser.ModelNode

func ModelActions

func ModelActions(model *parser.ModelNode, filters ...ModelActionFilter) (res []*parser.ActionNode)

func ModelAttributes

func ModelAttributes(model *parser.ModelNode) (res []*parser.AttributeNode)

func ModelCreateActions

func ModelCreateActions(model *parser.ModelNode, filters ...ModelActionFilter) (res []*parser.ActionNode)

ModelCreateActions returns all the actions in the given model, which are create-type actions.

func ModelField

func ModelField(model *parser.ModelNode, name string) *parser.FieldNode

func ModelFieldNames

func ModelFieldNames(model *parser.ModelNode) []string

func ModelFields

func ModelFields(model *parser.ModelNode, filters ...ModelFieldFilter) (res []*parser.FieldNode)

func ModelFieldsOfType added in v0.369.1

func ModelFieldsOfType(model *parser.ModelNode, typeName string) []*parser.FieldNode

FieldsInModelOfType provides a list of the field names for the fields in the given model, that have the given type name.

func ModelNames

func ModelNames(asts []*parser.AST, filters ...ModelFilter) (res []string)

func Models

func Models(asts []*parser.AST, filters ...ModelFilter) (res []*parser.ModelNode)

func PrimaryKey

func PrimaryKey(modelName string, asts []*parser.AST) *parser.FieldNode

PrimaryKey gives you the name of the primary key field on the given model. It favours fields that have the AttributePrimaryKey attribute, but drops back to the id field if none have.

func RelationAttributeValue added in v0.369.1

func RelationAttributeValue(attr *parser.AttributeNode) (field string, ok bool)

RelationAttributeValue attempts to retrieve the value of the @relation attribute

func ResolveInputField

func ResolveInputField(asts []*parser.AST, input *parser.ActionInputNode, parentModel *parser.ModelNode) (field *parser.FieldNode)

ResolveInputField returns the field that the input's type references

func ResolveInputType

func ResolveInputType(asts []*parser.AST, input *parser.ActionInputNode, parentModel *parser.ModelNode, action *parser.ActionNode) string

ResolveInputType returns a string represention of the type of the given input.

If the input is explicitly typed using a built in type that type is returned

example: (foo: Text) -> Text is returned

If `input` refers to a field on the parent model (or a nested field) then the type of that field is returned

example: (foo: some.field) -> The type of `field` on the model referrred to by `some` is returned

func Roles

func Roles(asts []*parser.AST) (res []*parser.RoleNode)

func SubscriberNames added in v0.368.0

func SubscriberNames(asts []*parser.AST) (res []string)

SubscriberNames gets a unique slice of subscriber names which have been defined in the schema.

func UserDefinedTypes

func UserDefinedTypes(asts []*parser.AST) (res []string)

func ValidOneToHasMany added in v0.369.1

func ValidOneToHasMany(belongsTo *parser.FieldNode, hasMany *parser.FieldNode) bool

Determine if pair form a valid 1:M pattern where, for example:

belongsTo:  author Author @relation(posts)
hasMany:    posts Post[]

func ValidUniqueOneToHasOne added in v0.369.1

func ValidUniqueOneToHasOne(hasOne *parser.FieldNode, belongsTo *parser.FieldNode) bool

Determine if pair form a valid 1:! pattern where, for example:

hasOne:  	  passport Passport @unique
belongsTo:    person Person

Types

type ModelActionFilter

type ModelActionFilter func(a *parser.ActionNode) bool

type ModelFieldFilter

type ModelFieldFilter func(f *parser.FieldNode) bool

type ModelFilter

type ModelFilter func(m *parser.ModelNode) bool

type Relationship added in v0.369.1

type Relationship struct {
	Model *parser.ModelNode
	Field *parser.FieldNode
}

func GetRelationship added in v0.369.1

func GetRelationship(asts []*parser.AST, currentModel *parser.ModelNode, currentField *parser.FieldNode) (*Relationship, error)

GetRelationship will return the related model and field on that model which forms the relationship.

func GetRelationshipCandidates added in v0.369.1

func GetRelationshipCandidates(asts []*parser.AST, model *parser.ModelNode, field *parser.FieldNode) []*Relationship

GetRelationshipCandidates will find all the candidates relationships that can be formed with the related model. Each relationship field should only have exactly 1 candidate, otherwise there are incorrectly defined relationships in the schema.

Jump to

Keyboard shortcuts

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