-
-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
122 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Nuwave\Lighthouse\Federation; | ||
|
||
use GraphQL\Language\AST\DirectiveNode; | ||
use GraphQL\Type\Schema; | ||
use Nuwave\Lighthouse\Schema\AST\ASTHelper; | ||
|
||
class FederationHelper | ||
{ | ||
/** @return array<string> */ | ||
public static function composedDirectives(Schema $schema): array | ||
{ | ||
$composedDirectives = []; | ||
|
||
foreach ($schema->extensionASTNodes as $extension) { | ||
foreach (ASTHelper::directiveDefinitions($extension, 'composeDirective') as $directive) { | ||
$name = ASTHelper::directiveArgValue($directive, 'name'); | ||
|
||
if (! is_string($name)) { | ||
continue; | ||
} | ||
|
||
$composedDirectives[] = ltrim($name, '@'); | ||
} | ||
} | ||
|
||
return $composedDirectives; | ||
} | ||
|
||
/** @return array<DirectiveNode> */ | ||
public static function schemaDirectives(Schema $schema): array | ||
{ | ||
$schemaDirectives = []; | ||
|
||
foreach ($schema->extensionASTNodes as $extension) { | ||
foreach ($extension->directives as $directive) { | ||
assert($directive instanceof DirectiveNode); | ||
|
||
$schemaDirectives[] = $directive; | ||
} | ||
} | ||
|
||
return $schemaDirectives; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tests\Utils\Directives; | ||
|
||
use Nuwave\Lighthouse\Schema\Directives\BaseDirective; | ||
|
||
final class BarDirective extends BaseDirective | ||
{ | ||
public static function definition(): string | ||
{ | ||
return /** @lang GraphQL */ <<<'GRAPHQL' | ||
""" | ||
Maximum foo. | ||
""" | ||
directive @bar on FIELD_DEFINITION | ||
GRAPHQL; | ||
} | ||
} |