You can store the nodes in the variable which matches the filter and then use that variable in from: and to:
Edit:
Here is the query example:
{
var(func: eq(name, "A")){
SOURCE as uid
}
var(func: eq(name, "L")){
TARGET as uid
}
path as shortest(from: uid(SOURCE), to: uid(TARGET)) {
friend
}
path(func: uid(path)) {
name
}
}