Skip to content

Commit

Permalink
Merge pull request #46 from scrnhq/hotfix/45-config-reference
Browse files Browse the repository at this point in the history
Use correct reference to Bakery models, fixes #45
  • Loading branch information
robertvansteen authored Jul 11, 2018
2 parents fad5ec9 + d314d46 commit eafa412
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/Support/DefaultSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

namespace Bakery\Support;

use Bakery\Utils\Utils;

class DefaultSchema extends Schema
{
public function models()
{
return config('bakery.types', []);
$models = config('bakery.models');

Utils::invariant(count($models) > 0, 'There must be models defined in the Bakery config.');

return $models;
}
}
2 changes: 2 additions & 0 deletions src/Support/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ public function toGraphQLSchema(): GraphQLSchema
['name' => 'Query']
);

Utils::invariant(count($query->getFields()) > 0, 'There must be query fields defined in the schema.');

if (count($query->getFields()) > 0) {
$config->setQuery($query);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/FeatureTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function setUp()
$this->withFactories(__DIR__.'/factories');

// Set up default schema.
app()['config']->set('bakery.types', [
app()['config']->set('bakery.models', [
Stubs\BakeryModels\UserBakery::class,
Stubs\BakeryModels\ArticleBakery::class,
Stubs\BakeryModels\PhoneBakery::class,
Expand Down
20 changes: 17 additions & 3 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Bakery\Tests;

use Bakery\Support\Schema;
use Bakery\Support\DefaultSchema;
use Bakery\Tests\Stubs\DummyType;
use Bakery\Tests\Stubs\DummyClass;
use Bakery\Tests\Stubs\DummyModel;
Expand Down Expand Up @@ -54,11 +55,24 @@ class TestSchema extends Schema

class SchemaTest extends FeatureTestCase
{
protected function setUp()
/** @test */
public function it_throws_exception_when_there_are_no_models_defined_with_default_schema()
{
parent::setUp();
app()['config']->set('bakery.models', []);

$this->expectException(InvariantViolation::class);

$schema = new DefaultSchema();
$schema->toGraphQLSchema();
}

app()['config']->set('bakery.types', []);
/** @test */
public function it_throws_exception_when_there_are_no_query_fields_defined_in_a_schema()
{
$this->expectException(InvariantViolation::class);

$schema = new Schema();
$schema->toGraphQLSchema();
}

/** @test */
Expand Down

0 comments on commit eafa412

Please sign in to comment.