Comments (27)
In fact this concerns all ID conversions. If that is something desirable I will give it a shot. Should not be breaking existing implementations because all types implement From
and Into
themselves.
from async-graphql.
Brilliant! @IcanDivideBy0 I much prefer your solution! Didn't consider removing Display
for those types an option.
from async-graphql.
Since you have this requirement, I think this feature makes sense. I'll add it now.😁
from async-graphql.
Cool. I will see what I can with error_extensions.md on monday.
from async-graphql.
Correct me if I'm wrong but this feels unnecessary complicated.
By removing the impl std::fmt::Display for Cursor
, we can then add
impl<T> From<T> for Cursor
where
T: std::fmt::Display
{
fn from(value: T) -> Self {
Cursor(value.to_string())
}
}
which removes the need for the ToGraphQLCursor
trait ?
Same goes for ID, I don't think those types needs to implement display, Debug should be enough for general purpose
from async-graphql.
@sunli829 you probably forgot to remove the impl fmt::Display for ID
? or any other From
where the type already impl fmt::Display
?
from async-graphql.
I use Uuids as well and I think it is quite common. Maybe implement it for T: Into<Uuid>
so that it works well with the new type pattern?
from async-graphql.
@nicolaiunrein I think that would be a good idea. When converting between ID and Cursor, I need to do id.to_string().into()
which isn't ideal.
from async-graphql.
@nicolaiunrein How is this feature going to be implemented?😁
from async-graphql.
Sorry, I am pretty busy at the moment with other projects. I will look at it tomorrow or on monday.
from async-graphql.
Well, we can't implement generic From
implementation due to conflicting implementations but I would suggest to add two traits:
pub trait ToGraphqlCursor {
fn to_graphql_cursor(&self) -> Cursor;
}
impl<T> ToGraphqlCursor for T
where
T: std::fmt::Display,
{
fn to_graphql_cursor(&self) -> Cursor {
Cursor(self.to_string())
}
}
and
pub trait ToGraphqlID {
fn to_graphql_id(self) -> ID;
}
impl<T> ToGraphqlID for T
where
T: std::fmt::Display,
{
fn to_graphql_id(self) -> ID {
ID(self.to_string())
}
}
which when imported give you two methods to_graphql_cursor
and to_graphql_id
on anything that implements std::fmt::Display
and allows you to instead of calling id.to_string().into()
just id.to_graphql_cursor
. Now this can be quite handy when you implement your own ID type as well:
pub struct MyID(Uuid);
impl std::fmt::Display for MyID { ... }
// somewhere else
let id = my_id.to_graphql_id();
What do you think?
from async-graphql.
I think it's good, it's really easier to use. 😁
In addition, can you add this error_extensions.md when you are free? I think you know more about this than me.
I have been working on a new parser for the past few days and it is now complete. You can upgrade to 1.11.0 to see if there is a problem with your current project.
Thanks again, ToGraphqlID
and ToGraphqlCursor
I will add later. 😁
from async-graphql.
Thank you. 😁
from async-graphql.
@nicolaiunrein It has been implemented in version 1.11.1.
from async-graphql.
from async-graphql.
In the end it's even simpler
let cursor: Cursor = "foo".into();
let my_uuid = uuid::Uuid::parse_str("936DA01F9ABD4d9d80C702AF85C822A8").unwrap();
let cursor: Cursor = my_uuid.into();
from async-graphql.
@IcanDivideBy0 Seems to require generic specialization?
36 | impl<T: Display> From for ID {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate core
:
- impl std::convert::From for T;
from async-graphql.
@nicolaiunrein Is this the reason?
from async-graphql.
Sorry, you actually answered the question. 😊@nicolaiunrein
from async-graphql.
@sunli829 let me send the PR
from async-graphql.
Weird things, you can compile and pass. I want to see how your modification differs from mine.😳
from async-graphql.
Thanks, I understand, because ID also implements Display, so it will conflict. I think the implementation of Display can indeed be removed, which is even simpler. Thank you for your PR. 😁
from async-graphql.
@nicolaiunrein ID
and Cursor
now properly implements From<fmt::Display>
on master.
@sunli829 I let you decide if this worth a release :)
from async-graphql.
Let me do it, just change the version number. 😂
from async-graphql.
In addition, can you add this error_extensions.md when you are free? I think you know more about this than me.
@sunli829 I wrote something but it got quite lengthy. Please review.
from async-graphql.
Thank you so much. I translated the Chinese version later. 🍺
from async-graphql.
@nicolaiunrein The documentation is too good, much better than mine. 😂
from async-graphql.
Related Issues (20)
- How can we use methods outside of graphql request context? HOT 3
- Stack overflow at `Schema::new()` when generic type's method returns self
- Consider disable the default features in Axum
- Better documentation HOT 3
- Async-graphql actix_web subscriptions don't work HOT 1
- Share data between guard and resolver HOT 2
- Add #[graphql(optional)] for fields (provde less boilerplate and more correctness) HOT 2
- async-graph-axum 7.0.0 only works with axum 0.7.0
- Cannot use string to publish to async channel HOT 3
- How to extract the query name in middleware HOT 3
- Disable introspection, returns null in __typename--Dynamic Schema
- How to view the graphql endpoint in Apollo studio explorer? HOT 2
- How do you create a model that doesn't have hardcoded values? HOT 1
- Adjust `#[allow(clippy::all)]` in macro expansions to not override `clippy::disallowed_macros` HOT 2
- Unintentional breaking change, removing `#[async_trait]`, in patch release HOT 2
- Access the value of "variable" arguments (`Value::Variable`)
- Has anyone does any benchmarks because im getting extremely poor results and I do not know why? HOT 8
- Get mutable referenece to the global data defined in the `Context` or `Schema` HOT 1
- Confusing `unused_mut` warning in `#[Object]` HOT 8
- How to handle both directions of one-to-many relation in federated graph
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-graphql.