gql

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2017 License: AGPL-3.0, Apache-2.0 Imports: 11 Imported by: 0

README

Comparing the old and new methods, we find that using slice makes the parsing 20% faster on average than using channels. Also, using slices allows the parser to backtrack and peek the tokens which couldn't be done using channels as each token can only be consumed once.

Name                              unit    Old     New     Improvement
----------------------------------------------------------------------
Benchmark_Filters-4               ns/op   14007   9634    31 %
Benchmark_Geq-4                   ns/op   11701   8602    26 %
Benchmark_Date-4                  ns/op   11687   8630    26 %
Benchmark_directors-4             ns/op   18663   14201   23 %
Benchmark_Filters_parallel-4      ns/op   6486    5015    22 %
Benchmark_Movies-4                ns/op   16097   12807   20 %
Benchmark_directors_parallel-4    ns/op   8766    6966    20 %
Benchmark_Mutation-4              ns/op   5167    4155    19 %
Benchmark_Movies_parallel-4       ns/op   7537    6151    18 %
Benchmark_Date_parallel-4         ns/op   5462    4515    17 %
Benchmark_Geq_parallel-4          ns/op   5390    4485    16 %
Benchmark_Mutation_parallel-4     ns/op   2326    2161    07 %
Benchmark_Mutation1000-4          ns/op   549428  512851  06 %
Benchmark_Mutation1000_parallel-4 ns/op   261785  254911  02 %

Documentation

Overview

Package gql is responsible for lexing and parsing a GraphQL query/mutation.

Index

Constants

View Source
const (
	ANY_VAR   = 0
	UID_VAR   = 1
	VALUE_VAR = 2
	LIST_VAR  = 3
)

Variables

View Source
var (
	ErrInvalidUID = errors.New("UID has to be greater than one.")
)

Functions

func ParseMutation added in v0.9.0

func ParseMutation(mutation string) (*protos.Mutation, error)

func ParseUid added in v0.8.2

func ParseUid(xid string) (uint64, error)

Gets the uid corresponding

Types

type Arg added in v0.8.2

type Arg struct {
	Value        string
	IsValueVar   bool // If argument is val(a)
	IsGraphQLVar bool
}

type Count added in v0.8.2

type Count int

type Facets added in v0.7.3

type Facets struct {
	AllKeys bool
	Keys    []string // should be in sorted order.
}

Facet holds the information about gql Facets (edge key-value pairs).

type FilterTree added in v0.7.0

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 added in v0.7.0

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)
}

Function holds the information about gql functions.

func (*Function) IsAggregator added in v0.7.3

func (f *Function) IsAggregator() bool

func (*Function) IsPasswordVerifier added in v0.7.3

func (f *Function) IsPasswordVerifier() bool

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        []*protos.Order
	Children     []*GraphQuery
	Filter       *FilterTree
	MathExp      *MathTree
	Normalize    bool
	Recurse      bool
	RecurseArgs  RecurseArgs
	Cascade      bool
	IgnoreReflex bool
	Facets       *Facets
	FacetsFilter *FilterTree
	GroupbyAttrs []GroupByAttr
	FacetVar     map[string]string
	FacetOrder   string
	FacetDesc    bool

	// Indicates whether count of uids is requested as a child node. If
	// there is a child with count() attr, then this is not empty for the parent.
	// If there is an alias, this has the alias value, else its value is count.
	UidCount 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 internally used query.SubGraph before processing the query.

func (*GraphQuery) DebugPrint added in v0.7.0

func (gq *GraphQuery) DebugPrint(prefix string)

DebugPrint is useful for debugging.

type GroupByAttr added in v0.9.2

type GroupByAttr struct {
	Attr  string
	Alias string
	Langs []string
}

type MathTree added in v0.8.2

type MathTree struct {
	Fn    string
	Var   string
	Const types.Val // This will always be parsed as a float value
	Val   map[uint64]types.Val
	Child []*MathTree
}

type Mutation

type Mutation struct {
	Set     []*protos.NQuad
	Del     []*protos.NQuad
	DropAll bool
	Schema  string
}

Mutation stores the strings corresponding to set and delete operations.

func (Mutation) HasOps added in v0.8.2

func (m Mutation) HasOps() bool

HasOps returns true iff the mutation has at least one non-empty part.

type NQuad added in v0.8.2

type NQuad struct {
	*protos.NQuad
}

func (NQuad) CreateUidEdge added in v0.8.2

func (nq NQuad) CreateUidEdge(subjectUid uint64, objectUid uint64) *protos.DirectedEdge

func (NQuad) CreateValueEdge added in v0.8.2

func (nq NQuad) CreateValueEdge(subjectUid uint64) (*protos.DirectedEdge, error)

func (NQuad) ToDeletePredEdge added in v0.8.2

func (nq NQuad) ToDeletePredEdge() (*protos.DirectedEdge, error)

func (NQuad) ToEdgeUsing added in v0.8.2

func (nq NQuad) ToEdgeUsing(newToUid map[string]uint64) (*protos.DirectedEdge, error)

ToEdgeUsing determines the UIDs for the provided XIDs and populates the xidToUid map.

type RecurseArgs added in v0.9.2

type RecurseArgs struct {
	Depth     uint64
	AllowLoop bool
}

type Request added in v0.8.2

type Request struct {
	Str       string
	Variables map[string]string
	// We need this so that we don't try to do JSON.Unmarshal for request coming
	// from Go client, as we directly get the variables in a map.
	// TODO: Remove this flag.
	Http bool
}

type Result added in v0.7.2

type Result struct {
	Query     []*GraphQuery
	QueryVars []*Vars
	Schema    *protos.SchemaRequest
}

Result struct contains the Query list, its corresponding variable use list and the mutation block.

func Parse

func Parse(r Request) (res Result, rerr error)

Parse initializes and runs the lexer. It also constructs the GraphQuery subgraph from the lexed items.

type VarContext added in v0.8.2

type VarContext struct {
	Name string
	Typ  int //  1 for UID vars, 2 for value vars
}

type Vars added in v0.7.2

type Vars struct {
	Defines []string
	Needs   []string
}

Vars struct contains the list of variables defined and used by a query block.

Jump to

Keyboard shortcuts

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