query.Ref accepts a single argument for backwards compatibility with the Ref("collections/widget/123") format, which is serialized as { "@ref": "collections/widget/123" }.
The driver does this by just stuffing whatever is given to it as value => { "@ref": value }. This is a problem when the value provided is anything other than a string. The database expects FQL values to be... values! E.g. is illegal to even provide an expression that resolves to a string
Jira Ticket
Problem
query.Ref
accepts a single argument for backwards compatibility with theRef("collections/widget/123")
format, which is serialized as{ "@ref": "collections/widget/123" }
.The driver does this by just stuffing whatever is given to it as
value => { "@ref": value }
. This is a problem when the value provided is anything other than a string. The database expects FQL values to be... values! E.g. is illegal to even provide an expression that resolves to a stringThis error is correct behavior.
examples of other problematic queries
It is illegal wire protocol for FQL expressions to be in literal values, but is currently allowed
It there is also potential for folks to wrap a
value.Ref
into another layer of@ref
, which is problematic.Expected behavior
Using
query.Ref
with two arguments, it is expected that the arguments can be any expression 👍🏻But if only one argument is provided, we know it must be a string (again, not even an expression that could resolve to a string).
Solution
Assert that in the single-argument case the argument is a string, i.e.
typeof arguments[0] === 'string' || arguments[0] instanceof String
Testing
additional tests added