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

EAS-2497 : Collect possible GraphQL queries during lowering #56

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

gersbach
Copy link
Contributor

No description provided.

let mut operations = vec![];
if let std::result::Result::Ok(doc) = parse_query::<&str>(s) {
doc.definitions.into_iter().for_each(|operation| {
if let Definition::Operation(op) = operation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to collect possible queries from fragments as well.

Copy link
Contributor Author

@gersbach gersbach Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fragment componentParts on CompassCatalogQueryApi{
 	searchTeams(input: $test) {
    	... on CompassSearchTeamsConnection{
        nodes {
          teamId
        }
      }
  }
}

query compass_query($test:CompassSearchTeamsInput!) {
  compass {
    ...componentParts
  }
}

You mean something like this ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

doc.definitions.into_iter().for_each(|operation| {
if let Definition::Operation(op) = operation {
match op {
OperationDefinition::Mutation(mutation) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also have plain selection sets as well that need to be parsed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does AGG allow this ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure it did last time I checked, there was just a warning in the UI.

Comment on lines +125 to +126
.filter(|f| permissions_resolver.contains_key(f))
.map(|f| permissions_resolver.get(f).unwrap().to_owned())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.filter(|f| permissions_resolver.contains_key(f))
.map(|f| permissions_resolver.get(f).unwrap().to_owned())
.filter_map(|f| permissions_resolver.get(f))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent a little while looking at this and I initially tried to do the func mut, but the permissions_resolver.get(f) returns a &&str when we need a &str. AFAIK, there is no way to convert within the filter_map right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just add a Option::copied call after the get.

@@ -99,7 +103,69 @@ impl fmt::Display for Error {
}
}

impl std::error::Error for Error {}
fn check_graphql_and_perms(val: &Value) -> Vec<&str> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the string being returned here? And does it need to be a string in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes back to my internship, we decided on using string instead of enums for returning permissions.... I suppose we can swtich that. Let me know if we should.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason I'm going on this now, is because you have to hardcode the permissions anyway with the mapping, which means that the permissions are known at compile time.

Though if that's a stand in for deserializing an actual permission map where the permissions aren't static, then you can leave it as str, though make sure to add a comment.

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

Successfully merging this pull request may close these issues.

2 participants