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

Added IpAddress GraphQL custom scalar for IP addresses #365

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

henry0715-dev
Copy link
Contributor

@henry0715-dev henry0715-dev commented Dec 5, 2024

Close #353

Nic and NicInput that are not used as additional content have been
removed.

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 89.23077% with 21 lines in your changes missing coverage. Please review.

Project coverage is 71.00%. Comparing base (09b682a) to head (4a008ea).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/graphql/ip_location.rs 0.00% 17 Missing ⚠️
src/graphql.rs 66.66% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #365      +/-   ##
==========================================
+ Coverage   70.53%   71.00%   +0.46%     
==========================================
  Files          67       67              
  Lines       14416    14545     +129     
==========================================
+ Hits        10168    10327     +159     
+ Misses       4248     4218      -30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@henry0715-dev henry0715-dev force-pushed the henry/scalar_ip_address branch from ca314ad to 34e9b45 Compare December 5, 2024 05:47
@sehkone sehkone requested a review from msk December 12, 2024 23:22
@@ -651,13 +643,13 @@ impl From<types::Account> for Account {
}
}

fn strings_to_ip_addrs(ip_addrs: &[String]) -> Result<Vec<IpAddr>, AddrParseError> {
fn strings_to_ip_addrs(ip_addrs: &[IpAddress]) -> Vec<IpAddr> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this method name makes sense anymore.

.map(|ip_addr| ip_addr.parse::<IpAddr>())
.collect::<Result<Vec<_>, _>>()?;
.map(|ip_addr| ip_addr.0)
.collect::<Vec<IpAddr>>();
ip_addrs.sort();
Copy link
Contributor

Choose a reason for hiding this comment

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

sort_unstable would be a better option.

ip_addrs.sort();
Ok(ip_addrs)
ip_addrs
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to remove duplicate values, although it is not directly related to this issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added ip_addrs.dedup(); to remove duplicates.

CHANGELOG.md Outdated
@@ -7,6 +7,13 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Added `IpAddress` GraphQL scalar for IP addresses.
Copy link
Contributor

Choose a reason for hiding this comment

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

From the user's perspective, they would want to know the constraints this type enforces for validation, as well as the errors the API returns when a value doesn't meet those constraints. Therefore, I think it would be better to mention that the API returns a specific error message if the value cannot be parsed into IpAddr.

Copy link
Contributor

@sehkone sehkone Dec 13, 2024

Choose a reason for hiding this comment

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

The correct term is "custom scalar", not just "scalar".

Copy link
Contributor

Choose a reason for hiding this comment

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

To save your time, I let you know the error message when "abc" is input:

Failed to parse "IpAddress": Invalid IP address: abc (occurred while parsing "[IpAddress!]")

@henry0715-dev henry0715-dev force-pushed the henry/scalar_ip_address branch 3 times, most recently from 6b2c23a to be8ed94 Compare December 13, 2024 01:10
@henry0715-dev
Copy link
Contributor Author

@sehkone
Thank you for the PR comment.
The contents have been changed.
Thank you.

CHANGELOG.md Outdated
Comment on lines 16 to 19
- The API returns a specific error message if the value cannot be parsed
into `IpAddr`.
For example: `Failed to parse "IpAddress": Invalid IP address: abc(occurred
while parsing "[IpAddress!]")`
Copy link
Contributor

Choose a reason for hiding this comment

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

For clarity, I suggest:

The API returns the following error message when a value cannot be parsed as an IpAddr: Failed to parse "IpAddress": Invalid IP address: abc (occurred while parsing "[IpAddress!]"), where "abc" is the input.

@henry0715-dev henry0715-dev force-pushed the henry/scalar_ip_address branch 2 times, most recently from 9e4c4b7 to 0e77ccb Compare December 16, 2024 03:42
CHANGELOG.md Outdated
Comment on lines 18 to 20
- The API returns the following error message when a value cannot be parsed as
an `IpAddr`: `Failed to parse "IpAddress": Invalid IP address: abc (occurred
while parsing "[IpAddress!]")`, where "abc" is the input.
Copy link
Contributor

Choose a reason for hiding this comment

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

When a quoted message overflows like this, we can use backticks to create a block instead.

 - The API returns the following error message when a value cannot be parsed as
   an `IpAddr` (e.g., when "abc" is given):
   ```
   Failed to parse "IpAddress": Invalid IP address: abc (occurred while parsing
   "[IpAddress!]")
   ```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was no error in CI, so I thought it was an acceptable phrase.
We will apply it according to your suggestion.
Thank you.

@henry0715-dev henry0715-dev force-pushed the henry/scalar_ip_address branch 2 times, most recently from d8e66e5 to aa99349 Compare December 17, 2024 00:45
@sehkone
Copy link
Contributor

sehkone commented Dec 17, 2024

@henry0715-dev, this encounters Clippy warnings. Could you take care of them?

@henry0715-dev henry0715-dev force-pushed the henry/scalar_ip_address branch 3 times, most recently from 7d9cf9b to 19556a4 Compare December 18, 2024 00:13
@henry0715-dev
Copy link
Contributor Author

@henry0715-dev, this encounters Clippy warnings. Could you take care of them?

I have completed the fixes for the Clippy warnings.

CHANGELOG.md Outdated
Comment on lines 14 to 23
- Added `IpAddress` GraphQL custom scalar for IP addresses.

- Applied it to the GraphQL APIs `ipLocation`, `ipLocationList`,
`insertAccount`, `updateAccount`, `insertSamplingPolicy`, and
`updateSamplingPolicy`.
- The API returns the following error message when a value cannot be parsed as
an `IpAddr` (e.g., when "abc" is given):

```text
Failed to parse "IpAddress": Invalid IP address: abc (occurred while
parsing "[IpAddress!]")
```
Copy link
Contributor

@sehkone sehkone Dec 18, 2024

Choose a reason for hiding this comment

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

I think markdownlink requires an empty line before a backtick block, and the editor automatically inserts an empty line 15. However, these empty lines don't look good. Therefore, I suggest:

- Added `IpAddress` GraphQL custom scalar for IP addresses
  - Applied it to the GraphQL APIs `ipLocation`, `ipLocationList`,
    `insertAccount`, `updateAccount`, `insertSamplingPolicy`, and
    `updateSamplingPolicy`.
  - The API returns the following error message when a value cannot be parsed as
    an `IpAddr` (e.g., when "abc" is given):
    <!-- markdownlint-disable MD031 -->
    ```text
    Failed to parse "IpAddress": Invalid IP address: abc (occurred while
    parsing "[IpAddress!]")
    ```

I believe this could prevent the failure caused by markdownlint.

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of what I told above, it would better to update the .markdownlint.yaml file as follows:

---
MD024:
  siblings_only: true
MD031: false

Then, we can change the above part of CHANGELOG like:

- Added `IpAddress` GraphQL custom scalar for IP addresses
  - Applied it to the GraphQL APIs `ipLocation`, `ipLocationList`,
    `insertAccount`, `updateAccount`, `insertSamplingPolicy`, and
    `updateSamplingPolicy`.
  - The API returns the following error message when a value cannot be parsed as
    an `IpAddr` (e.g., when "abc" is given):
    ```text
    Failed to parse "IpAddress": Invalid IP address: abc (occurred while
    parsing "[IpAddress!]")
    ```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's been changed.
Thanks for your help.

@henry0715-dev henry0715-dev force-pushed the henry/scalar_ip_address branch from 19556a4 to 4493e0c Compare December 19, 2024 00:08
Close #353

`Nic` and `NicInput` that are not used as additional content have been
removed.
@henry0715-dev henry0715-dev force-pushed the henry/scalar_ip_address branch from 4493e0c to 4a008ea Compare December 19, 2024 00:09
@sehkone
Copy link
Contributor

sehkone commented Dec 19, 2024

@henry0715-dev

I modified the commit title according to what has changed, so as to include the term "custom." And, I also modified the body to mention the issue number at the bottom, which is more conventional. I just wanted to let you know.

@sehkone
Copy link
Contributor

sehkone commented Dec 19, 2024

@henry0715-dev,

I also changed the commit title to use an imperative verb instead of a past tense verb according to the rule.

@sehkone sehkone merged commit d4fe319 into main Dec 19, 2024
10 checks passed
@sehkone sehkone deleted the henry/scalar_ip_address branch December 19, 2024 01:01
@henry0715-dev henry0715-dev changed the title Added IpAddress GraphQL scalar for IP addresses Added IpAddress GraphQL custom scalar for IP addresses Dec 19, 2024
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.

Introduce a custom GraphQL scalar for IP addresses
3 participants