graph-node
graph-node copied to clipboard
GraphQL parse/validation caching
Since GraphQL parse and validate phase are static (does not depend on the user input like variables), we can implement caching for both phases (for parser: String => query::Document, for validation: String | query::Document => Vec<ValidationError>).
This might be more relevant once https://github.com/graphprotocol/graph-node/pull/3057 lands, because if we'll add more validation rules it might add some (probably minimal) overhead.
Usually it's implemented with LRU.
That's a good idea! For our purposes, I think it would be enough to keep a HashSet of the shape hashes of the queries that were successfully validated. We already calculate that hash (a u64) for all queries anyway. And since it's so little data, I don't think we have to worry about cache eviction and just keep those hashes for the lifetime of the service.
https://github.com/graphprotocol/graph-node/pull/3188#issuecomment-1021490277
Reopened, due to the high CPU issue we recently had with GraphQL validations.