Fix issues with mutation SQL

This commit is contained in:
Vikram Rangnekar
2019-10-03 03:08:01 -04:00
parent bcc443bd59
commit a8ad87115e
16 changed files with 317 additions and 266 deletions

View File

@ -97,9 +97,23 @@ func (al *allowList) add(req *gqlReq) {
return
}
var query string
for i := 0; i < len(req.Query); i++ {
c := req.Query[i]
if c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' {
query = req.Query
break
} else if c == '{' {
query = "query " + req.Query
break
}
}
al.saveChan <- &allowItem{
uri: req.ref,
gql: req.Query,
gql: query,
vars: req.Vars,
}
}

View File

@ -133,7 +133,8 @@ e.g. db:migrate -+1
}
func initLog() *zerolog.Logger {
logger := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).
out := zerolog.ConsoleWriter{Out: os.Stderr}
logger := zerolog.New(out).
With().
Timestamp().
Caller().

View File

@ -292,7 +292,7 @@ func cmdDBStatus(cmd *cobra.Command, args []string) {
}
fmt.Println("status: ", status)
fmt.Println("version: %d of %d\n", mver, len(m.Migrations))
fmt.Printf("version: %d of %d\n", mver, len(m.Migrations))
fmt.Println("host: ", conf.DB.Host)
fmt.Println("database:", conf.DB.DBName)
}

View File

@ -1,9 +1,6 @@
package serv_test
import (
"testing"
)
/*
func TestErrorLineExtract(t *testing.T) {
tests := []struct {
source string
@ -102,3 +99,4 @@ error`,
}
}
}
*/

View File

@ -56,7 +56,7 @@ func gqlHash(b string, vars []byte) string {
}
}
if vars == nil {
if vars == nil || len(vars) == 0 {
return hex.EncodeToString(h.Sum(nil))
}

View File

@ -61,6 +61,39 @@ func TestRelaxHash2(t *testing.T) {
}
}
func TestRelaxHash3(t *testing.T) {
var v1 = `users {
id
email
picture: avatar
products(limit: 2, where: {price: {gt: 10}}) {
id
name
description
}
}`
var v2 = `
users {
id
email
picture: avatar
products(limit: 2, where: {price: {gt: 10}}) {
id
name
description
}
}
`
h1 := gqlHash(v1, nil)
h2 := gqlHash(v2, nil)
if strings.Compare(h1, h2) != 0 {
t.Fatal("Hashes don't match they should")
}
}
func TestRelaxHashWithVars1(t *testing.T) {
var q1 = `
products(