-
Notifications
You must be signed in to change notification settings - Fork 429
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
Add support for GraphQL Schema Language #324
Conversation
A couple of notes:
|
45b7ecb
to
2bed836
Compare
I'm not so sure what the use case for this is. The schema language is usually used the other way around AFAIK, as in bootstrapping a server from a schema file and adding resolver methods. Downstream tools use a introspection query to get the schema, since that way the information is already structured in a standardized way. Where do you see this being useful? The only one I could think of is generating a easily readable specification of your schema for human consumption. |
You need a schema file to use https://github.com/graphql-rust/graphql-client among other use cases such as external tools. Sure, you could run the introspection query and that's the next thing I am adding. If the schema is defined in Juniper/rust, it is essentially "locked up" until runtime currently. |
But now that I think about it, perhaps it makes sense for this to be its own little crate/project, similar to https://github.com/davidpdrsn/juniper-from-schema? An argument can be made that it should be part of juniper as well as not. Is it a view of the schema one would reasonably expect juniper to handle? Or is it a nice-to-have that isn't intrinsic to how juniper does things. FWIW, Graphql.js has Then again, they also have a way to go from the IDL to the internal representation, which is what https://github.com/davidpdrsn/juniper-from-schema does in Rust land. I guess the same arguments would apply to #307 as well? So you could argue that juniper should include both this PR and something like I'm going to open an issue. |
Codecov Report
@@ Coverage Diff @@
## master #324 +/- ##
==========================================
- Coverage 87.79% 87.57% -0.23%
==========================================
Files 101 102 +1
Lines 14244 14457 +213
==========================================
+ Hits 12506 12660 +154
- Misses 1738 1797 +59
Continue to review full report at Codecov.
|
First glance looks good, I'll review thoroughly later today. One question is how much work it would be to fully switch over to Also maybe there is a more elegant way to detect builting types than |
@theduke For switching entirely over to Also, it would probably be pretty trivial to change this to go direct to the string output without going through |
@LegNeato as a first step I have opened a PR that allows a borrowed AST on the parser: graphql-rust/graphql-parser#19 I'll investigate wheter we'd really want to switch to that AST, and compare it with our own. |
@LegNeato I'm working on switching to graphql-parser. We could wait with this until that happens, or move ahead now if you'd like to get it in sooner. |
impl<'a, S> Field<'a, S> { | ||
/// Returns true if the type is built-in to GraphQL. | ||
pub fn is_builtin(&self) -> bool { | ||
// "used exclusively by GraphQL’s introspection system" |
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.
This seems a bit hacky, __
is not reserved so users could add their own objects/ fields/arguments/...
We could add a builtin: bool
flag to the relevant schema types.
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.
"All types and directives defined within a schema must not have a name which begins with {"__"} (two underscores), as this is used exclusively by GraphQL's introspection system."
Mostly looks good. Actually I'd be in favor of including it now, but without the feature, let's just build it in. |
Ok, I'll rip out the features, rebase, and switch to borrowing after your patch lands. |
Juniper has changed quite a bit since August (especially with the recommendation to base new PRs on the async branch). That said, keen to test this PR out, I rebased this onto #493 and changed the graphql-parser dependency to depend on the master branch and (after sprinkling in some lifetimes) this works like a charm. Seems like for this to be merged we are waiting on:
I can open a PR with my (minimal) changes, just know that I am still quite new to rust. |
I updated master to use the async-await branch. |
Would love a PR with the updated changes! |
@arlyon any chance you can put up the rebased changes? |
Friendly 👉@arlyon |
Hey, missed these for some reason. I was going to open a PR, but I noticed a new version of graphql-parser is out and it seems silly not to update. Lifetimes are a bit annoying to iron out so it's taking a bit of time. Edit: thought I was close to done, but can't get it right so I'm giving up. There's clearly some lifetime stuff I don't quite grasp. Sorry for blocking. |
@arlyon great, thank you! Yes, the new version should allow us to use &str instead of Strings and be a lot more memory efficient feel free to post WIPs if you get stuck! |
This was landed as #676 |
No description provided.