Apollo-link-rest: 🐛 Query throws an error when parameter value is falsy (0, false, null, undefined)

Created on 26 Feb 2018  ·  4Comments  ·  Source: apollographql/apollo-link-rest

I'm getting the following error when passing a 0 value on a variable.
Error: Network error: Missing params to run query, specify it in the query params or use an export directive

If instead I use a string it works.

I've debugged the code and found the issue in the replaceParam function which is checking for !value where (I guess 😃) should be checking for null/undefined values.

var replaceParam = function (endpoint, name, value) {
    if (!value || !name) {
        return endpoint;
    }
    return endpoint.replace(":" + name, value);
};

I'll send a PR

bug 🐛

All 4 comments

Good catch, the typescript way for this is

if (value != null || name != null)

I look forward to merging your PR! :)

Please add a unit test so we catch any future regressions.

It's clear for me that 0 and false represent real values and undefined a missing one, but not sure about null values.
What do you think @fbartho?

@gaguirre Sorry I missed your reply! I shipped your code as is. I think we probably should support passing null in, and letting a different layer deal with it.

Have you seen the pathBuilder function? That's the user provided code that could care about the distinction between undefined and null, or could actually use null usefully.

Do you think we should open a new ticket to track that case?

@fbartho no problem! I agree that null is a valid case and I've considered that in the PR.
The only missing thing was test cases for the undefined case, but the behavior I think is right: will throw a _Missing parameter_ error. 👍

Was this page helpful?
0 / 5 - 0 ratings