Skip to content

Commit

Permalink
fix(dbt Cloud): Update dbt metadata GraphQL query (#306)
Browse files Browse the repository at this point in the history
* fix(dbt Cloud): Update dbt metadata GraphQL query
* Re-adding blank line
* Pre-commit fix
  • Loading branch information
Vitor-Avila committed Jun 26, 2024
1 parent db71964 commit 0fdb888
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
34 changes: 19 additions & 15 deletions src/preset_cli/api/clients/dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
"""
Expand All @@ -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

Expand Down
36 changes: 21 additions & 15 deletions tests/api/clients/dbt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0fdb888

Please sign in to comment.