Skip to content
This repository was archived by the owner on Feb 10, 2019. It is now read-only.

Added Relay features from obsolete "feature/relay" branch #305

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Folklore/GraphQL/Relay/ConnectionEdgeType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Folklore\GraphQL\Relay;

use GraphQL\Type\Definition\Type;
use Folklore\GraphQL\Support\Type as BaseType;

class ConnectionEdgeType extends BaseType
{
public function fields()
{
return [
'cursor' => [
'type' => Type::nonNull(Type::id())
],
'node' => [
'type' => app('graphql')->type('Node')
]
];
}

public function toType()
{
return new EdgeObjectType($this->toArray());
}
}
82 changes: 82 additions & 0 deletions src/Folklore/GraphQL/Relay/Console/ConnectionMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Folklore\GraphQL\Relay\Console;

use Illuminate\Console\GeneratorCommand;

class ConnectionMakeCommand extends GeneratorCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:relay:connection {name}';

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

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

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

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\GraphQL\Type';
}

/**
* Build the class with the given name.
*
* @param string $name
* @return string
*/
protected function buildClass($name)
{
$stub = parent::buildClass($name);

return $this->replaceType($stub, $name);
}

/**
* Replace the namespace for the given stub.
*
* @param string $stub
* @param string $name
* @return $this
*/
protected function replaceType($stub, $name)
{
preg_match('/([^\\\]+)$/', $name, $matches);
$stub = str_replace(
'DummyConnection',
$matches[1],
$stub
);

return $stub;
}
}
82 changes: 82 additions & 0 deletions src/Folklore/GraphQL/Relay/Console/InputMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Folklore\GraphQL\Relay\Console;

use Illuminate\Console\GeneratorCommand;

class InputMakeCommand extends GeneratorCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:relay:input {name}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new GraphQL Relay mutation input class';

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

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

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\GraphQL\Type';
}

/**
* Build the class with the given name.
*
* @param string $name
* @return string
*/
protected function buildClass($name)
{
$stub = parent::buildClass($name);

return $this->replaceType($stub, $name);
}

/**
* Replace the namespace for the given stub.
*
* @param string $stub
* @param string $name
* @return $this
*/
protected function replaceType($stub, $name)
{
preg_match('/([^\\\]+)$/', $name, $matches);
$stub = str_replace(
'DummyInput',
$matches[1],
$stub
);

return $stub;
}
}
82 changes: 82 additions & 0 deletions src/Folklore/GraphQL/Relay/Console/MutationMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Folklore\GraphQL\Relay\Console;

use Illuminate\Console\GeneratorCommand;

class MutationMakeCommand extends GeneratorCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:relay:mutation {name}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new GraphQL Relay mutation class';

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

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

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\GraphQL\Mutation';
}

/**
* Build the class with the given name.
*
* @param string $name
* @return string
*/
protected function buildClass($name)
{
$stub = parent::buildClass($name);

return $this->replaceType($stub, $name);
}

/**
* Replace the namespace for the given stub.
*
* @param string $stub
* @param string $name
* @return $this
*/
protected function replaceType($stub, $name)
{
preg_match('/([^\\\]+)$/', $name, $matches);
$stub = str_replace(
'DummyMutation',
$matches[1],
$stub
);

return $stub;
}
}
82 changes: 82 additions & 0 deletions src/Folklore/GraphQL/Relay/Console/NodeMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Folklore\GraphQL\Relay\Console;

use Illuminate\Console\GeneratorCommand;

class NodeMakeCommand extends GeneratorCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:relay:node {name}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new GraphQL Relay node class';

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

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

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\GraphQL\Type';
}

/**
* Build the class with the given name.
*
* @param string $name
* @return string
*/
protected function buildClass($name)
{
$stub = parent::buildClass($name);

return $this->replaceType($stub, $name);
}

/**
* Replace the namespace for the given stub.
*
* @param string $stub
* @param string $name
* @return $this
*/
protected function replaceType($stub, $name)
{
preg_match('/([^\\\]+)$/', $name, $matches);
$stub = str_replace(
'DummyType',
$matches[1],
$stub
);

return $stub;
}
}
Loading