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

In interpolator, applyRule function does not replace an argument if "dataToReplace" is 0 #5817

Closed
4 tasks
WeizhengSap opened this issue Aug 9, 2023 · 0 comments · Fixed by #6037
Closed
4 tasks

Comments

@WeizhengSap
Copy link

WeizhengSap commented Aug 9, 2023

Issue workflow progress

Progress of the issue based on the
Contributor Workflow

Make sure to fork this template and run yarn generate in the terminal.

Please make sure Mesh package versions under package.json matches yours.

  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

In Interpolator.js, function applyRule has:

  applyRule(str, rule, data = {}) {
    const dataToReplace = this.applyData(rule.key, data);
    if (dataToReplace) {
      return str.replace(rule.replace, this.applyModifiers(rule.modifiers, dataToReplace, data));
    } else if (rule.alternativeText) {
      return str.replace(
        rule.replace,
        this.applyModifiers(rule.modifiers, rule.alternativeText, data),
      );
    }

    const defaultModifier = this.applyModifiers(rule.modifiers, rule.key, data);
    if (defaultModifier === rule.key) {
      return str.replace(rule.replace, '');
    }
    return str.replace(rule.replace, defaultModifier);
  }

So, when dataToReplace is 0, str.replace(rule.replace, '') will be returned.

To Reproduce Steps to reproduce the behavior:

parse string /users/{args.userId}/carts/{args.cartId}/entries/{args.entryNumber}, data is

{ 
  args: {
     cartId: '00001017',
     entryNumber: 0,
     userId: 'current'
  }
}

expected result is: /users/current/carts/00001017/entries/0
but what we got is: /users/current/carts/00001017/entries

Expected behavior

Environment:

  • OS:
  • @graphql-mesh/...:
  • NodeJS:

Additional context

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

Successfully merging a pull request may close this issue.

1 participant