Documentation
¶
Overview ¶
Package dql is responsible for lexing and parsing a GraphQL query/mutation.
Index ¶
- Constants
- func IsInequalityFn(name string) bool
- func ParseDQL(dqlQuery string) (*api.Request, error)
- func ParseMutation(mutation string) (req *api.Request, err error)
- func ParseUid(xid string) (uint64, error)
- func TypeValFrom(val *api.Value) types.Val
- type Arg
- type FacetOrder
- type FilterTree
- type Function
- type GraphQuery
- type GroupByAttr
- type MathTree
- type Mutation
- type NQuad
- func (nq NQuad) CreateUidEdge(subjectUid uint64, objectUid uint64) *pb.DirectedEdge
- func (nq NQuad) CreateValueEdge(subjectUid uint64) (*pb.DirectedEdge, error)
- func (nq NQuad) ToDeletePredEdge() (*pb.DirectedEdge, error)
- func (nq NQuad) ToEdgeUsing(newToUid map[string]uint64) (*pb.DirectedEdge, error)
- type RecurseArgs
- type Request
- type Result
- type ShortestPathArgs
- type VarContext
- type Vars
Constants ¶
const ( AnyVar = 0 UidVar = 1 ValueVar = 2 ListVar = 3 )
Variables ¶
This section is empty.
Functions ¶
func IsInequalityFn ¶
func ParseMutation ¶
ParseMutation parses a block into a mutation. Returns an object with a mutation or an upsert block with mutation, otherwise returns nil with an error.
Types ¶
type Arg ¶
type Arg struct {
Value string
IsValueVar bool // If argument is val(a), e.g. eq(name, val(a))
IsDQLVar bool
}
Arg stores an argument to a function.
type FacetOrder ¶
type FacetOrder struct {
Key string
Desc bool // true if ordering should be decending by this facet.
}
FacetOrder stores ordering for single facet key.
type FilterTree ¶
type FilterTree struct {
Op string
Child []*FilterTree
Func *Function
}
FilterTree is the result of parsing the filter directive. Either you can have `Op and Children` on non-leaf nodes Or Func at leaf nodes.
type Function ¶
type Function struct {
Attr string
Lang string // language of the attribute value
Name string // Specifies the name of the function.
Args []Arg // Contains the arguments of the function.
UID []uint64
NeedsVar []VarContext // If the function requires some variable
IsCount bool // gt(count(friends),0)
IsValueVar bool // eq(val(s), 5)
IsLenVar bool // eq(len(s), 5)
}
Function holds the information about dql functions.
func (*Function) IsAggregator ¶
IsAggregator returns true if the function name is an aggregation function.
func (*Function) IsPasswordVerifier ¶
IsPasswordVerifier returns true if the function name is "checkpwd".
type GraphQuery ¶
type GraphQuery struct {
UID []uint64
Attr string
Langs []string
Alias string
IsCount bool
IsInternal bool
IsGroupby bool
Var string
NeedsVar []VarContext
Func *Function
Expand string // Which variable to expand with.
Args map[string]string
// Query can have multiple sort parameters.
Order []*pb.Order
Children []*GraphQuery
Filter *FilterTree
MathExp *MathTree
Normalize bool
Recurse bool
RecurseArgs RecurseArgs
ShortestPathArgs ShortestPathArgs
Cascade []string
IgnoreReflex bool
Facets *pb.FacetParams
FacetsFilter *FilterTree
GroupbyAttrs []GroupByAttr
FacetVar map[string]string
FacetsOrder []*FacetOrder
// Used for ACL enabled queries to curtail results to only accessible params
AllowedPreds []string
// True for blocks that don't have a starting function and hence no starting nodes. They are
// used to aggregate and get variables defined in another block.
IsEmpty bool
// contains filtered or unexported fields
}
GraphQuery stores the parsed Query in a tree format. This gets converted to pb.y used query.SubGraph before processing the query.
func (*GraphQuery) DebugPrint ¶
func (gq *GraphQuery) DebugPrint(prefix string)
DebugPrint is useful for debugging.
type GroupByAttr ¶
GroupByAttr stores the arguments needed to process the @groupby directive.
type MathTree ¶
type MathTree struct {
Fn string
Var string
Const types.Val // This will always be parsed as a float value
Val *types.ShardedMap
Child []*MathTree
}
MathTree represents math operations in tree form for evaluation.
type Mutation ¶
type Mutation struct {
Cond string
Set []*api.NQuad
Del []*api.NQuad
AllowedPreds []string
Metadata *pb.Metadata
}
Mutation stores the strings corresponding to set and delete operations.
type NQuad ¶
NQuad is an alias for the NQuad type in the API protobuf library.
func (NQuad) CreateUidEdge ¶
func (nq NQuad) CreateUidEdge(subjectUid uint64, objectUid uint64) *pb.DirectedEdge
CreateUidEdge returns a Directed edge connecting the given subject and object UIDs.
func (NQuad) CreateValueEdge ¶
func (nq NQuad) CreateValueEdge(subjectUid uint64) (*pb.DirectedEdge, error)
CreateValueEdge returns a DirectedEdge with the given subject. The predicate, language, and facet values are derived from the NQuad.
func (NQuad) ToDeletePredEdge ¶
func (nq NQuad) ToDeletePredEdge() (*pb.DirectedEdge, error)
ToDeletePredEdge takes an NQuad of the form '* p *' and returns the equivalent directed edge. Returns an error if the NQuad does not have the expected form.
func (NQuad) ToEdgeUsing ¶
ToEdgeUsing determines the UIDs for the provided XIDs and populates the xidToUid map.
type RecurseArgs ¶
RecurseArgs stores the arguments needed to process the @recurse directive.
type Result ¶
type Result struct {
Query []*GraphQuery
QueryVars []*Vars
Schema *pb.SchemaRequest
}
Result struct contains the Query list, its corresponding variable use list and the mutation block.
func Parse ¶
Parse initializes and runs the lexer. It also constructs the GraphQuery subgraph from the lexed items.
func ParseWithNeedVars ¶
ParseWithNeedVars performs parsing of a query with given needVars.
The needVars parameter is passed in the case of upsert block. For example, when parsing the query block inside -
upsert {
query {
me(func: eq(email, "someone@gmail.com"), first: 1) {
v as uid
}
}
mutation {
set {
uid(v) <name> "Some One" .
uid(v) <email> "someone@gmail.com" .
}
}
}
The variable name v needs to be passed through the needVars parameter. Otherwise, an error is reported complaining that the variable v is defined but not used in the query block.
type ShortestPathArgs ¶
type ShortestPathArgs struct {
// From, To can have a uid or a uid function as the argument.
// 1. from: 0x01
// 2. from: uid(0x01)
// 3. from: uid(p) // a variable
From *Function
To *Function
}
ShortestPathArgs stores the arguments needed to process the shortest path query.
type VarContext ¶
VarContext stores information about the vars needed to complete a query.