From 7385ac368624a3a0a191d92b4620a8b1215f3840 Mon Sep 17 00:00:00 2001 From: Yian Shang Date: Fri, 10 Jan 2025 08:12:58 -0800 Subject: [PATCH] Move inputs to query file --- .../api/graphql/queries/sql.py | 52 +++++++++++++++++-- .../api/graphql/scalars/sql.py | 47 ----------------- 2 files changed, 47 insertions(+), 52 deletions(-) diff --git a/datajunction-server/datajunction_server/api/graphql/queries/sql.py b/datajunction-server/datajunction_server/api/graphql/queries/sql.py index 35244c1dd..7b068f864 100644 --- a/datajunction-server/datajunction_server/api/graphql/queries/sql.py +++ b/datajunction-server/datajunction_server/api/graphql/queries/sql.py @@ -4,14 +4,56 @@ import strawberry from strawberry.types import Info -from datajunction_server.api.graphql.scalars.sql import ( - CubeDefinition, - EngineSettings, - GeneratedSQL, -) +from datajunction_server.api.graphql.scalars.sql import GeneratedSQL from datajunction_server.construction.build_v2 import get_measures_query +@strawberry.input +class CubeDefinition: # pylint: disable=too-few-public-methods + """ + The cube definition for the query + """ + + metrics: Annotated[ + list[str], + strawberry.argument( + description="A list of metric node names", + ), + ] = None # type: ignore + dimensions: Annotated[ + list[str] | None, + strawberry.argument( + description="A list of dimension attribute names", + ), + ] = None + filters: Annotated[ + list[str] | None, + strawberry.argument( + description="A list of filter SQL clauses", + ), + ] = None + orderby: Annotated[ + list[str] | None, + strawberry.argument( + description="A list of order by clauses", + ), + ] = None + + +@strawberry.input +class EngineSettings: # pylint: disable=too-few-public-methods + """ + The engine settings for the query + """ + + name: str = strawberry.field( + description="The name of the engine used by the generated SQL", + ) + version: str | None = strawberry.field( + description="The version of the engine used by the generated SQL", + ) + + async def measures_sql( cube: CubeDefinition, engine: Optional[EngineSettings] = None, diff --git a/datajunction-server/datajunction_server/api/graphql/scalars/sql.py b/datajunction-server/datajunction_server/api/graphql/scalars/sql.py index 7ea6977a9..91cccfa71 100644 --- a/datajunction-server/datajunction_server/api/graphql/scalars/sql.py +++ b/datajunction-server/datajunction_server/api/graphql/scalars/sql.py @@ -1,6 +1,5 @@ """SQL-related scalars.""" from functools import cached_property -from typing import Annotated import strawberry from strawberry.types import Info @@ -20,52 +19,6 @@ QueryBuildType = strawberry.enum(QueryBuildType_) -@strawberry.input -class CubeDefinition: # pylint: disable=too-few-public-methods - """ - The cube definition for the query - """ - - metrics: Annotated[ - list[str], - strawberry.argument( - description="A list of metric node names", - ), - ] = None # type: ignore - dimensions: Annotated[ - list[str] | None, - strawberry.argument( - description="A list of dimension attribute names", - ), - ] = None - filters: Annotated[ - list[str] | None, - strawberry.argument( - description="A list of filter SQL clauses", - ), - ] = None - orderby: Annotated[ - list[str] | None, - strawberry.argument( - description="A list of order by clauses", - ), - ] = None - - -@strawberry.input -class EngineSettings: # pylint: disable=too-few-public-methods - """ - The engine settings for the query - """ - - name: str = strawberry.field( - description="The name of the engine used by the generated SQL", - ) - version: str | None = strawberry.field( - description="The version of the engine used by the generated SQL", - ) - - @strawberry.type class SemanticEntity: """