Skip to content

Commit

Permalink
created edge make command
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissm79 committed Aug 28, 2016
1 parent 0f44dd6 commit 3abf3cb
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/LaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function register()
Support\Console\Commands\QueryMakeCommand::class,
Support\Console\Commands\TypeMakeCommand::class,
Support\Console\Commands\ConnectionMakeCommand::class,
Support\Console\Commands\EdgeMakeCommand::class,
]);

$this->registerMacro();
Expand Down
74 changes: 74 additions & 0 deletions src/Support/Console/Commands/EdgeMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Nuwave\Lighthouse\Support\Console\Commands;

use Illuminate\Console\GeneratorCommand;

class EdgeMakeCommand extends GeneratorCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $name = 'lighthouse:edge';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate a Relay connection.';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Edge';

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return __DIR__.'/stubs/relay_edge.stub';
}

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return config('lighthouse.namespaces.edges');
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [];
}

/**
* Replace the class name for the given stub.
*
* @param string $stub
* @param string $name
* @return string
*/
protected function replaceClass($stub, $name)
{
$class = str_replace($this->getNamespace($name).'\\', '', $name);

return str_replace('DummyClass', $class, $stub);
}
}
50 changes: 50 additions & 0 deletions src/Support/Console/Commands/stubs/relay_edge.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace DummyNamespace;

use Nuwave\Lighthouse\Support\Interfaces\ConnectionEdge;

class DummyClass implements ConnectionEdge
{
/**
* Name of edge.
*
* @return string
*/
public function name()
{
return '';
}

/**
* Name of type edge resolves.
*
* @return string
*/
public function type()
{
return '';
}

/**
* Extract edge from payload.
*
* @param mixed $payload
* @return mixed
*/
public function edge($payload)
{
// return $payload[''];
}

/**
* Resolve cursor.
*
* @param mixed $payload
* @return mixed
*/
public function cursor($payload)
{
// TODO: Resolve cursor
}
}

0 comments on commit 3abf3cb

Please sign in to comment.