Should the documentation for caching the parsed schema also recommend passing assumeValidSDL to avoid re-validating the schema on every request?
We do some manual operations to merge multiple .graphql files and modifications based on schema-level directives (authorization control based on session type) so we wouldn't want to opt out entirely. Instead we moved to manually call DocumentValidator::assertValidSDL as part of the build process and then pass assumeValidSDL to avoid it on every request. We saw a hefty reduction in resource usage after doing so.
$cacheFilename = 'cached_schema.php';
if (!file_exists($cacheFilename)) {
$document = Parser::parse(file_get_contents('./schema.graphql'));
DocumentValidator::assertValidSDL($document);
file_put_contents($cacheFilename, "<?php\nreturn " . var_export(AST::toArray($document), true) . ";\n");
} else {
$document = AST::fromArray(require $cacheFilename); // fromArray() is a lazy operation as well
}
$typeConfigDecorator = function () {};
$schema = BuildSchema::build($document, $typeConfigDecorator, ['assumeValidSDL' => true]);
Do you see any reason why this could be a problem, or could this be made the default recommendation in the documentation?
Should the documentation for caching the parsed schema also recommend passing
assumeValidSDLto avoid re-validating the schema on every request?We do some manual operations to merge multiple
.graphqlfiles and modifications based on schema-level directives (authorization control based on session type) so we wouldn't want to opt out entirely. Instead we moved to manually callDocumentValidator::assertValidSDLas part of the build process and then passassumeValidSDLto avoid it on every request. We saw a hefty reduction in resource usage after doing so.Do you see any reason why this could be a problem, or could this be made the default recommendation in the documentation?