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

Use the datasource type within queries to unmarshal them in PHP #569

Merged
merged 2 commits into from
Oct 1, 2024

Conversation

K-Phoen
Copy link
Member

@K-Phoen K-Phoen commented Oct 1, 2024

Same than #567, but for PHP

@K-Phoen K-Phoen self-assigned this Oct 1, 2024
@K-Phoen K-Phoen requested a review from a team as a code owner October 1, 2024 10:34
Copy link

github-actions bot commented Oct 1, 2024

Note: in addition to the changes introduced by this PR, the diff includes unreleased changes living in main.

🔎 Changes to grafana-foundation-sdk@next+cog-v0.0.x

diff --git a/php/src/Cog/Runtime.php b/php/src/Cog/Runtime.php
index 254a453..d759255 100644
--- a/php/src/Cog/Runtime.php
+++ b/php/src/Cog/Runtime.php
@@ -92,6 +92,11 @@ final class Runtime
      */
     public function dataqueryFromArray(array $data, string $dataqueryTypeHint): Dataquery
     {
+        // Dataqueries might reference the datasource to use, and its type. Let's use that.
+        if (empty($dataqueryTypeHint) && !empty($data['datasource']) && !empty($data['datasource']['type'])) {
+            $dataqueryTypeHint = $data['datasource']['type'];
+        }
+
         // A hint tells us the dataquery type: let's use it.
         if (!empty($dataqueryTypeHint) && isset($this->dataqueryVariants[$dataqueryTypeHint])) {
             $fromArray = $this->dataqueryVariants[$dataqueryTypeHint]->fromArray;

@K-Phoen K-Phoen merged commit c3c3e16 into main Oct 1, 2024
13 checks passed
@K-Phoen K-Phoen deleted the php/better-dataquery-unmarshal branch October 1, 2024 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants