-
Notifications
You must be signed in to change notification settings - Fork 46
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
feat(apollo-parser, apollo-compiler): support parsing and validating FieldSet #685
Conversation
In order to support `FieldSet` work in `federation-next`, we'd like to allow specific `field_set` parsing. It can be accessed after constructing the parser by calling `.parse_fieldset`. ```rust let source = r#"{ a }"#; let parser = Parser::new(source); let cst: SyntaxTree<cst::SelectionSet> = parser.parse_fieldset(); let errors = cst.errors().collect::<Vec<_>>(); assert_eq!(errors.len(), 0); let sel_set: cst::SelectionSet = cst.selection_set(); let _ = sel_set.selections().map(|sel| { if let cst::Selection::Field(f) = sel { assert_eq!(f.name().unwrap().text().as_ref(), "a") } }); ```
@@ -164,17 +190,30 @@ impl SyntaxTreeBuilder { | |||
|
|||
pub(crate) fn finish( | |||
self, | |||
field_set: bool, |
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.
Alternatively, we could also have pub(crate) fn finish_document
and pub(crate) fn finish_fieldset
. I am pretty indifferent here.
} | ||
} | ||
|
||
pub fn parse_fieldset(mut self) -> SyntaxTree<SelectionSet> { |
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.
i am almost certain i'd like this to be called parse_selection_set
. fieldset
is a federation specific term based on a non-spec scalar definition. I'd rather have the parser be by the spec
This follows specification naming more closely, rather than aligning the parser to federation implementation
…`@requires` Because field sets may or may not have opening braces, we are no longer strictly following the graphql specification. As part of this change, the API points referencing parsing `selection_set` are now renamed to `field_set`
This commit creates several wrapper types to handle FieldSet. - apollo-compiler's parser endpoint now has `parse_field_set` public API and an internal `parse_field_set_ast`, - executable document now has a `FieldSet` struct that allows us to store build errors along with the actual selection set - internal compiler's ast now has an implementation for `FieldSet` with source information for diagnostics and the actual selection set - it additionally implements a `FieldSet::from_cst` and `FieldSet::to_field_set` (which converts this to executable HIR `FieldSet` type)
b8b425f
to
1ee4d47
Compare
This starts work on supporting FieldSet.
The current items in scope:
SyntaxTree::selection_set
getter method for accessing selection set created from FieldSet parsingcloses #681