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

feat(apollo-parser, apollo-compiler): support parsing and validating FieldSet #685

Merged
merged 10 commits into from
Oct 10, 2023

Conversation

lrlna
Copy link
Member

@lrlna lrlna commented Oct 9, 2023

This starts work on supporting FieldSet.

The current items in scope:

  • support FieldSet parsing in apollo_parser
  • create SyntaxTree::selection_set getter method for accessing selection set created from FieldSet parsing
  • incorporate FieldSet parsing in apollo_compiler
  • create FieldSet validation in apollo_compiler that only runs specific validation rules

closes #681

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")
    }
});
```
@lrlna lrlna added the apollo-compiler issues/PRs pertaining to semantic analysis & validation label Oct 9, 2023
@lrlna lrlna self-assigned this Oct 9, 2023
@@ -164,17 +190,30 @@ impl SyntaxTreeBuilder {

pub(crate) fn finish(
self,
field_set: bool,
Copy link
Member Author

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> {
Copy link
Member Author

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

lrlna and others added 7 commits October 10, 2023 08:36
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)
@SimonSapin SimonSapin marked this pull request as ready for review October 10, 2023 14:36
@SimonSapin SimonSapin merged commit da57a9d into compiler-v1.0 Oct 10, 2023
9 checks passed
@SimonSapin SimonSapin deleted the field_set_parsing branch October 10, 2023 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apollo-compiler issues/PRs pertaining to semantic analysis & validation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants