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

Strip undefined values from URL params; disallow some forms for params #88

Merged
merged 1 commit into from
Nov 18, 2022

Conversation

glasser
Copy link
Member

@glasser glasser commented Nov 9, 2022

Being able to specify params as a single record object is very convenient, but it becomes inconvenient when some parameters are optional. Previously you could not use the record object syntax if a parameter is optional. Now you can use that syntax and we will strip undefined values, like JSON.stringify.

Previously we allowed all of the various forms of data that can be passed to new URLSearchParams() (and in fact just passed what we got directly to there). Implementing this undefined-stripping for all of the forms (like "arbitrary iterable object of two-element arrays") would be a lot of code copied from the DOM implementation, but not stripping undefined from the other forms would be inconsistent. So we change to only allow the record form (which is the only form that our docs show) plus providing URLSearchParams yourself; if you used one of the other forms you can just add a new URLSearchParams() to your code.

See the changeset entry for more details.

Fixes #24.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 9, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Being able to specify `params` as a single record object is very
convenient, but it becomes inconvenient when some parameters are
optional. Previously you could not use the record object syntax if a
parameter is optional. Now you can use that syntax and we will strip
undefined values, like `JSON.stringify`.

Previously we allowed all of the various forms of data that can be
passed to `new URLSearchParams()` (and in fact just passed what we got
directly to there). Implementing this undefined-stripping for all of the
forms (like "arbitrary iterable object of two-element arrays") would be
a lot of code copied from the DOM implementation, but *not* stripping
undefined from the other forms would be inconsistent. So we change to
*only* allow the record form (which is the only form that our docs show)
plus providing `URLSearchParams` yourself; if you used one of the other
forms you can just add a `new URLSearchParams()` to your code.

See the changeset entry for more details.

Fixes #24.
Copy link
Member

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very pleased with this outcome!

@glasser glasser merged commit 2c3dbd0 into main Nov 18, 2022
@glasser glasser deleted the glasser/param-undefined branch November 18, 2022 00:34
@github-actions github-actions bot mentioned this pull request Nov 18, 2022
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 this pull request may close these issues.

RESTDataSource serializes undefined values as "undefined"
2 participants