|
21 | 21 | use Nuwave\Lighthouse\Federation\Directives\KeyDirective; |
22 | 22 | use Nuwave\Lighthouse\Federation\Directives\ProvidesDirective; |
23 | 23 | use Nuwave\Lighthouse\Federation\Directives\RequiresDirective; |
| 24 | +use Nuwave\Lighthouse\Schema\RootType; |
24 | 25 |
|
25 | 26 | class FederationPrinter |
26 | 27 | { |
@@ -53,21 +54,26 @@ public static function print(Schema $schema): string |
53 | 54 | unset($types[$type]); |
54 | 55 | } |
55 | 56 |
|
56 | | - $originalQueryType = Arr::pull($types, 'Query'); |
57 | | - $config->setQuery(new ObjectType([ |
58 | | - 'name' => 'Query', |
59 | | - 'fields' => array_filter( |
60 | | - $originalQueryType->getFields(), |
61 | | - static function (FieldDefinition $field): bool { |
62 | | - return ! in_array($field->name, static::FEDERATION_FIELDS); |
63 | | - } |
64 | | - ), |
65 | | - 'interfaces' => $originalQueryType->getInterfaces(), |
66 | | - ])); |
67 | | - |
68 | | - $config->setMutation(Arr::pull($types, 'Mutation')); |
69 | | - |
70 | | - $config->setSubscription(Arr::pull($types, 'Subscription')); |
| 57 | + /** @var \GraphQL\Type\Definition\ObjectType $originalQueryType */ |
| 58 | + $originalQueryType = Arr::pull($types, RootType::QUERY); |
| 59 | + $queryFieldsWithoutFederation = array_filter( |
| 60 | + $originalQueryType->getFields(), |
| 61 | + static function (FieldDefinition $field): bool { |
| 62 | + return ! in_array($field->name, static::FEDERATION_FIELDS); |
| 63 | + } |
| 64 | + ); |
| 65 | + $newQueryType = count($queryFieldsWithoutFederation) > 0 |
| 66 | + ? new ObjectType([ |
| 67 | + 'name' => RootType::QUERY, |
| 68 | + 'fields' => $queryFieldsWithoutFederation, |
| 69 | + 'interfaces' => $originalQueryType->getInterfaces(), |
| 70 | + ]) |
| 71 | + : null; |
| 72 | + $config->setQuery($newQueryType); |
| 73 | + |
| 74 | + $config->setMutation(Arr::pull($types, RootType::MUTATION)); |
| 75 | + |
| 76 | + $config->setSubscription(Arr::pull($types, RootType::SUBSCRIPTION)); |
71 | 77 |
|
72 | 78 | $config->setTypes($types); |
73 | 79 |
|
|
0 commit comments