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
Adding GQL prefix on important components #78
Conversation
I wonder if it's more idiomatic to name the types eg. |
+1 to @nicolaiunrein - I like the lowercase |
I might have under estimated the task 😂 but it's finally done! |
// types | ||
pub use crate::{ | ||
GqlContext, GqlData, GqlError, GqlFieldResult, GqlID, GqlInputValueResult, GqlQueryBuilder, | ||
GqlResult, GqlSchema, GqlValue, GqlVariables, | ||
}; | ||
|
||
// traits | ||
pub use crate::{ErrorExtensions, IntoGqlQueryBuilder, ResultExt, Type}; | ||
|
||
// procedural macros | ||
pub use crate::{ | ||
GqlEnum, GqlInputObject, GqlInterface, GqlObject, GqlScalar, GqlSimpleObject, GqlSubscription, | ||
GqlUnion, | ||
}; |
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.
Here's the prelude content
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.
Impressive amount of changes, awesome job! I just did a quick scroll-through of the code and had a couple questions.
pub struct GQLRequest(QueryBuilder); | ||
/// It's a wrapper of `GqlQueryBuilder`, you can use `GQLRequest::into_inner` unwrap it to `GqlQueryBuilder`. | ||
/// `async_graphql::IntoGqlQueryBuilderOpts` allows to configure extraction process. | ||
pub struct GQLRequest(GqlQueryBuilder); |
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.
Should GQLRequest
be updated too?
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.
yes I think we should change GQLResponse
and GQLRequest
.
There also another GQLError
in http module, but it's just a wrapper around &GqlError
to implement serialize, I guess we can implement Serialize
on GqlError
directly now
pub use async_graphql_derive::GqlScalar; | ||
|
||
mod deprecated { | ||
pub use super::GqlContext as Context; |
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.
Is there a way to annotate deprecations in rust?
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'll check that tomorrow :)
mod deprecated { | ||
pub use super::GqlContext as Context; | ||
pub use super::GqlContextBase as ContextBase; | ||
pub use super::GqlData as Data; | ||
pub use super::GqlDataSource as DataSource; | ||
pub use super::GqlEnum as Enum; | ||
pub use super::GqlError as Error; | ||
pub use super::GqlFieldResult as FieldResult; | ||
pub use super::GqlID as ID; | ||
pub use super::GqlInputObject as InputObject; | ||
pub use super::GqlInputValueResult as InputValueResult; | ||
pub use super::GqlInterface as Interface; | ||
pub use super::GqlObject as Object; | ||
pub use super::GqlQueryBuilder as QueryBuilder; | ||
pub use super::GqlResult as Result; | ||
pub use super::GqlScalar as Scalar; | ||
pub use super::GqlSchema as Schema; | ||
pub use super::GqlSimpleObject as SimpleObject; | ||
pub use super::GqlSubscription as Subscription; | ||
pub use super::GqlUnion as Union; | ||
pub use super::GqlValue as Value; | ||
pub use super::GqlVariables as Variables; | ||
} | ||
|
||
#[doc(hidden)] | ||
pub use deprecated::*; |
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.
Previous exports names are still available here, the whole project build and pass tests with this module disabled
The button |
When I woke up and saw this huge change, I was very excited and thank @IcanDivideBy0 for his efforts. But I also carefully considered the necessity of this Gql prefix. When they need to use prelude, I think in most cases it is So I hope we can discuss the necessity of this PR again. I'm so sorry, this is my mistake, I did not think about it yesterday, and here I solemnly apologize to @IcanDivideBy0. 🙇 |
Oh god, don't add prefix, we should use module. |
Currently, |
@phated Don't use |
@vkill you are missing the point of a prelude. We are expected to import * |
Renaming only the prelude export is my current thinking. 😁 crate::prelude::ID to crate::prelude::GqlID |
I feel really sorry too 😢. So if the prefix is not an option what about only exporting the (convenience-)traits in the prelude with the use async_graphql::{ self as gql, prelude::* };
#[gql::SimpleObject]
struct MyObject {
id: gql::ID,
any: gql::Any,
// ...
} That would mean we need to re-export missing frequently used types at the crate root level. Which we are doing already. |
How about this? use async_graphql::prelude::*;
#[GqlSimpleObject]
struct MyObject {
id: GqlID, // GQL_ID, GID
any: GqlAny,
// ...
} |
Besides the fact that it looks like Java 😆 I really don't think having two names point to the same type is a good idea. |
We shouldn't have 2 names, but we also cannot export very generic names from the prelude. How do you want to do both without these changes? |
The only solution then is not to include the types in the prelude. And only have traits there which are already generically implemented but required to be in the namespace. I think renaming certain types like |
I encountered the problem with Result last night while trying to do some upgrades. This is why I support the prefixed names. |
It's all fine really, I should have thought of it too :) I like the // I don't have strong opinion on this:
use async_graphql::prelude::*;
use async_graphql as gql;
// but...
#[GqlObject]
#[gql::Object] // I find this one more readable That being said I think we should keep some of the prefixed version: |
I'm using Adding a note on this in the Book/readme might be of some interrest |
I'm really happy to see you are not frustrated by this. 🍺 |
@IcanDivideBy0 I agree mostly on what you are saying. Two points though:
|
But I remember I read in the rust book that |
You're right, that's ugly too :/ |
Like |
That‘s what I‘m saying. |
Damn, naming things is HARD 😂 |
I also think prelude is necessary. In fact, the most important thing is to import the necessary traits. |
In fact, unless writing test code, I never import * |
The most fundamental reason is that the name |
Up until now |
I just thought |
Well I just tried to rename to
but it works fine without renaming in cargo.toml and using Edit: |
If that's the only two traits then I think it's not worth a prelude. I don't know how many people are actually using those. In Apollo there is a section in the book but I think there is trend in GraphQL towards returning result-enums much like in Rust to get typed errors. In fact that's what I started doing after implementing |
Let's put this issue aside for now. 😁 |
This what I have so far
I can't find the button to mark the PR as Draft, is that something that should be enabled at project level ?
what's missing:
GqlError
GqlInputValueResult
GqlQueryBuilder
GqlResult
GqlValue
GqlID