|
4 | 4 |
|
5 | 5 | use Closure;
|
6 | 6 | use GraphQL\Schema;
|
| 7 | +use GraphQL\GraphQL as GraphQLBase; |
| 8 | +use GraphQL\Type\Definition\Type; |
| 9 | +use GraphQL\Type\Definition\Directive; |
7 | 10 | use GraphQL\Type\Definition\ObjectType;
|
| 11 | +use GraphQL\Type\Definition\FieldArgument; |
| 12 | +use GraphQL\Type\Definition\DirectiveLocation; |
8 | 13 | 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; |
13 | 14 | use Nuwave\Lighthouse\Schema\Field;
|
14 | 15 | use Nuwave\Lighthouse\Schema\QueryParser;
|
15 | 16 | use Nuwave\Lighthouse\Schema\FieldParser;
|
16 | 17 | 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; |
17 | 22 |
|
18 | 23 | class GraphQL
|
19 | 24 | {
|
@@ -87,6 +92,10 @@ public function buildSchema()
|
87 | 92 | 'mutation' => $mutationType,
|
88 | 93 | 'subscription' => $subscriptionType,
|
89 | 94 | 'types' => $this->typesWithInterfaces->all(),
|
| 95 | + 'directives' => array_merge( |
| 96 | + GraphQLBase::getInternalDirectives(), |
| 97 | + [$this->connectionDirective()] |
| 98 | + ) |
90 | 99 | ]);
|
91 | 100 | }
|
92 | 101 |
|
@@ -115,6 +124,30 @@ protected function generateSchemaType(Collection $fields, $name)
|
115 | 124 | }
|
116 | 125 | }
|
117 | 126 |
|
| 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 | + |
118 | 151 | /**
|
119 | 152 | * Extract instance from type registrar.
|
120 | 153 | *
|
|
0 commit comments