ParseWithNeedVars performs parsing of a query with given needVars. The needVars parameter is passed in the case of upsert block. For example, when parsing the query block inside - upsert { query { me(func: eq(email, "someone@gmail.com"), first: 1) { v as uid } } mutatio
(r Request, needVars []string)
| 639 | // The variable name v needs to be passed through the needVars parameter. Otherwise, an error |
| 640 | // is reported complaining that the variable v is defined but not used in the query block. |
| 641 | func ParseWithNeedVars(r Request, needVars []string) (res Result, rerr error) { |
| 642 | query := r.Str |
| 643 | vmap := convertToVarMap(r.Variables) |
| 644 | |
| 645 | var lexer lex.Lexer |
| 646 | lexer.Reset(query) |
| 647 | lexer.Run(lexTopLevel) |
| 648 | if err := lexer.ValidateResult(); err != nil { |
| 649 | return res, err |
| 650 | } |
| 651 | |
| 652 | var qu *GraphQuery |
| 653 | it := lexer.NewIterator() |
| 654 | fmap := make(fragmentMap) |
| 655 | for it.Next() { |
| 656 | item := it.Item() |
| 657 | switch item.Typ { |
| 658 | case itemOpType: |
| 659 | switch item.Val { |
| 660 | case "mutation": |
| 661 | return res, item.Errorf("Mutation block no longer allowed.") |
| 662 | case "schema": |
| 663 | if res.Schema != nil { |
| 664 | return res, item.Errorf("Only one schema block allowed ") |
| 665 | } |
| 666 | if res.Query != nil { |
| 667 | return res, item.Errorf("Schema block is not allowed with query block") |
| 668 | } |
| 669 | if res.Schema, rerr = getSchema(it); rerr != nil { |
| 670 | return res, rerr |
| 671 | } |
| 672 | case "fragment": |
| 673 | // TODO(jchiu0): This is to be done in ParseSchema once it is ready. |
| 674 | fnode, rerr := getFragment(it) |
| 675 | if rerr != nil { |
| 676 | return res, rerr |
| 677 | } |
| 678 | fmap[fnode.Name] = fnode |
| 679 | case "query": |
| 680 | if res.Schema != nil { |
| 681 | return res, item.Errorf("Schema block is not allowed with query block") |
| 682 | } |
| 683 | if qu, rerr = getVariablesAndQuery(it, vmap); rerr != nil { |
| 684 | return res, rerr |
| 685 | } |
| 686 | res.Query = append(res.Query, qu) |
| 687 | } |
| 688 | case itemLeftCurl: |
| 689 | if qu, rerr = getQuery(it); rerr != nil { |
| 690 | return res, rerr |
| 691 | } |
| 692 | res.Query = append(res.Query, qu) |
| 693 | case itemName: |
| 694 | it.Prev() |
| 695 | if qu, rerr = getQuery(it); rerr != nil { |
| 696 | return res, rerr |
| 697 | } |
| 698 | res.Query = append(res.Query, qu) |
no test coverage detected