Skip to content
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

SLB-426: GraphQL Build entity update #1535

Merged
merged 1 commit into from
Jun 7, 2024

Conversation

chindris
Copy link
Contributor

@chindris chindris commented Jun 6, 2024

Package(s) involved

silverback_gatsby

Description of changes

Once the GraphQL Build entity is saved at /admin/config/graphql/servers/build/silverback_gatsby for example (let's say the Notification user gets updated), a second update operation is not possible because the buildEntity() method of the Build entity class uses "+" to append data into the configuration entity. But the "+" operation would not overwrite existing data. One solution (which has been implemented) is to use array_merge. Another one would be to use the "+", but in a different way, something like:
$entity->schema_configuration[$entity->schema] = $form_state->getValue('schema_configuration')[$entity->schema] + $entity->schema_configuration[$entity->schema]

Related Issue(s)

GraphQL Server Build entities cannot be updated

How has this been tested?

Locally, manually.

Copy link
Contributor

@pmelab pmelab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't += supposed to be a shorthand for array merge 😅 ? Thank you for nothing PHP!

Nevertheless, thanks @chindris

@chindris
Copy link
Contributor Author

chindris commented Jun 7, 2024

Isn't += supposed to be a shorthand for array merge 😅 ? Thank you for nothing PHP!

Nevertheless, thanks @chindris

@pmelab they are similar, but not exactly the same...They do merge arrays, but in a different way, here is an excerpt from the array_merge docs ( https://www.php.net/manual/en/function.array-merge.php ):
If the input arrays have the same string keys, then the later value for that key will overwrite the previous one.
and then in one of the examples bellow, it states:
If you want to append array elements from the second array to the first array while not overwriting the elements from the first array and not re-indexing, use the + array union operator.
So by using the union operator ("+"), the elements from the first array are not overwritten.

@chindris chindris merged commit 21e025c into development Jun 7, 2024
2 of 3 checks passed
@chindris chindris deleted the SLB-426-graphql-build-entities-update branch June 7, 2024 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants