-
Notifications
You must be signed in to change notification settings - Fork 16
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
EZP-32261: Added field name override #98
Conversation
ezplatform_graphql.schema.content.field_name.override: | ||
id: id_ |
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.
Is id
the only one field which might generate name collision?
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.
That's the only field that I'm aware of.
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.
OK, but please rememeber ot document this behaviour. // cc @ezsystems/documentation-team
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.
There are actually more, but they are all prefixed with _
, making collisions less likely:
_info: | |
description: "Item's content info" | |
type: Content | |
_content: | |
description: "Underlying content item" | |
type: Content | |
deprecationReason: "Renamed to _info" | |
_type: | |
description: "Item's content type" | |
type: ContentType | |
_location: | |
description: "The content's main location" | |
type: Location | |
_allLocations: | |
description: "All the content's locations" | |
type: "[Location]" | |
_name: | |
description: "The content item's name, in the prioritized language(s), based on the object name pattern" | |
type: String | |
_url: | |
description: "The content item's url alias, based on the main location." | |
type: String | |
_thumbnail: | |
type: Thumbnail |
|
||
// Workaround for https://issues.ibexa.co/browse/EZP-32261 | ||
if (\array_key_exists($fieldName, $this->fieldNameOverrides)) { | ||
return $this->fieldNameOverrides[$fieldName]; |
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.
IMHO is worth to warn user at this point that name collision happened (e.g. add warning to logs).
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.
Added a warning level log entry so it will be shown in the output of
php bin/console ezplatform:graphql:generate-schema
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.
Ideally we would rather prevent declaring fields as "id", but I guess that's the next best thing.
I would suggest making it forbidden to do so in 4.x, treating "id" (along with uppercase variations) like a PHP keyword - just not allow it. WDYT?
I agree, but we still have to keep in mind, that we have to prepare some migration scenario for the customers upgrading from (for example) 2.5 LTS, where And of course some entries in the documentation. |
/** | ||
* @var \Psr\Log\LoggerInterface | ||
*/ | ||
private $logger; |
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.
Use LoggerAwareTrait
and LoggerAwareInterface
instead.
public function __construct(LoggerInterface $logger, array $fieldNameOverrides) | ||
{ | ||
$this->caseConverter = new CamelCaseToSnakeCaseNameConverter(null, false); | ||
$this->logger = $logger; |
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.
Allow logger to be null and initialize it to NullLogger
if done so. This will make the eventual testing easier.
public function __construct(LoggerInterface $logger, array $fieldNameOverrides) | |
{ | |
$this->caseConverter = new CamelCaseToSnakeCaseNameConverter(null, false); | |
$this->logger = $logger; | |
public function __construct(array $fieldNameOverrides, ?LoggerInterface $logger = null) | |
{ | |
$this->caseConverter = new CamelCaseToSnakeCaseNameConverter(null, false); | |
$this->logger = $logger ?? new NullLogger(); |
Don't forget to import the class if this suggestion is acceptable for you.
@@ -109,7 +138,7 @@ private function pluralize($name) | |||
} | |||
|
|||
if (substr($name, -1) === 'y') { | |||
if (in_array(substr($name, -2, 1), ['a', 'e', 'i', 'o', 'u'])) { | |||
if (\in_array(substr($name, -2, 1), ['a', 'e', 'i', 'o', 'u'])) { |
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.
CS: you should rather import it with use function in_array;
@@ -124,7 +153,7 @@ private function pluralize($name) | |||
return substr($name, 0, -2) . 'i'; | |||
} | |||
|
|||
if (in_array(substr($name, -2), ['on', 'um'])) { | |||
if (\in_array(substr($name, -2), ['on', 'um'])) { |
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.
CS: the same remark as above
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.
Running php-cs-fixer fix
drops use function in_array;
and adds \in_array
🤷♂️ - I guess if I push it, CS test will fail as well.
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.
QA approved on Ibexa DXP 3.2.5-dev & v3.2.5 with patch & diff.
Could you merge it up? |
Merged to 3.0 in 7d75c68 |
Merged to master in 86f5870 |
This PR adds an option to define field name overrides to avoid issues like:
https://issues.ibexa.co/browse/EZP-32261