Skip to content

Commit 2ac5f8b

Browse files
committed
add connection directive
1 parent d89f2d8 commit 2ac5f8b

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

src/GraphQL.php

+37-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44

55
use Closure;
66
use GraphQL\Schema;
7+
use GraphQL\GraphQL as GraphQLBase;
8+
use GraphQL\Type\Definition\Type;
9+
use GraphQL\Type\Definition\Directive;
710
use GraphQL\Type\Definition\ObjectType;
11+
use GraphQL\Type\Definition\FieldArgument;
12+
use GraphQL\Type\Definition\DirectiveLocation;
813
use Illuminate\Support\Collection;
9-
use Nuwave\Lighthouse\Support\Traits\Container\QueryExecutor;
10-
use Nuwave\Lighthouse\Support\Traits\Container\ScalarTypes;
11-
use Nuwave\Lighthouse\Support\Interfaces\Connection;
12-
use Nuwave\Lighthouse\Support\Cache\FileStore;
1314
use Nuwave\Lighthouse\Schema\Field;
1415
use Nuwave\Lighthouse\Schema\QueryParser;
1516
use Nuwave\Lighthouse\Schema\FieldParser;
1617
use Nuwave\Lighthouse\Schema\SchemaBuilder;
18+
use Nuwave\Lighthouse\Support\Cache\FileStore;
19+
use Nuwave\Lighthouse\Support\Interfaces\Connection;
20+
use Nuwave\Lighthouse\Support\Traits\Container\ScalarTypes;
21+
use Nuwave\Lighthouse\Support\Traits\Container\QueryExecutor;
1722

1823
class GraphQL
1924
{
@@ -87,6 +92,10 @@ public function buildSchema()
8792
'mutation' => $mutationType,
8893
'subscription' => $subscriptionType,
8994
'types' => $this->typesWithInterfaces->all(),
95+
'directives' => array_merge(
96+
GraphQLBase::getInternalDirectives(),
97+
[$this->connectionDirective()]
98+
)
9099
]);
91100
}
92101

@@ -115,6 +124,30 @@ protected function generateSchemaType(Collection $fields, $name)
115124
}
116125
}
117126

127+
/**
128+
* Generate a connection directive
129+
* TODO: Allow directives to be added to the schema by the user.
130+
* Currently this allows the use of the connection directive in Apollo client.
131+
*
132+
* @return Directive
133+
*/
134+
protected function connectionDirective()
135+
{
136+
return new Directive([
137+
'name' => 'connection',
138+
'description' => '',
139+
'locations' => [DirectiveLocation::FIELD, DirectiveLocation::FIELD_DEFINITION],
140+
'args' => [
141+
new FieldArgument([
142+
'name' => 'key',
143+
'type' => Type::string(),
144+
'description' => '',
145+
'defaultValue' => ''
146+
])
147+
]
148+
]);
149+
}
150+
118151
/**
119152
* Extract instance from type registrar.
120153
*

0 commit comments

Comments
 (0)