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

By-name lookup argument lists and input object values in high-level representation #858

Open
goto-bus-stop opened this issue May 3, 2024 · 0 comments
Labels
apollo-compiler issues/PRs pertaining to semantic analysis & validation

Comments

@goto-bus-stop
Copy link
Member

goto-bus-stop commented May 3, 2024

In our apollo_compiler::ast level representation, field and directive arguments are represented by Vec<Node<Argument>>, and input object values are represented by Vec<(Name, Node<Value>)>. This is to maintain order and allow the possibility of duplicate names, which are syntactically valid, but not semantically valid.

The lists are normally short so it's not a big deal to have to iterate when you want to look up a particular argument or key. For field and directive arguments, we have an argument_by_name() method that does that for you. However, a malicious input could take a long time if the lists are used inefficiently (for example, an order-independent comparison between input object values that does an O(n^2) nested loop)

The apollo_compiler::{schema,executable} representations could instead use maps for these. A build error would be raised if any duplicates are encountered. We can still store key order by using an IndexMap (this would be good for serialization round-tripping), but ignore key order in == comparisons. It also slightly prevents users from building invalid schemas and operations by not being able to represent duplicate names.

@goto-bus-stop goto-bus-stop added the apollo-compiler issues/PRs pertaining to semantic analysis & validation label May 3, 2024
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

No branches or pull requests

1 participant