Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run dev/build add-on only once #544

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions _config/dataobject.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ SilverStripe\ORM\DataObject:
graphql_blacklisted_fields:
LinkTracking: true
FileTracking: true
extensions:
- SilverStripe\GraphQL\Extensions\DevBuildExtension

4 changes: 4 additions & 0 deletions _config/dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
Name: graphql-dev
---
SilverStripe\ORM\DatabaseAdmin:
extensions:
- SilverStripe\GraphQL\Extensions\DevBuildExtension

SilverStripe\Dev\DevelopmentAdmin:
registered_controllers:
graphql:
Expand Down
32 changes: 14 additions & 18 deletions src/Extensions/DevBuildExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,25 @@ class DevBuildExtension extends DataExtension
*/
private static bool $enabled = true;

private static bool $done = false;

public function onAfterBuild(): void
{
if (!static::config()->get('enabled')) {
return;
}
if (!self::$done) {
// Get the current graphQL logger
$defaultLogger = Injector::inst()->get(LoggerInterface::class . '.graphql-build');

try {
// Define custom logger
$logger = Logger::singleton();
$logger->setVerbosity(Logger::INFO);
Injector::inst()->registerService($logger, LoggerInterface::class . '.graphql-build');

Build::singleton()->buildSchema();
self::$done = true;
} finally {
// Restore default logger back to its starting state
Injector::inst()->registerService($defaultLogger, LoggerInterface::class . '.graphql-build');
}

// Get the current graphQL logger
$defaultLogger = Injector::inst()->get(LoggerInterface::class . '.graphql-build');

try {
// Define custom logger
$logger = Logger::singleton();
$logger->setVerbosity(Logger::INFO);
Injector::inst()->registerService($logger, LoggerInterface::class . '.graphql-build');

Build::singleton()->buildSchema();
} finally {
// Restore default logger back to its starting state
Injector::inst()->registerService($defaultLogger, LoggerInterface::class . '.graphql-build');
}
}
}