graphql-parser
graphql-parser copied to clipboard
Add SchemaVisitor and QueryVisitor traits and functions
Fixes https://github.com/graphql-rust/graphql-parser/issues/25
Implementation is based upon the description here https://github.com/rust-unofficial/patterns/blob/master/patterns/visitor.md
It looks good to me on the whole! It's unsollicited, but if nobody else has the time, I could do a more in-depth review.
@tomhoule that would be great 😊
@tailhook will leave it to you to look at and land.
It looks like there are multiple mistakes with visiting recursively.
Or was non-recursive visitor intentional?
Hi y'all, I'm gonna try another experimental flavor of an implementation for this, following the graphql-js interface. Here is my reasoning for this:
enterwould let you manipulate a node of the AST tree before entering its subtreeleavewould let you manipulate a node of the AST tree after its subtree has been visited- It would pave the way for schema-aware visitors using a
TypeInfostruct. Here's some example usage.
The biggest use-case of a system like this in my case is doing custom validation of a query based on a schema, this API lets you do that.
We implemented a visitor (with type info) for both schema and queries in https://github.com/dotansimha/graphql-tools-rs , also a (almost) spec-compliant validation phase.
Thanks for this PR, it was a great inspiration!
@dotansimha why did you post this in 3 different places? 😅
@dotansimha why did you post this in 3 different places? 😅
I saw these PRs are duplicated anyway, so I hope it would help someone :) I'll delete if that's a problem ;) didn't plan to annoy anyone with notifications :x
I'll close this for now. Its been a long time and I no longer have bandwidth to follow this through.