Comments (10)
I have found a way to implement this feature and am trying it out.
#[Object]
struct MyObj {
a: i32,
b: i32,
}
#[Object]
impl MyObj {
async fn c(&self) -> i32 {
....
}
}
from async-graphql.
One other solution for that would be to have a macro that would autogenerate getters for each field with ability to override somehow?
from async-graphql.
I haven't thought of a good way to generate getters automatically, the only way to do it now is use a procedural macro include SimpleObject
and Object
to get the information I need to generate the code, I think it's pretty ugly.
gql_obj! {
#[SimpleObject]
struct MyObj {
a: i32,
b: i32,
}
#[Object]
impl MyObj {
async fn c(&self) -> i32 {
...
}
}
}
from async-graphql.
Yeah, it sure is.
One other option would be to allow getting fields from both simpleObj and Obj with the ability to exclude and override I guess. Can't think of anything cleaner atm, but definitely worth investigating to avoid doing the getters thing every time.
One other thing that came to mind is the ability to switch default behaviour in terms of field inclusion/exclusion, for simple/objects. As in include all by default, but allow to optionally do exclude all and then do includes. This is not very important though if it makes the code way too complex.
from async-graphql.
I doubt this is possible in the rust language unless I create a DSL with a macro, which would make the ide's auto-complete and formatting unavailable, which is not what I want.
from async-graphql.
Right, yeah, it's an interesting problem.
I'm wondering if the macro defined on impl
has access to any of the fields in the struct? The idea here is that we might not even need to support using both macros at the same time as long as we can use #[Object] and tell it to do the struct work too.
from async-graphql.
Speaking of getters: this seems like a good enough solution for those types that automatically translate to graphql and back: https://docs.rs/crate/derive-getters/0.1.0 . The rest can be ignored and implemented manually.
from async-graphql.
So it is possible to generate getters and setters, I just with I could somehow manage to mark that impl
that's being generated as Object
.
async-graphql might benefit from something like that, because that kinda solves this particular issue we are discussing here.
from async-graphql.
Yeah had the same Idea as well. Well you could write your own derive-getters that annotates the impl with Object but how are you going to extend that impl then? Can you have more than one impl block at a time annotated with Object? Otherwise this is kinda pointless isnβt it?
from async-graphql.
Sorry everyone, I still can't do it.
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.