Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1a8eea9

Browse files
committedMar 15, 2018
Added Relay features from obsolete "feature/relay" branch as suggested in
issue folkloreinc#284
1 parent 389c38d commit 1a8eea9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3491
-0
lines changed
 
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Folklore\GraphQL\Relay;
4+
5+
use GraphQL\Type\Definition\Type;
6+
use Folklore\GraphQL\Support\Type as BaseType;
7+
8+
class ConnectionEdgeType extends BaseType
9+
{
10+
public function fields()
11+
{
12+
return [
13+
'cursor' => [
14+
'type' => Type::nonNull(Type::id())
15+
],
16+
'node' => [
17+
'type' => app('graphql')->type('Node')
18+
]
19+
];
20+
}
21+
22+
public function toType()
23+
{
24+
return new EdgeObjectType($this->toArray());
25+
}
26+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace Folklore\GraphQL\Relay\Console;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
7+
class ConnectionMakeCommand extends GeneratorCommand
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'make:relay:connection {name}';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Create a new GraphQL Relay connection';
22+
23+
/**
24+
* The type of class being generated.
25+
*
26+
* @var string
27+
*/
28+
protected $type = 'ConnectionType';
29+
30+
/**
31+
* Get the stub file for the generator.
32+
*
33+
* @return string
34+
*/
35+
protected function getStub()
36+
{
37+
return __DIR__.'/stubs/connection.stub';
38+
}
39+
40+
/**
41+
* Get the default namespace for the class.
42+
*
43+
* @param string $rootNamespace
44+
* @return string
45+
*/
46+
protected function getDefaultNamespace($rootNamespace)
47+
{
48+
return $rootNamespace.'\GraphQL\Type';
49+
}
50+
51+
/**
52+
* Build the class with the given name.
53+
*
54+
* @param string $name
55+
* @return string
56+
*/
57+
protected function buildClass($name)
58+
{
59+
$stub = parent::buildClass($name);
60+
61+
return $this->replaceType($stub, $name);
62+
}
63+
64+
/**
65+
* Replace the namespace for the given stub.
66+
*
67+
* @param string $stub
68+
* @param string $name
69+
* @return $this
70+
*/
71+
protected function replaceType($stub, $name)
72+
{
73+
preg_match('/([^\\\]+)$/', $name, $matches);
74+
$stub = str_replace(
75+
'DummyConnection',
76+
$matches[1],
77+
$stub
78+
);
79+
80+
return $stub;
81+
}
82+
}

0 commit comments

Comments
 (0)
Please sign in to comment.