Move license from MIT to Apache 2.0. Add Makefile
This commit is contained in:
@ -116,7 +116,7 @@ func listToMap(list []string) map[string]struct{} {
|
||||
|
||||
func mapToList(m map[string]string) []string {
|
||||
list := []string{}
|
||||
for k, _ := range m {
|
||||
for k := range m {
|
||||
list = append(list, strings.ToLower(k))
|
||||
}
|
||||
sort.Strings(list)
|
||||
|
@ -461,7 +461,7 @@ func (i *item) String() string {
|
||||
case itemStringVal:
|
||||
v = "string"
|
||||
}
|
||||
return fmt.Sprintf("%s", v)
|
||||
return v
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -85,7 +85,6 @@ type Parser struct {
|
||||
input []byte // the string being scanned
|
||||
pos int
|
||||
items []item
|
||||
depth int
|
||||
err error
|
||||
}
|
||||
|
||||
@ -185,15 +184,6 @@ func (p *Parser) ignore() {
|
||||
p.pos = n
|
||||
}
|
||||
|
||||
func (p *Parser) current() item {
|
||||
return p.items[p.pos]
|
||||
}
|
||||
|
||||
func (p *Parser) eof() bool {
|
||||
n := p.pos + 1
|
||||
return p.items[n].typ == itemEOF
|
||||
}
|
||||
|
||||
func (p *Parser) peek(types ...itemType) bool {
|
||||
n := p.pos + 1
|
||||
if p.items[n].typ == itemEOF {
|
||||
@ -250,7 +240,7 @@ func (p *Parser) parseOp() (*Operation, error) {
|
||||
p.ignore()
|
||||
|
||||
for n := 0; n < 10; n++ {
|
||||
if p.peek(itemName) == false {
|
||||
if !p.peek(itemName) {
|
||||
break
|
||||
}
|
||||
|
||||
@ -275,7 +265,7 @@ func (p *Parser) parseQueryOp() (*Operation, error) {
|
||||
var err error
|
||||
|
||||
for n := 0; n < 10; n++ {
|
||||
if p.peek(itemName) == false {
|
||||
if !p.peek(itemName) {
|
||||
break
|
||||
}
|
||||
|
||||
@ -306,7 +296,7 @@ func (p *Parser) parseFields(fields []Field) ([]Field, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
if p.peek(itemName) == false {
|
||||
if !p.peek(itemName) {
|
||||
return nil, errors.New("expecting an alias or field name")
|
||||
}
|
||||
|
||||
@ -374,13 +364,13 @@ func (p *Parser) parseArgs(args []Arg) ([]Arg, error) {
|
||||
p.ignore()
|
||||
break
|
||||
}
|
||||
if p.peek(itemName) == false {
|
||||
if !p.peek(itemName) {
|
||||
return nil, errors.New("expecting an argument name")
|
||||
}
|
||||
args = append(args, Arg{Name: p.val(p.next())})
|
||||
arg := &args[(len(args) - 1)]
|
||||
|
||||
if p.peek(itemColon) == false {
|
||||
if !p.peek(itemColon) {
|
||||
return nil, errors.New("missing ':' after argument name")
|
||||
}
|
||||
p.ignore()
|
||||
@ -441,12 +431,12 @@ func (p *Parser) parseObj() (*Node, error) {
|
||||
break
|
||||
}
|
||||
|
||||
if p.peek(itemName) == false {
|
||||
if !p.peek(itemName) {
|
||||
return nil, errors.New("expecting an argument name")
|
||||
}
|
||||
nodeName := p.val(p.next())
|
||||
|
||||
if p.peek(itemColon) == false {
|
||||
if !p.peek(itemColon) {
|
||||
return nil, errors.New("missing ':' after Field argument name")
|
||||
}
|
||||
p.ignore()
|
||||
|
@ -7,13 +7,16 @@ import (
|
||||
|
||||
func TestCompile1(t *testing.T) {
|
||||
qc, _ := NewCompiler(Config{})
|
||||
qc.AddRole("user", "product", TRConfig{
|
||||
err := qc.AddRole("user", "product", TRConfig{
|
||||
Query: QueryConfig{
|
||||
Columns: []string{"id", "Name"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err := qc.Compile([]byte(`
|
||||
_, err = qc.Compile([]byte(`
|
||||
{ product(id: 15) {
|
||||
id
|
||||
name
|
||||
@ -26,13 +29,16 @@ func TestCompile1(t *testing.T) {
|
||||
|
||||
func TestCompile2(t *testing.T) {
|
||||
qc, _ := NewCompiler(Config{})
|
||||
qc.AddRole("user", "product", TRConfig{
|
||||
err := qc.AddRole("user", "product", TRConfig{
|
||||
Query: QueryConfig{
|
||||
Columns: []string{"ID"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err := qc.Compile([]byte(`
|
||||
_, err = qc.Compile([]byte(`
|
||||
query { product(id: 15) {
|
||||
id
|
||||
name
|
||||
@ -45,13 +51,16 @@ func TestCompile2(t *testing.T) {
|
||||
|
||||
func TestCompile3(t *testing.T) {
|
||||
qc, _ := NewCompiler(Config{})
|
||||
qc.AddRole("user", "product", TRConfig{
|
||||
err := qc.AddRole("user", "product", TRConfig{
|
||||
Query: QueryConfig{
|
||||
Columns: []string{"ID"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err := qc.Compile([]byte(`
|
||||
_, err = qc.Compile([]byte(`
|
||||
mutation {
|
||||
product(id: 15, name: "Test") {
|
||||
id
|
||||
|
Reference in New Issue
Block a user