Skip to content

Commit

Permalink
Merge branch '4' into 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Aug 20, 2023
2 parents ff11a35 + 9768191 commit 45874f4
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 27 deletions.
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');
}
}
}
4 changes: 1 addition & 3 deletions src/Schema/Plugin/SortPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
21 changes: 18 additions & 3 deletions tests/Schema/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -436,6 +439,7 @@ public function testFilterAndSort()

$id1 = $dataObject1->ID;
$id2 = $dataObject2->ID;
$id3 = $dataObject3->ID;

$schema = $this->createSchema(new TestSchemaBuilder([$dir]));

Expand Down Expand Up @@ -474,7 +478,7 @@ public function testFilterAndSort()

$query = <<<GRAPHQL
query {
readOneDataObjectFake(sort: { myField: DESC }) {
readOneDataObjectFake(sort: { AuthorID: DESC , myField: ASC }) {
myField
}
}
Expand All @@ -485,14 +489,25 @@ public function testFilterAndSort()

$query = <<<GRAPHQL
query {
readOneDataObjectFake(sort: { myField: DESC }, filter: { id: { ne: $id2 } }) {
readOneDataObjectFake(sort: { myField: DESC }) {
myField
}
}
GRAPHQL;
$result = $this->querySchema($schema, $query);
$this->assertSuccess($result);
$this->assertResult('readOneDataObjectFake.myField', 'test1', $result);
$this->assertResult('readOneDataObjectFake.myField', 'test3', $result);

$query = <<<GRAPHQL
query {
readOneDataObjectFake(sort: { myField: DESC }, filter: { id: { ne: $id3 } }) {
myField
}
}
GRAPHQL;
$result = $this->querySchema($schema, $query);
$this->assertSuccess($result);
$this->assertResult('readOneDataObjectFake.myField', 'test2', $result);

$query = <<<GRAPHQL
query {
Expand Down
1 change: 1 addition & 0 deletions tests/Schema/_testFilterAndSort/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SilverStripe\GraphQL\Tests\Fake\DataObjectFake:
sort: true
fields:
myField: true
AuthorID: true
author:
fields:
firstName: true
Expand Down

0 comments on commit 45874f4

Please sign in to comment.