-
Notifications
You must be signed in to change notification settings - Fork 222
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
Using phpdoc as language expression #478
Comments
Hi @sylfabre, |
Hi @Vincz For instance with https://github.com/overblog/GraphQLBundle/blob/master/docs/definitions/type-system/object.md as an example:
|
@Vincz I think he means something like this: Query:
type: object
config:
fields:
author:
type: "Author"
description: '@=phpdoc("App\\Entity\\Author")'
args:
id:
description: '@=phpdoc("App\\Entity\\Author::$id")'
type: "Int"
name:
description: '@=phpdoc("App\\Entity\\Author::getName()")'
type: "String"
resolve: "@=resolver('Author', [args, info])" @sylfabre If so I find it ok. |
@murtukov you're right |
@sylfabre what behind phpdoc expression function? Is the parsing done on runtime or on Symfony container compile time? |
@mcg-web this is the code <?php
namespace App\GraphQL\ExpressionLanguage;
use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction;
class PhpDoc extends ExpressionFunction
{
public function __construct()
{
parent::__construct(
'phpdoc',
function ($string) {
// Removing backslashes and double-quotes
// App\\Entity\\AccountingBankReconciliation::\$id => App\Entity\AccountingBankReconciliation::$id
$string = substr(stripcslashes($string), 1, -1);
// Property comment
if (preg_match('/^[a-zA-Z0-9\\\\]+::\$[a-zA-Z0-9]+$/', $string)) {
list($class, $name) = explode('::$', $string);
$reflection = new \ReflectionProperty($class, $name);
} elseif (preg_match('/^[a-zA-Z0-9\\\\]+::[A-Z0-9_]+$/', $string)) {
// Constant comment
list($class, $name) = explode('::', $string);
$reflection = new \ReflectionClassConstant($class, $name);
} elseif (preg_match('/^[a-zA-Z0-9\\\\]+::[a-zA-Z0-9]+\(\)$/', $string)) {
// Method comment
list($class, $name) = explode('::', $string);
$reflection = new \ReflectionMethod($class, substr($name, 0, -2));
} else {
// Class comment
$reflection = new \ReflectionClass($string);
}
$phpdoc = $reflection->getDocComment();
// First line
$line = explode("\n", $phpdoc)[1];
// Removing spaces prefix
$line = trim($line);
// Removing '* '
$line = mb_substr($line, 2);
return '\'' . $line . '\'';
}
);
}
} The parsing is done on Symfony container compile time |
@sylfabre So eventually it dublicates the code, it just happens behind the scenes. Basically it doesn't prevent the dublication of code, it just automates it. |
@murtukov you don't have to write it two times in your code: that's why it is no longer duplicated. And yes eventually it's duplicated in the cache like the YAML config files are rewritten in PHP in the cache too. Your point about confusion is valid: the cache should be invalidated when a description is changed (like what happens when you update a YAML config file) |
At AssoConnect, we use the PHPDoc content (class, method and property) as description for GraphQL as we do not want to duplicate code/content.
We have developed a custom language expression
@phpdoc(SomeClass::$someProperty)
.Would you like a PR for this?
The text was updated successfully, but these errors were encountered: