Repository navigation
Create the schema export directory when it does not exist - #10369
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The new directory guard can throw for bare relative filenames because Path.GetDirectoryName may return null, causing a regression.
Pull request overview
This PR fixes SchemaFileExporter.Export so exporting a schema to a path whose directory doesn’t exist no longer fails, by creating the target directory before writing the schema and settings files.
Changes:
- Update
SchemaFileExporter.Exportto create the target directory when a non-empty directory component is present. - Adjust existing exporter tests to stop pre-creating the directory.
- Add a new test to validate exporting into a nested (previously non-existent) directory.
File summaries
| File | Description |
|---|---|
| src/HotChocolate/Core/src/Types/Execution/Internal/SchemaFileExporter.cs | Create export directory before writing output files (but needs null-safe directory handling). |
| src/HotChocolate/Core/test/Types.Tests/Execution/Internal/SchemaFileExporterTests.cs | Update tests to rely on exporter directory creation; add nested-directory regression test. |
Review details
Suppressed comments (1)
src/HotChocolate/Core/src/Types/Execution/Internal/SchemaFileExporter.cs:48
Path.GetDirectoryName(schemaFileName)can return null for a bare relative filename (e.g. "schema.graphqls"). With the newdirectory.Length > 0guard andPath.Combine(directory, ...), this will throw (NullReferenceException/ArgumentNullException). Coalesce null to an empty string before the length check and combine so the original behavior (writing to the current directory) remains valid.
var directory = System.IO.Path.GetDirectoryName(schemaFileName)!;
if (directory.Length > 0)
{
Directory.CreateDirectory(directory);
}
var baseName = System.IO.Path.GetFileNameWithoutExtension(schemaFileName);
var settingsFileName = System.IO.Path.Combine(directory, $"{baseName}-settings.json");
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Patch coverage100.0% of changed lines covered (1/1)
Project coverage: 57.9% (288135/497753 lines) |
glen-84
added a commit
that referenced
this pull request
Sep 23, 2026
This was referenced Sep 26, 2026
Merged
This was referenced Oct 3, 2026
Open
This was referenced Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SchemaFileExporter.Exportnow creates the target directory before writing the schema and settings files. The previous guard only calledDirectory.CreateDirectorywhen the directory already existed, so exporting into a path that did not exist yet failed withDirectoryNotFoundException.schema.graphqlsyields and whatDirectory.CreateDirectoryrejects.Test plan
Export_Should_CreateDirectory_When_DirectoryDoesNotExistexports into a nested path that does not exist and asserts both files are written. It failed withDirectoryNotFoundExceptionbefore the change.SchemaFileExporterTestsno longer pre-create the directory themselves and still pass.