Skip to content

Commit 8b9e8bd

Browse files
zimzatspawnia
authored andcommitted
Recommend using assumeValidSDL when caching a parsed schema
1 parent 11ce901 commit 8b9e8bd

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

docs/schema-definition-language.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,20 @@ It is recommended to cache the intermediate parsed representation of the schema
6565

6666
```php
6767
use GraphQL\Language\Parser;
68+
use GraphQL\Validator\DocumentValidator;
6869
use GraphQL\Utils\BuildSchema;
6970
use GraphQL\Utils\AST;
7071

7172
$cacheFilename = 'cached_schema.php';
7273

7374
if (!file_exists($cacheFilename)) {
7475
$document = Parser::parse(file_get_contents('./schema.graphql'));
76+
DocumentValidator::assertValidSDL($document);
7577
file_put_contents($cacheFilename, "<?php\nreturn " . var_export(AST::toArray($document), true) . ";\n");
7678
} else {
7779
$document = AST::fromArray(require $cacheFilename); // fromArray() is a lazy operation as well
7880
}
7981

8082
$typeConfigDecorator = function () {};
81-
$schema = BuildSchema::build($document, $typeConfigDecorator);
83+
$schema = BuildSchema::build($document, $typeConfigDecorator, ['assumeValidSDL' => true]);
8284
```

0 commit comments

Comments
 (0)