diff --git a/README.md b/README.md index 5ac7544c..72c6ba31 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ To run code generation manually: ```shell pip install ariadne-codegen -ariadne-codegen +python -m ariadne_codegen ``` ariadne-codegen runs automatically via pre-commit hooks and CI/CD when GraphQL files are modified. diff --git a/openhexa/cli/api.py b/openhexa/cli/api.py index 1739564e..deb519e8 100644 --- a/openhexa/cli/api.py +++ b/openhexa/cli/api.py @@ -11,10 +11,12 @@ from datetime import datetime from importlib.metadata import version from pathlib import Path +from typing import Any from zipfile import ZipFile import click import docker +import httpx import requests from docker.models.containers import Container from graphql import build_client_schema, build_schema, get_introspection_query @@ -760,6 +762,9 @@ def execute(self, query, **kwargs): """Decorate parent execute method to log the GraphQL query and response.""" _detect_graphql_breaking_changes(token=self.token) + if self.token is None: + raise InvalidTokenError("No token found for workspace") + if settings.debug: click.echo("") click.echo("Graphql Query:") @@ -776,3 +781,13 @@ def execute(self, query, **kwargs): click.echo(f"Response: {response}") return response + + def get_data(self, response: httpx.Response) -> dict[str, Any]: + """Get the data from the response, handling errors and authentication issues.""" + try: + data = super().get_data(response) + except Exception as e: + if "Resolver requires an authenticated user" in str(e): + raise InvalidTokenError("No or invalid token found for workspace, please check your configuration.") + raise + return data diff --git a/openhexa/graphql/graphql_client/__init__.py b/openhexa/graphql/graphql_client/__init__.py index 629bc82b..6d4f1fc6 100644 --- a/openhexa/graphql/graphql_client/__init__.py +++ b/openhexa/graphql/graphql_client/__init__.py @@ -156,7 +156,6 @@ MembershipRole, MessagePriority, OrderByDirection, - OrganizationMembershipRole, ParameterType, ParameterWidget, PermissionMode, @@ -328,20 +327,6 @@ InviteWorkspaceMemberInviteWorkspaceMember, InviteWorkspaceMemberInviteWorkspaceMemberWorkspaceMembership, ) -from .organization import ( - Organization, - OrganizationOrganization, - OrganizationOrganizationPermissions, - OrganizationOrganizationWorkspaces, - OrganizationOrganizationWorkspacesItems, - OrganizationOrganizationWorkspacesItemsCountries, -) -from .organizations import ( - Organizations, - OrganizationsOrganizations, - OrganizationsOrganizationsWorkspaces, - OrganizationsOrganizationsWorkspacesItems, -) from .pipeline import ( Pipeline, PipelinePipelineByCode, @@ -610,18 +595,7 @@ "MembershipRole", "MessagePriority", "OrderByDirection", - "Organization", "OrganizationInput", - "OrganizationMembershipRole", - "OrganizationOrganization", - "OrganizationOrganizationPermissions", - "OrganizationOrganizationWorkspaces", - "OrganizationOrganizationWorkspacesItems", - "OrganizationOrganizationWorkspacesItemsCountries", - "Organizations", - "OrganizationsOrganizations", - "OrganizationsOrganizationsWorkspaces", - "OrganizationsOrganizationsWorkspacesItems", "ParameterInput", "ParameterType", "ParameterWidget", diff --git a/openhexa/graphql/graphql_client/client.py b/openhexa/graphql/graphql_client/client.py index c3a20332..b2e0db76 100644 --- a/openhexa/graphql/graphql_client/client.py +++ b/openhexa/graphql/graphql_client/client.py @@ -72,8 +72,6 @@ InviteWorkspaceMember, InviteWorkspaceMemberInviteWorkspaceMember, ) -from .organization import Organization, OrganizationOrganization -from .organizations import Organizations, OrganizationsOrganizations from .pipeline import Pipeline, PipelinePipelineByCode from .pipelines import Pipelines, PipelinesPipelines from .remove_webapp_from_favorites import ( @@ -796,64 +794,6 @@ def delete_connection( data = self.get_data(response) return DeleteConnection.model_validate(data).delete_connection - def organization( - self, id: Any, **kwargs: Any - ) -> Optional[OrganizationOrganization]: - query = gql( - """ - query Organization($id: UUID!) { - organization(id: $id) { - id - name - shortName - workspaces { - items { - slug - name - countries { - code - } - } - } - permissions { - createWorkspace - archiveWorkspace - } - } - } - """ - ) - variables: Dict[str, object] = {"id": id} - response = self.execute( - query=query, operation_name="Organization", variables=variables, **kwargs - ) - data = self.get_data(response) - return Organization.model_validate(data).organization - - def organizations(self, **kwargs: Any) -> List[OrganizationsOrganizations]: - query = gql( - """ - query Organizations { - organizations { - id - name - workspaces { - items { - slug - name - } - } - } - } - """ - ) - variables: Dict[str, object] = {} - response = self.execute( - query=query, operation_name="Organizations", variables=variables, **kwargs - ) - data = self.get_data(response) - return Organizations.model_validate(data).organizations - def get_users( self, query: str, workspace_slug: str, **kwargs: Any ) -> List[GetUsersUsers]: diff --git a/openhexa/graphql/graphql_client/enums.py b/openhexa/graphql/graphql_client/enums.py index 6805a7c9..7e6823fd 100644 --- a/openhexa/graphql/graphql_client/enums.py +++ b/openhexa/graphql/graphql_client/enums.py @@ -461,12 +461,6 @@ class OrderByDirection(str, Enum): DESC = "DESC" -class OrganizationMembershipRole(str, Enum): - ADMIN = "ADMIN" - MEMBER = "MEMBER" - OWNER = "OWNER" - - class ParameterType(str, Enum): bool = "bool" custom = "custom" diff --git a/openhexa/graphql/graphql_client/input_types.py b/openhexa/graphql/graphql_client/input_types.py index 9f99fd2a..fc8967da 100644 --- a/openhexa/graphql/graphql_client/input_types.py +++ b/openhexa/graphql/graphql_client/input_types.py @@ -173,7 +173,6 @@ class CreateWorkspaceInput(BaseModel): description: Optional[str] = None load_sample_data: Optional[bool] = Field(alias="loadSampleData", default=None) name: str - organization_id: Optional[Any] = Field(alias="organizationId", default=None) slug: Optional[str] = None diff --git a/openhexa/graphql/queries.graphql b/openhexa/graphql/queries.graphql index c162ae0a..10972fcb 100644 --- a/openhexa/graphql/queries.graphql +++ b/openhexa/graphql/queries.graphql @@ -305,39 +305,39 @@ mutation DeleteConnection($input: DeleteConnectionInput!) { } } -query Organization($id: UUID!) { - organization(id: $id) { - id - name - shortName - workspaces { - items { - slug - name - countries { - code - } - } - } - permissions { - createWorkspace - archiveWorkspace - } - } -} - -query Organizations { - organizations { - id - name - workspaces { - items { - slug - name - } - } - } -} +#query Organization($id: UUID!) { +# organization(id: $id) { +# id +# name +# shortName +# workspaces { +# items { +# slug +# name +# countries { +# code +# } +# } +# } +# permissions { +# createWorkspace +# archiveWorkspace +# } +# } +#} +# +#query Organizations { +# organizations { +# id +# name +# workspaces { +# items { +# slug +# name +# } +# } +# } +#} query GetUsers($query: String!, $workspaceSlug: String!) { users(query: $query, workspaceSlug: $workspaceSlug) { diff --git a/openhexa/graphql/schema.generated.graphql b/openhexa/graphql/schema.generated.graphql index bc5b601f..0d6a3862 100644 --- a/openhexa/graphql/schema.generated.graphql +++ b/openhexa/graphql/schema.generated.graphql @@ -890,7 +890,6 @@ input CreateWorkspaceInput { description: String loadSampleData: Boolean name: String! - organizationId: UUID slug: String } @@ -2452,26 +2451,14 @@ type Organization { """The unique identifier of the organization.""" id: UUID! - """The members of the organization.""" - members(page: Int, perPage: Int): OrganizationMembershipPage! - """The name of the organization.""" name: String! - """The permissions the current user has in the organization.""" - permissions: OrganizationPermissions! - - """The short name of the organization.""" - shortName: String - """The type of the organization.""" type: String! """The URL of the organization.""" url: String! - - """The workspaces associated with the organization.""" - workspaces(page: Int, perPage: Int): WorkspacePage! } """ @@ -2494,36 +2481,6 @@ input OrganizationInput { url: String } -"""Represents a membership in an organization.""" -type OrganizationMembership { - createdAt: DateTime! - id: UUID! - organization: Organization! - role: OrganizationMembershipRole! - updatedAt: DateTime - user: User! -} - -"""Represents a page of organization memberships.""" -type OrganizationMembershipPage { - items: [WorkspaceMembership!]! - pageNumber: Int! - totalItems: Int! - totalPages: Int! -} - -"""Represents the role of a organization membership.""" -enum OrganizationMembershipRole { - ADMIN - MEMBER - OWNER -} - -type OrganizationPermissions { - archiveWorkspace: Boolean! - createWorkspace: Boolean! -} - """Represents an input parameter of a pipeline.""" input ParameterInput { choices: [Generic!] @@ -3063,7 +3020,6 @@ type Query { me: Me! metadataAttributes(targetId: OpaqueID!): [MetadataAttribute]! notebooksUrl: URL! - organization(id: UUID!): Organization """Retrieves a list of organizations.""" organizations: [Organization!]! @@ -3086,11 +3042,11 @@ type Query { """Retrieves a page of pipelines ordered by relevant name.""" pipelines(name: String, page: Int, perPage: Int, search: String, workspaceSlug: String): PipelinesPage! - searchDatabaseTables(organizationId: UUID, page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]): DatabaseTableResultPage! - searchDatasets(organizationId: UUID, page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]): DatasetResultPage! - searchFiles(organizationId: UUID, page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]): FileResultPage! - searchPipelineTemplates(organizationId: UUID, page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]): PipelineTemplateResultPage! - searchPipelines(organizationId: UUID, page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]): PipelineResultPage! + searchDatabaseTables(page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]!): DatabaseTableResultPage! + searchDatasets(page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]!): DatasetResultPage! + searchFiles(page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]!): FileResultPage! + searchPipelineTemplates(page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]!): PipelineTemplateResultPage! + searchPipelines(page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]!): PipelineResultPage! team(id: UUID!): Team teams(page: Int, perPage: Int, term: String): TeamPage! @@ -3104,7 +3060,7 @@ type Query { webapp(id: UUID!): Webapp webapps(favorite: Boolean, page: Int, perPage: Int, workspaceSlug: String): WebappsPage! workspace(slug: String!): Workspace - workspaces(organizationId: UUID, page: Int, perPage: Int, query: String): WorkspacePage! + workspaces(page: Int, perPage: Int, query: String): WorkspacePage! } """ @@ -4147,7 +4103,6 @@ type Workspace { invitations(includeAccepted: Boolean, page: Int, perPage: Int): WorkspaceInvitationPage! members(page: Int, perPage: Int): WorkspaceMembershipPage! name: String! - organization: Organization permissions: WorkspacePermissions! slug: String! updatedAt: DateTime