Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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