(it *lex.ItemIterator, curp *GraphQuery)
| 2641 | } |
| 2642 | |
| 2643 | func parseDirective(it *lex.ItemIterator, curp *GraphQuery) error { |
| 2644 | valid := true |
| 2645 | it.Prev() |
| 2646 | item := it.Item() |
| 2647 | if item.Typ == itemLeftCurl { |
| 2648 | // Ideally we should check that curp was created at current depth. |
| 2649 | valid = false |
| 2650 | } |
| 2651 | it.Next() |
| 2652 | |
| 2653 | isExpand := false |
| 2654 | if curp != nil && len(curp.Expand) > 0 { |
| 2655 | isExpand = true |
| 2656 | } |
| 2657 | // No directive is allowed on pb.subgraph like expand all (except type filters), |
| 2658 | // value variables, etc. |
| 2659 | if !valid || curp == nil || (curp.IsInternal && !isExpand) { |
| 2660 | return item.Errorf("Invalid use of directive.") |
| 2661 | } |
| 2662 | |
| 2663 | it.Next() |
| 2664 | item = it.Item() |
| 2665 | peek, err := it.Peek(1) |
| 2666 | if err != nil || item.Typ != itemName { |
| 2667 | return item.Errorf("Expected directive or language list") |
| 2668 | } |
| 2669 | |
| 2670 | if isExpand && item.Val != "filter" { |
| 2671 | return item.Errorf(errExpandType) |
| 2672 | } |
| 2673 | |
| 2674 | switch { |
| 2675 | case item.Val == "facets": // because @facets can come w/t '()' |
| 2676 | res, err := parseFacets(it) |
| 2677 | if err != nil { |
| 2678 | return err |
| 2679 | } |
| 2680 | switch { |
| 2681 | case res.f != nil: |
| 2682 | curp.FacetVar = res.vmap |
| 2683 | curp.FacetsOrder = res.facetsOrder |
| 2684 | if curp.Facets != nil { |
| 2685 | return item.Errorf("Only one facets allowed") |
| 2686 | } |
| 2687 | curp.Facets = res.f |
| 2688 | case res.ft != nil: |
| 2689 | if curp.FacetsFilter != nil { |
| 2690 | return item.Errorf("Only one facets filter allowed") |
| 2691 | } |
| 2692 | if res.ft.hasVars() { |
| 2693 | return item.Errorf( |
| 2694 | "variables are not allowed in facets filter.") |
| 2695 | } |
| 2696 | curp.FacetsFilter = res.ft |
| 2697 | default: |
| 2698 | return item.Errorf("Facets parsing failed.") |
| 2699 | } |
| 2700 | case item.Val == "cascade": |
no test coverage detected