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
Dynamic schema #30
Comments
I’m relatively new to GraphQL and haven’t encountered dynamic schemas. Could you provide a link? Or an example use-case? |
https://github.com/graphql-go/graphql Like this, allows change schema at run time. |
Alright so here is a somewhat incomplete and unordered list of thoughts: Cons
Pros
|
I tried it out yesterday, but it didn't work😂, and I'm still thinking about a better way to do it. The main reason is that rust does not support generic specialization, solving the problem with |
I will definitely 🎉 when specialization lands on stable rust. |
Have you looked at the Syllogism crate for specialization? |
Thank you for telling me about |
Yep, dynamic schema would definitely be something of interest.
And I'd like to support some sort of querying by these dynamic fields. At the moment I'm looking at custom implementation for this as this is tricky and not really supported by the graphql spec, considering that in the example above each RecordType might have a different schema. But, getting back to reality - it would be nice to support dynamic schema! |
Validation the JSONMap you could try |
@sunli829 I'll give it a shot, I can probably integrate that with http://rustless.org/valico/doc/valico/ |
This should solve the problem perfectly.😁 |
@sunli829 yeah, except I need to pass said schema to the validator. |
If you need a context, the |
I think we should probably add an execution phase validator called |
Yeah, that would be awesome.
Yeah, I have figured as much. |
@sunli829 should I add a ticket for |
This should be finished by tomorrow. I have been trying other improvements for the last two days. |
Curious to see what you came up with for other issues we had! |
In fact, I'm still thinking about how to use #[field(guard="require_auth")
async fn value(&self) -> i32 {...} async fn value(&self, ctx: &Context<'_>) -> FieldResult<i32> {
require_auth(ctx)?;
} The guard attribute doesn't offer any convenience, and I'm still wondering if this feature is necessary. |
I tried to optimize the way the interface is defined, but I was not satisfied with either approach. |
That actually seems very nice to me, because then we could apply several guards as well, and that's several method calls. Take a look at some of the features of https://docs.nestjs.com/graphql/tooling for inspiration, they have some powerful annotations in place that make working with graphql a blast! |
Thank you, that gave me some inspiration, and I'm working on that right now. |
One important feature I overlooked is that guard can be applied to the SimpleObject. |
Yeah, I mean there are plenty of nice looking features there, but not all of them can be implemented in rust the same way, as it's not the same. For example, there is an ability to annotate methods and types so that they end up being parts of the query/mutation/subscription without actually being one object AFAIK. That allows for splitting the schema by functionality, we could kind of mimic that by having a composite struct I suppose. |
I created a new issue #43, adding this feature was more difficult than I expected, I needed to modify some code generation, and it probably took a little longer to complete. |
@sunli829, what became of this issue? I wasn't able to follow along properly to understand if this was implemented. There was mention of passing new schemas to validators and not having a context available. Then there was discussion about a guard and it looks like that was implemented, although I don't recall seeing guards mentioned in the book. A use case I have in mind is enabling users of vimwiki-server to define custom logic that can leverage the data models I've built for the vimwiki language and respond to some custom query using an embedded language like Lua that connects to the Rust server. My only thought right now without some way to define a custom schema alongside my static schema is through some general-purpose query: {
lua_query(key: "some identifier", input: "some input") {
key
output
}
} |
Am I right in thinking that dynamic schemas would also be needed to implement an Apollo Gateway replacement in rust? |
Yes, you are absolutely correct. 😁 |
Dynamic schemas would be a big win for my production work. I have/am developing a system for the company I work for which allows us to add/remove/change our systems behavior at runtime using a series of configuration files, part of which is being able to manipulate our webserver/graphql interface. Right now I have to use a super generic interface that works for all situations but isn't ideal due to how vague it is. |
Hey @sunli829 you closed this as |
@Bjohnson131 Please take a look at https://github.com/apollographql/apollo-rs Currently, if you want to implement a dynamic schema, you have to implement it by yourself. Use apollo-encoder to generate a schema SDL and apollo-parser to parse GraphQL requests. |
I'm working on this, it's going well, and a preview will be released this week. 🙂 |
I underestimated the amount of work, but it should be done this week. |
This is so big! If you get a preview, let me know! I'll be following! |
I opened a PR to track progress. |
This issue can be probably closed |
Async-graphql
lacks an important feature that most graphql implementations do not. Support both static and dynamic schema, and only with dynamic schema can write something likehasaru
.I have some preliminary ideas about the implementation of this feature. Do you think this feature is important?
@nicolaiunrein @phated
The text was updated successfully, but these errors were encountered: