-
Notifications
You must be signed in to change notification settings - Fork 426
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
Switch to graphql-parser #138
Comments
That looks much better than my half-baked Pest parser (although I still prefer pest to combine but that's not important)! It would be really neat for the Rust ecosystem to standardise on a single parser so at least every crate wanting to do something with GraphQL doesn't have to rewrite it and it has many eyes on it. |
@tailhook I'll look over the code, but in principle, as long as the AST produced is decent and can easily be converted (without much cloning) I'd definitely be in favour. This also concers https://github.com/nrc/graphql and @nrc. We'd also need the parser to handle parsing the GraphQL schema definition language. |
@tailhook also, it's important to have great error reporting for parsing errors and to be able to map each ast node to the query location. |
Sure, here is the issue: nrc/graphql#36
I think it's good enough. Of course, we have positions of all the errors. And "unexpected A, expected B, C". I'm not sure what else to say. Perhaps, there aren't much test for error reporting yet. Currently, we don't have decent API for the error besides: format me a string, but it should be easy to add just need to figure out how it might look like.
We have positions for all important elements. The approach is different that one here, but we can discuss details.
Surely, on a todo list. Does seem like another weekend project in it's size. The good thing that tokenizer may be reused entirely. |
@tailhook all sounds great, I'll look over the code! Would you be interested in moving the parser into the It would be cool to have all GraphQL related stuff under one hood, and it would ensure that someone else can maintain the parser if you need a break or whatever. That's not in any way a requirement for me, though. ps: I've written a demo parser in combine too, I think it's a good choice as in the the current parser combinator ecosystem. |
I'm fine with that. Should it be done now? |
SDL is implemented and pushed to crates.io as v0.2.0 |
Is there anything blocking that? |
@Keats I haven't had time to look over the code. We will probably want to have a custom-tailored ast for Juniper. Especially wrt tokio, where sharing the AST between possible lots of resolvers (futures) should be as cheap as possible. @mhallin had some concerns, so we probably want his input here. |
Hello, and thanks for bringing this up to the table! While the parser part looks good, I've got some reservations for giving up control over the AST data structures to a general-purpose library. The issue I see is that we won't be able to model the data the way that suits a server application best. For example, our AST of today uses I believe you could switch over graphql-parser to use this code, or build even better versions of all of this, but my reluctance comes from the fact that we now can do that without having to think about other use cases than ours. |
Well, AST in graphql-parser is currently owned, so works fine for async code right now. Then we can try to benchmark and optimize things. Usually, rust/jemalloc is very good, so allocations themselves are rarely problem. Given that request processing does lots of validation and probably has a bunch of hashmaps the overhead of allocations may be amortized. Also if Another point of view is that size of |
IMO it's fine if we start from what's there and optimize later, especially if @tailhook is fine with moving the repo into the graphql-rust org. I also agree that the AST is probably a minuscule part of the work that happens when executing a resolver. But: query {
users(page: 2, pagesize: 100) {
id
username
posts(max: 20) {
name
comments(limit: 5) {
id
title
}
}
likes(max: 50) {
post {
id
title
}
time
}
}
} Let's assume that the posts, posts.comments, likes, likes.posts queries are run as futures. That means: Now let's think about 100 of those queries running concurrently... So I think this can become a significant overhead. There are a lot of possible optimizations, like just unsafely passing around references to the full AST, using an Arc of the initial query string like mhallin has tried, using some kind of per-query interner, ... But it's something that we'll need to think about. |
I expect this to work by wrapping an I.e. the AST after validation/optimization is a bit different from what we have right after parsing anyway. |
Some progress: graphql-rust/graphql-parser#19 |
@tailhook considering this issue was opened more than 2 years ago. Would the progress on graphql-parser be sufficient to fully replace the the current parser? I.e. what is the current status of this issue? |
Hi,
Since there is no activity in #32 I've decided to write a separate crate for graphql-parser.
It's not based on code here but built using excellent
combine
crate (making the grammar more readable in my opinion). So in a weekend project I could build the parser for the whole graphql grammar. Which means it should be on par with this crate for features (I've not checked every feature, but we also have subscriptions and triple-quoted strings already implemented).What do you think about integrating with the
graphql-parser
crate instead of keeping custom parser?The text was updated successfully, but these errors were encountered: