Skip to content

Commit

Permalink
Use NullDatabase
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Jul 7, 2021
1 parent 4409a77 commit 1fd544d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Script\Event;
use Composer\IO\IOInterface;
use ReflectionClass;
use SilverStripe\Core\CoreKernel;
use SilverStripe\GraphQL\Schema\Exception\EmptySchemaException;
use SilverStripe\GraphQL\Schema\Schema;
use SilverStripe\GraphQL\Schema\SchemaBuilder;
use SilverStripe\ORM\Connect\MySQLDatabase;
use SilverStripe\ORM\Connect\NullDatabase;
use SilverStripe\ORM\DB;

class Plugin implements PluginInterface, EventSubscriberInterface
{
Expand Down Expand Up @@ -57,10 +61,16 @@ public function generateSchema(Event $event)
return;
}

// Throw an exception when any logic in this execution is attempting to perform a query.
// GraphQL code generation can happen on environments which don't have a valid database connection,
// for example in CI when preparing a deployment package.
DB::set_conn(new NullDatabase());


// Not using sake because it creates a HTTPApplication through cli-script.php.
// This would trigger middlewares assuming a HTTP request execution
// (rather than CLI), which then connect to the database that might not be available during this build.
$kernel = new CoreKernel(BASE_PATH, false);
$kernel = new CoreKernel(BASE_PATH);
try {
// Any composer update can introduce new config statements that require a manifest flush.
// Since there is no way to pass flush=1 through composer commands, the safest way is to always perform the flush.
Expand Down

0 comments on commit 1fd544d

Please sign in to comment.