fillShortestPathVars reads value of the uid variable from mp map and fills it into From and To parameters.
(mp map[string]varValue)
| 1765 | // fillShortestPathVars reads value of the uid variable from mp map and fills it into From and To |
| 1766 | // parameters. |
| 1767 | func (sg *SubGraph) fillShortestPathVars(mp map[string]varValue) error { |
| 1768 | // The uidVar.Uids can be nil or have an empty uid list if the variable didn't |
| 1769 | // return any uids. This would mean sg.Params.From or sg.Params.To is 0 and the |
| 1770 | // query would return an empty result. |
| 1771 | |
| 1772 | if sg.Params.ShortestPathArgs.From != nil && len(sg.Params.ShortestPathArgs.From.NeedsVar) > 0 { |
| 1773 | fromVar := sg.Params.ShortestPathArgs.From.NeedsVar[0].Name |
| 1774 | uidVar, ok := mp[fromVar] |
| 1775 | if !ok { |
| 1776 | return errors.Errorf("value of from var(%s) should have already been populated", |
| 1777 | fromVar) |
| 1778 | } |
| 1779 | if uidVar.Uids != nil && len(uidVar.Uids.Uids) > 0 { |
| 1780 | if len(uidVar.Uids.Uids) > 1 { |
| 1781 | return errors.Errorf("from variable(%s) should only expand to 1 uid", fromVar) |
| 1782 | } |
| 1783 | sg.Params.From = uidVar.Uids.Uids[0] |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | if sg.Params.ShortestPathArgs.To != nil && len(sg.Params.ShortestPathArgs.To.NeedsVar) > 0 { |
| 1788 | toVar := sg.Params.ShortestPathArgs.To.NeedsVar[0].Name |
| 1789 | uidVar, ok := mp[toVar] |
| 1790 | if !ok { |
| 1791 | return errors.Errorf("value of to var(%s) should have already been populated", |
| 1792 | toVar) |
| 1793 | } |
| 1794 | if uidVar.Uids != nil && len(uidVar.Uids.Uids) > 0 { |
| 1795 | if len(uidVar.Uids.Uids) > 1 { |
| 1796 | return errors.Errorf("to variable(%s) should only expand to 1 uid", toVar) |
| 1797 | } |
| 1798 | sg.Params.To = uidVar.Uids.Uids[0] |
| 1799 | } |
| 1800 | } |
| 1801 | return nil |
| 1802 | } |
| 1803 | |
| 1804 | // fillVars reads the value corresponding to a variable from the map mp and stores it inside |
| 1805 | // SubGraph. This value is then later used for execution of the SubGraph. |