apollographql / apollo-rs

Spec compliant GraphQL Tools in Rust.
Apache License 2.0
566 stars 43 forks source link

fix(compiler): cache the implementers map per executable document #863

Closed goto-bus-stop closed 3 months ago

goto-bus-stop commented 3 months ago

Fixes #862.

I had proposed a different approach that would let us cache the implementers map for as long as the schema is immutable, so it could be reused for different query validations. That approach had an issue that made Valid::assume_valid_ref very, very subtle to use, so we are not doing that right now.

This is a less ideal version but it does solve the immediate problem. We had an OperationValidationConfig structure that contains contextual information about the current operation. This extends that idea to have an ExecutableValidationContext for the whole document, and "child" OperationValidationContexts for each operation.

The included benchmark goes from 200ms of validation time to 2ms.