Comments (18)
Excited to see this! Please let me know if I can help in any way
from async-graphql.
I tried it and it worked.
Here is the new interface definition.
#[Interface]
trait Node: Send + Sync {
async fn id(&self) -> i32;
}
struct MyObj;
#[Implement]
impl Node for MyObj {
async fn id(&self) -> i32 {
10
}
}
#[Object]
impl MyObj {
async fn value(&self) -> i32 {
20
}
}
struct Query;
#[Object]
impl Query {
async fn my_obj(&self) -> NodeInterface<MyObj> {
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NodeInterface is generated automatically, which may cause the auto-completion of the ide to fail.
MyObj.into()
}
}
The following is a query that can be executed correctly.
{
id
... on Node {
id1: id
}
... on MyObj {
value
}
}
from async-graphql.
Trait object are the only way to solve this problem, but I don't have a computer right now, so I'll think about it later.
from async-graphql.
Wow! This looks great!!!!!
from async-graphql.
I couldn't implement such a feature because lose the type information if converted to a trait object.😭
#[Object]
impl Query {
async fn my_obj(&self) -> Vec<NodeInterface<???>> {
vec![MyObjA.into(), MyObjB.into()]
}
}
from async-graphql.
I suppose NodeInterface is a struct?
I don’t think this compiles but wouldn’t that be the correct signature?
#[Object]
impl Query {
async fn my_obj(&self) -> Vec<NodeInterface<dyn Node>> {
vec![MyObjA.into(), MyObjB.into()]
}
}
from async-graphql.
I need to think again about whether this generic parameter is really necessary.
from async-graphql.
And we are unable able to do this?
struct Query;
#[Object]
impl Query {
async fn my_obj(&self) -> impl Node {
MyObj{}
}
}
from async-graphql.
No, this is just type MyObj, which is missing the interface information, so need a wrapper.
from async-graphql.
Correct me if I’m wrong but I think under the hood impl Query gets converted to a trait? and returning impl Trait is not supported on trait methods.
But what about utilising the flatten attribute inside the generated Interface somehow to inline existing fields?
from async-graphql.
No, this is just type MyObj, which is missing the interface information, so need a wrapper.
If you impl Node for MyObj
, why would it not fulfill the trait implementation type signature?
from async-graphql.
Cannot use a trait object, which is a run-time type, and generate Schema requires static type.
So let's go back to #38, is it worth sacrificing a little type safety for more flexible interface definitions?
from async-graphql.
The generic list should solve all the problems. I'm still thinking about it.
from async-graphql.
This is impossible, so I'm going to close it right now.
from async-graphql.
I think #38 is the best solution, removing many of the limitations of function forwarding and making it easy to use. Panic at startup is acceptable.
from async-graphql.
I discussed this at my presentation and everyone wanted static type checking. It takes a long time to start up the server to see that you made a mistake.
from async-graphql.
Let's keep the original design the same.😂
from async-graphql.
I'll try again.
from async-graphql.
Related Issues (20)
- 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
- Question: How to get server to send ping messages on subscriptions? HOT 2
- Parsing multiple operations in a file HOT 1
- Non nullable variables should allow default values HOT 3
- Object with single skipped field but with ComplexObject HOT 2
- As using proxy type
- Using flatten inside an impl with no other fields causes a compile error
- Subscription with MPSC receiver in context data
- Reduce clippy noise from #[Object] macro HOT 2
- Guard trait lifetime HOT 1
- Using generics with both SimpleObject and InputObject as field in output type fails HOT 1
- Subscription Authentication
- Stack overflow after upgrade to 7.0.2 HOT 5
- Does async-graphql validate responses?
- Error reading data from ExtensionContext after upgrade to 7.0.3 HOT 1
- Create a general error formateer
- Allow flatten on arguments HOT 1
- External fields not getting generated in SDL
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.