gql

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 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

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

func ParseUid

func ParseUid(xid string) (uint64, error)

Gets the uid corresponding

Types

type Arg

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

type AttrLang

type AttrLang struct {
	Attr  string
	Langs []string
}

type Count

type Count int

type Facets

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

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

Function holds the information about gql functions.

func (*Function) IsAggregator

func (f *Function) IsAggregator() bool

func (*Function) IsPasswordVerifier

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
	Cascade      bool
	IgnoreReflex bool
	Facets       *Facets
	FacetsFilter *FilterTree
	GroupbyAttrs []AttrLang
	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

func (gq *GraphQuery) DebugPrint(prefix string)

DebugPrint is useful for debugging.

type MathTree

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

func (m Mutation) HasOps() bool

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

type NQuad

type NQuad struct {
	*protos.NQuad
}

func (NQuad) CreateUidEdge

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

func (NQuad) CreateValueEdge

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

func (NQuad) ToDeletePredEdge

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

func (NQuad) ToEdgeUsing

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 Request

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

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

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

type Vars

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