question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

core: ConfigArgService.validateRequiredFields() fails checking ShippingEligibilityChecker with required arg

See original GitHub issue

It seems saving a shipping method with an assigned ShippingEligibilityChecker which has at least one arg with required:true and containing a type which can’t be parsed by JSON.parse() always fails with the configurable-argument-is-required error.

I think the problem is the validateRequiredFields method, which checks the value with:

let val: unknown;
if (inputArg) {
    try {
        val = JSON.parse(inputArg?.value);
    } catch (e) {
        // ignore
    }
}
if (val == null) {
    throw new UserInputError('error.configurable-argument-is-required', {
        name,
    });
}

As inputArg.value is a string in my case, JSON.parse(inputArg?.value) throws an error (which is ignored), val == null evaluates to true and the validation fails.

Possible types seem to be from ConfigArgType: 'string' | 'int' | 'float' | 'boolean' | 'datetime' | 'ID'. So my proposition is to change the error-evaluation to something like !inputArg || inputArg.value === null || input.value === "" to cover all types (not exactly sure on this, peer review please: are all type covered correctly?).

Code here: config-arg.service.ts#L91

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
michaelbromleycommented, May 3, 2021

That’s true, but purely for the purpose of checking for “emptiness” in required fields, I think an empty string check is sufficient.

If we then want to also validate the actual data of each field, then that’s another issue and would warrant its own feature request.

0reactions
Wanztwurstcommented, May 3, 2021

I think Int, Float, Bool and Null work with JSON.parse(), the others are basically strings and should be checked if they are not empty.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vendure/config-arg.service.ts at master - GitHub
A headless GraphQL ecommerce framework for the modern web - vendure/config-arg.service.ts at master · vendure-ecommerce/vendure.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found