-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
Codecov ReportAttention: Patch coverage is
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. |
ca314ad
to
34e9b45
Compare
src/graphql/account.rs
Outdated
@@ -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> { |
There was a problem hiding this comment.
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.
src/graphql/account.rs
Outdated
.map(|ip_addr| ip_addr.parse::<IpAddr>()) | ||
.collect::<Result<Vec<_>, _>>()?; | ||
.map(|ip_addr| ip_addr.0) | ||
.collect::<Vec<IpAddr>>(); | ||
ip_addrs.sort(); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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!]")
6b2c23a
to
be8ed94
Compare
@sehkone |
CHANGELOG.md
Outdated
- 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!]")` |
There was a problem hiding this comment.
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.
9e4c4b7
to
0e77ccb
Compare
CHANGELOG.md
Outdated
- 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. |
There was a problem hiding this comment.
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!]")
```
There was a problem hiding this comment.
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.
d8e66e5
to
aa99349
Compare
@henry0715-dev, this encounters Clippy warnings. Could you take care of them? |
7d9cf9b
to
19556a4
Compare
I have completed the fixes for the Clippy warnings. |
CHANGELOG.md
Outdated
- 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!]") | ||
``` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!]")
```
There was a problem hiding this comment.
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.
19556a4
to
4493e0c
Compare
Close #353 `Nic` and `NicInput` that are not used as additional content have been removed.
4493e0c
to
4a008ea
Compare
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. |
I also changed the commit title to use an imperative verb instead of a past tense verb according to the rule. |
IpAddress
GraphQL scalar for IP addressesIpAddress
GraphQL custom scalar for IP addresses
Close #353
Nic
andNicInput
that are not used as additional content have beenremoved.