diff --git a/CHANGELOG.md b/CHANGELOG.md index 25955cb6..41527e26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## v0.31.2 + +### Added + +- Add `DirectoriesFinder` + ## v0.31.1 ### Added diff --git a/src/Codegen/DirectoriesFinder.php b/src/Codegen/DirectoriesFinder.php new file mode 100644 index 00000000..47b27cef --- /dev/null +++ b/src/Codegen/DirectoriesFinder.php @@ -0,0 +1,26 @@ + */ + protected array $directoryFinders; + + /** @param array $directoryFinders */ + public function __construct(array $directoryFinders) + { + $this->directoryFinders = $directoryFinders; + } + + public function documents(): array + { + $documents = []; + foreach ($this->directoryFinders as $directory) { + // Merge ensures uniqueness of the found paths + $documents = array_merge($documents, $directory->documents()); + } + + return $documents; + } +} diff --git a/tests/Unit/Codegen/DirectoriesFinderTest.php b/tests/Unit/Codegen/DirectoriesFinderTest.php new file mode 100644 index 00000000..6f1f25c4 --- /dev/null +++ b/tests/Unit/Codegen/DirectoriesFinderTest.php @@ -0,0 +1,35 @@ +documents())); + } + + public function testDeduplicates(): void + { + $subFinder1 = new DirectoryFinder(__DIR__ . '/finder/sub'); + $subFinder2 = new DirectoryFinder(__DIR__ . '/finder/sub'); + + $directoriesFinder = new DirectoriesFinder([$subFinder1, $subFinder2]); + + self::assertSame([ + __DIR__ . '/finder/sub/should-also-be-found.graphql', + ], array_keys($directoriesFinder->documents())); + } +}