-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API Add Directive types #580
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/* @var object $scope */ | ||
/* @var \SilverStripe\GraphQL\Schema\Type\Directive $directive */ | ||
/* @var array $globals */ | ||
?> | ||
<?php $directive = $scope; ?> | ||
namespace <?=$globals['namespace']; ?>; | ||
|
||
use GraphQL\Type\Definition\Directive; | ||
|
||
// @type:<?=$directive->getName(); ?> | ||
|
||
class <?=$globals['obfuscator']->obfuscate($directive->getName()) ?> extends Directive | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct([ | ||
'name' => '<?=$directive->getName() ?>', | ||
<?php if (!empty($directive->getDescription())) : ?> | ||
'description' => '<?=addslashes($directive->getDescription()); ?>', | ||
<?php endif; ?> | ||
|
||
'locations' => [ | ||
<?php foreach ($directive->getLocations() as $location) : ?> | ||
'<?=$location; ?>', | ||
<?php endforeach; ?> | ||
], // locations | ||
<?php if (!empty($directive->getArgs())) : ?> | ||
'args' => [ | ||
<?php foreach ($directive->getArgs() as $arg) : ?> | ||
[ | ||
'name' => '<?=$arg->getName(); ?>', | ||
'type' => <?=$arg->getEncodedType()->encode(); ?>, | ||
<?php if ($arg->getDefaultValue() !== null) : ?> | ||
'defaultValue' => <?=var_export($arg->getDefaultValue(), true); ?>, | ||
<?php endif; ?> | ||
], // arg | ||
<?php endforeach; ?> | ||
], // args | ||
<?php endif; ?> | ||
]); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,27 @@ public static function <?=$component->getName(); ?>() { return static::get('<?=$ | |
<?php endforeach; ?> | ||
|
||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably breaks some PSR specs, I'm not sure if it matters here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You say "this" on a comment on an empty line... but I assume you are actually referring to having multiple classes defined in the same file? That does break PSR1 (see the PSR1 spec). One approach would be to reuse the same template file (with only one clsas definition) for both of these since they're practically identical, and just add appropriate conditional statements. e.g. type.inc.php uses a lot of conditional logic to build its class. |
||
class <?=$globals['directiveClassName']; ?> extends AbstractTypeRegistry | ||
{ | ||
protected static $types = []; | ||
|
||
protected static function getSourceDirectory(): string | ||
{ | ||
return __DIR__; | ||
} | ||
|
||
protected static function getSourceNamespace(): string | ||
{ | ||
return __NAMESPACE__; | ||
} | ||
|
||
public static function directives() { | ||
return [ | ||
<?php foreach ($globals['directives'] as $directive) : ?> | ||
static::get('<?=$directive->getName(); ?>'), | ||
<?php endforeach; ?> | ||
]; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this change made? It seems unrelated