Fix bug with deep-nested queries

This commit is contained in:
Vikram Rangnekar 2019-12-30 01:17:37 -05:00
parent 482203ba05
commit 343589c3bd
3 changed files with 20 additions and 11 deletions

View File

@ -303,10 +303,18 @@ func (s *DBSchema) SetRel(child, parent string, rel *DBRel) error {
sp := strings.ToLower(flect.Singularize(parent)) sp := strings.ToLower(flect.Singularize(parent))
pp := strings.ToLower(flect.Pluralize(parent)) pp := strings.ToLower(flect.Pluralize(parent))
s.rm[sc][sp] = rel if _, ok := s.rm[sc][sp]; !ok {
s.rm[sc][pp] = rel s.rm[sc][sp] = rel
s.rm[pc][sp] = rel }
s.rm[pc][pp] = rel if _, ok := s.rm[sc][pp]; !ok {
s.rm[sc][pp] = rel
}
if _, ok := s.rm[pc][sp]; !ok {
s.rm[pc][sp] = rel
}
if _, ok := s.rm[pc][pp]; !ok {
s.rm[pc][pp] = rel
}
return nil return nil
} }

View File

@ -151,8 +151,6 @@ func nestedUpdateRelColumnsMap(item kvitem) map[string]struct{} {
sk := make(map[string]struct{}, len(item.items)) sk := make(map[string]struct{}, len(item.items))
for _, v := range item.items { for _, v := range item.items {
//fmt.Println(">>", v._ctype > 0 && v.relCP.Type == RelOneToMany, v.relCP.Right.Col)
if v._ctype > 0 && v.relCP.Type == RelOneToMany { if v._ctype > 0 && v.relCP.Type == RelOneToMany {
sk[v.relCP.Right.Col] = struct{}{} sk[v.relCP.Right.Col] = struct{}{}
} }

View File

@ -253,7 +253,6 @@ func (com *Compiler) Compile(query []byte, role string) (*QCode, error) {
func (com *Compiler) compileQuery(qc *QCode, op *Operation, role string) error { func (com *Compiler) compileQuery(qc *QCode, op *Operation, role string) error {
id := int32(0) id := int32(0)
parentID := int32(-1)
if len(op.Fields) == 0 { if len(op.Fields) == 0 {
return errors.New("invalid graphql no query found") return errors.New("invalid graphql no query found")
@ -275,7 +274,8 @@ func (com *Compiler) compileQuery(qc *QCode, op *Operation, role string) error {
for i := range op.Fields { for i := range op.Fields {
if op.Fields[i].ParentID == -1 { if op.Fields[i].ParentID == -1 {
st.Push(op.Fields[i].ID) val := op.Fields[i].ID | (-1 << 16)
st.Push(val)
} }
} }
@ -288,7 +288,10 @@ func (com *Compiler) compileQuery(qc *QCode, op *Operation, role string) error {
return fmt.Errorf("selector limit reached (%d)", maxSelectors) return fmt.Errorf("selector limit reached (%d)", maxSelectors)
} }
fid := st.Pop() val := st.Pop()
fid := val & 0xFFFF
parentID := (val >> 16) & 0xFFFF
field := &op.Fields[fid] field := &op.Fields[fid]
if _, ok := com.bl[field.Name]; ok { if _, ok := com.bl[field.Name]; ok {
@ -357,8 +360,8 @@ func (com *Compiler) compileQuery(qc *QCode, op *Operation, role string) error {
} }
if len(f.Children) != 0 { if len(f.Children) != 0 {
parentID = s.ID val := f.ID | (s.ID << 16)
st.Push(f.ID) st.Push(val)
continue continue
} }