From 2981640b96bb9e2cfa41232b48f8a0b61e02fc5f Mon Sep 17 00:00:00 2001 From: Chris Joe Date: Tue, 4 Jul 2023 13:20:56 +1200 Subject: [PATCH 1/3] fix(SortPlugin): amend sorting to all fields --- src/Schema/Plugin/SortPlugin.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Schema/Plugin/SortPlugin.php b/src/Schema/Plugin/SortPlugin.php index d7ded7ff..98a2fa06 100644 --- a/src/Schema/Plugin/SortPlugin.php +++ b/src/Schema/Plugin/SortPlugin.php @@ -91,9 +91,7 @@ public static function sort(array $context): Closure return null; } $sortArgs = $args[$fieldName] ?? []; - foreach ($sortArgs as $field => $dir) { - $list = $list->sort($field, $dir); - } + $list = $list->sort($sortArgs); return $list; }; From 47811b88cd1ae7e39cf13ed698223f6a13b4d047 Mon Sep 17 00:00:00 2001 From: Chris Joe Date: Fri, 7 Jul 2023 13:04:50 +1200 Subject: [PATCH 2/3] test(SortPlugin): add integration test for multi-sort --- tests/Schema/IntegrationTest.php | 21 ++++++++++++++++++--- tests/Schema/_testFilterAndSort/models.yml | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/Schema/IntegrationTest.php b/tests/Schema/IntegrationTest.php index c8dc2491..23cc2a72 100644 --- a/tests/Schema/IntegrationTest.php +++ b/tests/Schema/IntegrationTest.php @@ -425,6 +425,9 @@ public function testFilterAndSort() $dataObject2 = DataObjectFake::create(['MyField' => 'test2', 'AuthorID' => $author2->ID]); $dataObject2->write(); + $dataObject3 = DataObjectFake::create(['MyField' => 'test3', 'AuthorID' => $author2->ID]); + $dataObject3->write(); + $file1 = File::create(['Title' => 'file1']); $file1->write(); @@ -436,6 +439,7 @@ public function testFilterAndSort() $id1 = $dataObject1->ID; $id2 = $dataObject2->ID; + $id3 = $dataObject3->ID; $schema = $this->createSchema(new TestSchemaBuilder([$dir])); @@ -474,7 +478,7 @@ public function testFilterAndSort() $query = <<querySchema($schema, $query); $this->assertSuccess($result); - $this->assertResult('readOneDataObjectFake.myField', 'test1', $result); + $this->assertResult('readOneDataObjectFake.myField', 'test3', $result); + + $query = <<querySchema($schema, $query); + $this->assertSuccess($result); + $this->assertResult('readOneDataObjectFake.myField', 'test2', $result); $query = << Date: Mon, 24 Jul 2023 20:36:58 +1200 Subject: [PATCH 3/3] Run dev/build add-on only once Instead of once for every DataObject that exists in the project. Although there's an early exist after the first execution runs, there are N-1 more runs checking the same thing. This isn't really a change, nor impactful... it is just a touch of code hygiene :) --- _config/dataobject.yml | 3 --- _config/dev.yml | 4 ++++ src/Extensions/DevBuildExtension.php | 32 ++++++++++++---------------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/_config/dataobject.yml b/_config/dataobject.yml index f1280ebd..fcdb4a39 100644 --- a/_config/dataobject.yml +++ b/_config/dataobject.yml @@ -5,6 +5,3 @@ SilverStripe\ORM\DataObject: graphql_blacklisted_fields: LinkTracking: true FileTracking: true - extensions: - - SilverStripe\GraphQL\Extensions\DevBuildExtension - diff --git a/_config/dev.yml b/_config/dev.yml index 7b51e285..c19ab4e1 100644 --- a/_config/dev.yml +++ b/_config/dev.yml @@ -1,6 +1,10 @@ --- Name: graphql-dev --- +SilverStripe\ORM\DatabaseAdmin: + extensions: + - SilverStripe\GraphQL\Extensions\DevBuildExtension + SilverStripe\Dev\DevelopmentAdmin: registered_controllers: graphql: diff --git a/src/Extensions/DevBuildExtension.php b/src/Extensions/DevBuildExtension.php index 9285ab10..64ce1579 100644 --- a/src/Extensions/DevBuildExtension.php +++ b/src/Extensions/DevBuildExtension.php @@ -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'); } } }