Skip to content

Commit

Permalink
include full namespace when registering loader
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissm79 committed Nov 19, 2016
1 parent eb65517 commit b7931c7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 30 deletions.
29 changes: 3 additions & 26 deletions src/Schema/Registrars/BaseRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use Nuwave\Lighthouse\Schema\Field;
use Nuwave\Lighthouse\Schema\SchemaBuilder as Schema;
use Nuwave\Lighthouse\Support\Traits\Container\SchemaClassRegistrar;

abstract class BaseRegistrar
{
use SchemaClassRegistrar;

/**
* Collection of registered definitions.
*
Expand Down Expand Up @@ -83,32 +86,6 @@ protected function createField($name, $namespace)
return $field;
}

/**
* Get class name.
*
* @param string $namespace
* @return string
*/
protected function getClassName($namespace)
{
$current = $this->schema->getNamespace();

return empty(trim($current)) ? $namespace : trim($current, '\\') . '\\' . $namespace;
}

/**
* Set local instance of schema container.
*
* @param Schema $schema
* @return self
*/
public function setSchema(Schema $schema)
{
$this->schema = $schema;

return $this;
}

/**
* Get instance of schema.
*
Expand Down
12 changes: 9 additions & 3 deletions src/Schema/Registrars/DataLoaderRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

namespace Nuwave\Lighthouse\Schema\Registrars;

use Nuwave\Lighthouse\Support\Traits\Container\SchemaClassRegistrar;

class DataLoaderRegistrar
{
use SchemaClassRegistrar;

/**
* Add Data Loader to registrar.
*
* @param string $name
* @param string $loader
* @param string $name
* @param string $namespace
* @return bool
*/
public function register($name, $loader)
public function register($name, $namespace)
{
$loader = $this->getClassName($namespace);

app()->singleton($loader);
app()->alias($loader, $this->alias($name));

Expand Down
6 changes: 5 additions & 1 deletion src/Support/Traits/Container/CentralRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ public function getCursorRegistrar()
*/
public function getDataLoaderRegistrar()
{
return app(DataLoaderRegistrar::class);
if (! $this->loaderRegistrar) {
$this->loaderRegistrar = app(DataLoaderRegistrar::class)->setSchema($this);
}

return $this->loaderRegistrar;
}
}
34 changes: 34 additions & 0 deletions src/Support/Traits/Container/SchemaClassRegistrar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Nuwave\Lighthouse\Support\Traits\Container;

use Nuwave\Lighthouse\Schema\SchemaBuilder;

trait SchemaClassRegistrar
{
/**
* Set local instance of schema container.
*
* @param SchemaBuilder $schema
* @return self
*/
public function setSchema(SchemaBuilder $schema)
{
$this->schema = $schema;

return $this;
}

/**
* Get class name.
*
* @param string $namespace
* @return string
*/
protected function getClassName($namespace)
{
$current = $this->schema->getNamespace();

return empty(trim($current)) ? $namespace : trim($current, '\\') . '\\' . $namespace;
}
}

0 comments on commit b7931c7

Please sign in to comment.