apollographql / federation-next

Moved to the Router repository
https://github.com/apollographql/router/tree/dev/apollo-federation
Other
19 stars 1 forks source link

Port `SelectionSet::contains`, and some operation.rs tweaks #290

Closed goto-bus-stop closed 4 months ago

goto-bus-stop commented 4 months ago

This is part of the FetchDependencyGraph::optimize() work.

This PR first makes a few tweaks to operation.rs:

Then it implements the Selection::contains() / SelectionSet::contains() family of functions. in JS land, .contains() returns a ContainResult enum, which is castable to a boolean. That doesn't make sense in Rust, so instead I add a .containment() function, which returns an enum, and a .contains() shorthand which returns a bool. .containment() checks if the left-hand side (self) contains, is a superset of, the right-hand side (other). There is an option to ignore the case where __typename is present in other but not in self: if provided, self will still be considered to contain other even if self does not have a __typename.

It's a bit confusing but the tests should clarify what that does.