Skip to content
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 SchemaVisitor and QueryVisitor traits and functions #26

Open
wants to merge 4 commits into
base: master
from

Conversation

@davidpdrsn
Copy link
Contributor

@davidpdrsn davidpdrsn commented Jul 21, 2019

Fixes #25

Implementation is based upon the description here https://github.com/rust-unofficial/patterns/blob/master/patterns/visitor.md

@tomhoule
Copy link
Member

@tomhoule tomhoule commented Sep 18, 2019

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.

@davidpdrsn
Copy link
Contributor Author

@davidpdrsn davidpdrsn commented Sep 20, 2019

@tomhoule that would be great 😊

Copy link
Member

@tomhoule tomhoule left a comment

I'm not the maintainer of this crate, but as far as I'm concerned it looks good :)


fn walk_fragment_definition<'ast, V: QueryVisitor<'ast>>(visitor: &mut V, node: &'ast FragmentDefinition) {
visitor.visit_fragment_definition(node);
}

This comment has been minimized.

@tomhoule

tomhoule Sep 20, 2019
Member

Would it make sense to further walk down the fragment's selection?

This comment has been minimized.

@davidpdrsn

davidpdrsn Oct 7, 2019
Author Contributor

Addressed in db9310e 👍


fn walk_inline_fragment<'ast, V: QueryVisitor<'ast>>(visitor: &mut V, node: &'ast InlineFragment) {
visitor.visit_inline_fragment(node);
}

This comment has been minimized.

@tomhoule

tomhoule Sep 20, 2019
Member

Same as for fragments, would it make sense to visit the selection set?

This comment has been minimized.

@davidpdrsn

davidpdrsn Oct 7, 2019
Author Contributor

Addressed in cb71a7e 👍

Copy link
Member

@LegNeato LegNeato left a comment

This looks great to me.

@LegNeato
Copy link
Member

@LegNeato LegNeato commented Mar 14, 2020

@tailhook will leave it to you to look at and land.

Copy link
Collaborator

@tailhook tailhook left a comment

It looks like there are multiple mistakes with visiting recursively. I'm not sure how to structure code or how to test it well to eliminate these bugs.

(sorry that it took so long...)

visitor.visit_field(inner);
walk_field(visitor, inner);
Comment on lines +202 to +203

This comment has been minimized.

@tailhook

tailhook Apr 1, 2020
Collaborator

I don't understand this pattern. You first do visit_field and then walk_field which calls visit_field again. Same with fragments. Am I misunderstanding something?

//!
//! walk_document(&mut number_of_type, &doc);
//!
//! assert_eq!(number_of_type.count, 2);

This comment has been minimized.

@tailhook

tailhook Apr 1, 2020
Collaborator

This doesn't look right. There are four fields if visiting recursively: query, id, country, id and single one if not (users). Currently it looks like you just counting users twice.

@tailhook
Copy link
Collaborator

@tailhook tailhook commented Apr 1, 2020

It looks like there are multiple mistakes with visiting recursively.

Or was non-recursive visitor intentional?

This was referenced Apr 1, 2020
//! }
//!
//! fn main() {
//! let mut number_of_type = FieldsCounter::new();

This comment has been minimized.

@spawnia

spawnia Apr 10, 2020

Suggested change
//! let mut number_of_type = FieldsCounter::new();
//! let mut fields_counter = FieldsCounter::new();

number_of_type seems to indicate this is supposed to count types, not fields, which does not really make sense when walking over a query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants