From 0fdb8888e71a110135efd6d7ddad51e803fa4c06 Mon Sep 17 00:00:00 2001 From: Vitor Avila <96086495+Vitor-Avila@users.noreply.github.com> Date: Wed, 26 Jun 2024 17:19:12 -0300 Subject: [PATCH] fix(dbt Cloud): Update dbt metadata GraphQL query (#306) * fix(dbt Cloud): Update dbt metadata GraphQL query * Re-adding blank line * Pre-commit fix --- src/preset_cli/api/clients/dbt.py | 34 ++++++++++++++++------------- tests/api/clients/dbt_test.py | 36 ++++++++++++++++++------------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/preset_cli/api/clients/dbt.py b/src/preset_cli/api/clients/dbt.py index 0a18a77..fcd14ed 100644 --- a/src/preset_cli/api/clients/dbt.py +++ b/src/preset_cli/api/clients/dbt.py @@ -817,21 +817,23 @@ def get_og_metrics(self, job_id: int) -> List[MetricSchema]: Fetch all available metrics. """ query = """ - query GetMetrics($jobId: Int!) { - metrics(jobId: $jobId) { - uniqueId - name - label - type - sql - filters { - field - operator - value + query GetMetrics($jobId: BigInt!) { + job(id: $jobId) { + metrics { + uniqueId + name + label + type + sql + filters { + field + operator + value + } + dependsOn + description + meta } - dependsOn - description - meta } } """ @@ -842,7 +844,9 @@ def get_og_metrics(self, job_id: int) -> List[MetricSchema]: ) metric_schema = MetricSchema() - metrics = [metric_schema.load(metric) for metric in payload["data"]["metrics"]] + metrics = [ + metric_schema.load(metric) for metric in payload["data"]["job"]["metrics"] + ] return metrics diff --git a/tests/api/clients/dbt_test.py b/tests/api/clients/dbt_test.py index 62dfaa7..a7f4159 100644 --- a/tests/api/clients/dbt_test.py +++ b/tests/api/clients/dbt_test.py @@ -1135,21 +1135,27 @@ def test_dbt_client_get_og_metrics(mocker: MockerFixture) -> None: GraphqlClient = mocker.patch("preset_cli.api.clients.dbt.GraphqlClient") GraphqlClient().execute.return_value = { "data": { - "metrics": [ - { - "uniqueId": "metric.jaffle_shop.new_customers", - "name": "new_customers", - "label": "New Customers", - "type": "count", - "sql": "customer_id", - "filters": [ - {"field": "number_of_orders", "operator": ">", "value": "0"}, - ], - "dependsOn": ["model.jaffle_shop.customers"], - "description": "The number of paid customers using the product", - "meta": {}, - }, - ], + "job": { + "metrics": [ + { + "uniqueId": "metric.jaffle_shop.new_customers", + "name": "new_customers", + "label": "New Customers", + "type": "count", + "sql": "customer_id", + "filters": [ + { + "field": "number_of_orders", + "operator": ">", + "value": "0", + }, + ], + "dependsOn": ["model.jaffle_shop.customers"], + "description": "The number of paid customers using the product", + "meta": {}, + }, + ], + }, }, } auth = Auth()