Generate strongly typed consumers with clientgen
After a lot of refactoring, I added a clientgen
utility and graphqlclient
support library to build strongly typed clients from static request documents, similar to the way that client frameworks like Apollo or Relay generate types for the variables and responses.
Since clientgen
parses and validates the request at code generation time, in addition to the text of the request document returned by GetRequestText
, it will also return a pre-parsed and pre-validated request AST (Abstract Syntax Tree) from GetRequestObject
. There's a new benchmark program called client_benchmark
in the samples
directory, which replaces the parse/validate step with the pre-built request AST from GetRequestObject
, and it replaces JSON serialization with parsing directly into the strongly typed response object. Your mileage may vary, on my fast Intel desktop running Windows, it had a little over 2x the single-threaded throughput of parsing and validating plus JSON serialization, and on a low-powered ARM64 Linux laptop it had just under 2x the throughput. Either way, the bulk of the savings came from not needing to parse and validate the queries in the loop, on the faster machine serializing to the strongly typed object was slightly faster and on the other serializing to JSON was slightly faster.