Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw on missing parameters #22

Open
rexxars opened this issue Oct 18, 2020 · 1 comment
Open

Throw on missing parameters #22

rexxars opened this issue Oct 18, 2020 · 1 comment

Comments

@rexxars
Copy link
Member

rexxars commented Oct 18, 2020

I expected the following to throw an error:

let query = `name == $name`
let tree = parse(query)
let value = await evaluate(tree, {dataset: [], params: {}})
let data = await value.get()

...but it actually results in true

I think it'd be better if undefined parameters would throw an error:

Param $name referenced, but not provided
@ryaninvents
Copy link

@rexxars The current behavior actually seems right to me. Check out this example which might help explain:

let {parse, evaluate} = require("groq-js")
let query = `constructor.name == $name`
let tree = parse(query)
let value = await evaluate(tree, {dataset: [], params: {$name: 'Array'}})
let data = await value.get();

Note that your query does not have a top-level projection * [...], so you're effectively asking whether [].name == undefined, which is true. If you set query to * [name == $name] then you get an empty array back which also matches expectations.

Your suggestion definitely seems like it would be useful, so it would be nice to have a strictParameters: true setting on the options object in evaluate which would trigger errors for missing params.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants