Skip to content

Commit cdb901f

Browse files
authored
fix: Set schema to Prod/Demo schema, handle exception gracefully (#288)
1 parent a537dee commit cdb901f

File tree

8 files changed

+55
-178
lines changed

8 files changed

+55
-178
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ To run code generation manually:
163163

164164
```shell
165165
pip install ariadne-codegen
166-
ariadne-codegen
166+
python -m ariadne_codegen
167167
```
168168

169169
ariadne-codegen runs automatically via pre-commit hooks and CI/CD when GraphQL files are modified.

openhexa/cli/api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
from datetime import datetime
1212
from importlib.metadata import version
1313
from pathlib import Path
14+
from typing import Any
1415
from zipfile import ZipFile
1516

1617
import click
1718
import docker
19+
import httpx
1820
import requests
1921
from docker.models.containers import Container
2022
from graphql import build_client_schema, build_schema, get_introspection_query
@@ -760,6 +762,9 @@ def execute(self, query, **kwargs):
760762
"""Decorate parent execute method to log the GraphQL query and response."""
761763
_detect_graphql_breaking_changes(token=self.token)
762764

765+
if self.token is None:
766+
raise InvalidTokenError("No token found for workspace")
767+
763768
if settings.debug:
764769
click.echo("")
765770
click.echo("Graphql Query:")
@@ -776,3 +781,13 @@ def execute(self, query, **kwargs):
776781
click.echo(f"Response: {response}")
777782

778783
return response
784+
785+
def get_data(self, response: httpx.Response) -> dict[str, Any]:
786+
"""Get the data from the response, handling errors and authentication issues."""
787+
try:
788+
data = super().get_data(response)
789+
except Exception as e:
790+
if "Resolver requires an authenticated user" in str(e):
791+
raise InvalidTokenError("No or invalid token found for workspace, please check your configuration.")
792+
raise
793+
return data

openhexa/graphql/graphql_client/__init__.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@
156156
MembershipRole,
157157
MessagePriority,
158158
OrderByDirection,
159-
OrganizationMembershipRole,
160159
ParameterType,
161160
ParameterWidget,
162161
PermissionMode,
@@ -328,20 +327,6 @@
328327
InviteWorkspaceMemberInviteWorkspaceMember,
329328
InviteWorkspaceMemberInviteWorkspaceMemberWorkspaceMembership,
330329
)
331-
from .organization import (
332-
Organization,
333-
OrganizationOrganization,
334-
OrganizationOrganizationPermissions,
335-
OrganizationOrganizationWorkspaces,
336-
OrganizationOrganizationWorkspacesItems,
337-
OrganizationOrganizationWorkspacesItemsCountries,
338-
)
339-
from .organizations import (
340-
Organizations,
341-
OrganizationsOrganizations,
342-
OrganizationsOrganizationsWorkspaces,
343-
OrganizationsOrganizationsWorkspacesItems,
344-
)
345330
from .pipeline import (
346331
Pipeline,
347332
PipelinePipelineByCode,
@@ -610,18 +595,7 @@
610595
"MembershipRole",
611596
"MessagePriority",
612597
"OrderByDirection",
613-
"Organization",
614598
"OrganizationInput",
615-
"OrganizationMembershipRole",
616-
"OrganizationOrganization",
617-
"OrganizationOrganizationPermissions",
618-
"OrganizationOrganizationWorkspaces",
619-
"OrganizationOrganizationWorkspacesItems",
620-
"OrganizationOrganizationWorkspacesItemsCountries",
621-
"Organizations",
622-
"OrganizationsOrganizations",
623-
"OrganizationsOrganizationsWorkspaces",
624-
"OrganizationsOrganizationsWorkspacesItems",
625599
"ParameterInput",
626600
"ParameterType",
627601
"ParameterWidget",

openhexa/graphql/graphql_client/client.py

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@
7272
InviteWorkspaceMember,
7373
InviteWorkspaceMemberInviteWorkspaceMember,
7474
)
75-
from .organization import Organization, OrganizationOrganization
76-
from .organizations import Organizations, OrganizationsOrganizations
7775
from .pipeline import Pipeline, PipelinePipelineByCode
7876
from .pipelines import Pipelines, PipelinesPipelines
7977
from .remove_webapp_from_favorites import (
@@ -796,64 +794,6 @@ def delete_connection(
796794
data = self.get_data(response)
797795
return DeleteConnection.model_validate(data).delete_connection
798796

799-
def organization(
800-
self, id: Any, **kwargs: Any
801-
) -> Optional[OrganizationOrganization]:
802-
query = gql(
803-
"""
804-
query Organization($id: UUID!) {
805-
organization(id: $id) {
806-
id
807-
name
808-
shortName
809-
workspaces {
810-
items {
811-
slug
812-
name
813-
countries {
814-
code
815-
}
816-
}
817-
}
818-
permissions {
819-
createWorkspace
820-
archiveWorkspace
821-
}
822-
}
823-
}
824-
"""
825-
)
826-
variables: Dict[str, object] = {"id": id}
827-
response = self.execute(
828-
query=query, operation_name="Organization", variables=variables, **kwargs
829-
)
830-
data = self.get_data(response)
831-
return Organization.model_validate(data).organization
832-
833-
def organizations(self, **kwargs: Any) -> List[OrganizationsOrganizations]:
834-
query = gql(
835-
"""
836-
query Organizations {
837-
organizations {
838-
id
839-
name
840-
workspaces {
841-
items {
842-
slug
843-
name
844-
}
845-
}
846-
}
847-
}
848-
"""
849-
)
850-
variables: Dict[str, object] = {}
851-
response = self.execute(
852-
query=query, operation_name="Organizations", variables=variables, **kwargs
853-
)
854-
data = self.get_data(response)
855-
return Organizations.model_validate(data).organizations
856-
857797
def get_users(
858798
self, query: str, workspace_slug: str, **kwargs: Any
859799
) -> List[GetUsersUsers]:

openhexa/graphql/graphql_client/enums.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,6 @@ class OrderByDirection(str, Enum):
461461
DESC = "DESC"
462462

463463

464-
class OrganizationMembershipRole(str, Enum):
465-
ADMIN = "ADMIN"
466-
MEMBER = "MEMBER"
467-
OWNER = "OWNER"
468-
469-
470464
class ParameterType(str, Enum):
471465
bool = "bool"
472466
custom = "custom"

openhexa/graphql/graphql_client/input_types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ class CreateWorkspaceInput(BaseModel):
173173
description: Optional[str] = None
174174
load_sample_data: Optional[bool] = Field(alias="loadSampleData", default=None)
175175
name: str
176-
organization_id: Optional[Any] = Field(alias="organizationId", default=None)
177176
slug: Optional[str] = None
178177

179178

openhexa/graphql/queries.graphql

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -305,39 +305,39 @@ mutation DeleteConnection($input: DeleteConnectionInput!) {
305305
}
306306
}
307307

308-
query Organization($id: UUID!) {
309-
organization(id: $id) {
310-
id
311-
name
312-
shortName
313-
workspaces {
314-
items {
315-
slug
316-
name
317-
countries {
318-
code
319-
}
320-
}
321-
}
322-
permissions {
323-
createWorkspace
324-
archiveWorkspace
325-
}
326-
}
327-
}
328-
329-
query Organizations {
330-
organizations {
331-
id
332-
name
333-
workspaces {
334-
items {
335-
slug
336-
name
337-
}
338-
}
339-
}
340-
}
308+
#query Organization($id: UUID!) {
309+
# organization(id: $id) {
310+
# id
311+
# name
312+
# shortName
313+
# workspaces {
314+
# items {
315+
# slug
316+
# name
317+
# countries {
318+
# code
319+
# }
320+
# }
321+
# }
322+
# permissions {
323+
# createWorkspace
324+
# archiveWorkspace
325+
# }
326+
# }
327+
#}
328+
#
329+
#query Organizations {
330+
# organizations {
331+
# id
332+
# name
333+
# workspaces {
334+
# items {
335+
# slug
336+
# name
337+
# }
338+
# }
339+
# }
340+
#}
341341

342342
query GetUsers($query: String!, $workspaceSlug: String!) {
343343
users(query: $query, workspaceSlug: $workspaceSlug) {

openhexa/graphql/schema.generated.graphql

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,6 @@ input CreateWorkspaceInput {
890890
description: String
891891
loadSampleData: Boolean
892892
name: String!
893-
organizationId: UUID
894893
slug: String
895894
}
896895

@@ -2452,26 +2451,14 @@ type Organization {
24522451
"""The unique identifier of the organization."""
24532452
id: UUID!
24542453

2455-
"""The members of the organization."""
2456-
members(page: Int, perPage: Int): OrganizationMembershipPage!
2457-
24582454
"""The name of the organization."""
24592455
name: String!
24602456

2461-
"""The permissions the current user has in the organization."""
2462-
permissions: OrganizationPermissions!
2463-
2464-
"""The short name of the organization."""
2465-
shortName: String
2466-
24672457
"""The type of the organization."""
24682458
type: String!
24692459

24702460
"""The URL of the organization."""
24712461
url: String!
2472-
2473-
"""The workspaces associated with the organization."""
2474-
workspaces(page: Int, perPage: Int): WorkspacePage!
24752462
}
24762463

24772464
"""
@@ -2494,36 +2481,6 @@ input OrganizationInput {
24942481
url: String
24952482
}
24962483

2497-
"""Represents a membership in an organization."""
2498-
type OrganizationMembership {
2499-
createdAt: DateTime!
2500-
id: UUID!
2501-
organization: Organization!
2502-
role: OrganizationMembershipRole!
2503-
updatedAt: DateTime
2504-
user: User!
2505-
}
2506-
2507-
"""Represents a page of organization memberships."""
2508-
type OrganizationMembershipPage {
2509-
items: [WorkspaceMembership!]!
2510-
pageNumber: Int!
2511-
totalItems: Int!
2512-
totalPages: Int!
2513-
}
2514-
2515-
"""Represents the role of a organization membership."""
2516-
enum OrganizationMembershipRole {
2517-
ADMIN
2518-
MEMBER
2519-
OWNER
2520-
}
2521-
2522-
type OrganizationPermissions {
2523-
archiveWorkspace: Boolean!
2524-
createWorkspace: Boolean!
2525-
}
2526-
25272484
"""Represents an input parameter of a pipeline."""
25282485
input ParameterInput {
25292486
choices: [Generic!]
@@ -3063,7 +3020,6 @@ type Query {
30633020
me: Me!
30643021
metadataAttributes(targetId: OpaqueID!): [MetadataAttribute]!
30653022
notebooksUrl: URL!
3066-
organization(id: UUID!): Organization
30673023

30683024
"""Retrieves a list of organizations."""
30693025
organizations: [Organization!]!
@@ -3086,11 +3042,11 @@ type Query {
30863042

30873043
"""Retrieves a page of pipelines ordered by relevant name."""
30883044
pipelines(name: String, page: Int, perPage: Int, search: String, workspaceSlug: String): PipelinesPage!
3089-
searchDatabaseTables(organizationId: UUID, page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]): DatabaseTableResultPage!
3090-
searchDatasets(organizationId: UUID, page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]): DatasetResultPage!
3091-
searchFiles(organizationId: UUID, page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]): FileResultPage!
3092-
searchPipelineTemplates(organizationId: UUID, page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]): PipelineTemplateResultPage!
3093-
searchPipelines(organizationId: UUID, page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]): PipelineResultPage!
3045+
searchDatabaseTables(page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]!): DatabaseTableResultPage!
3046+
searchDatasets(page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]!): DatasetResultPage!
3047+
searchFiles(page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]!): FileResultPage!
3048+
searchPipelineTemplates(page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]!): PipelineTemplateResultPage!
3049+
searchPipelines(page: Int = 1, perPage: Int = 15, query: String!, workspaceSlugs: [String]!): PipelineResultPage!
30943050
team(id: UUID!): Team
30953051
teams(page: Int, perPage: Int, term: String): TeamPage!
30963052

@@ -3104,7 +3060,7 @@ type Query {
31043060
webapp(id: UUID!): Webapp
31053061
webapps(favorite: Boolean, page: Int, perPage: Int, workspaceSlug: String): WebappsPage!
31063062
workspace(slug: String!): Workspace
3107-
workspaces(organizationId: UUID, page: Int, perPage: Int, query: String): WorkspacePage!
3063+
workspaces(page: Int, perPage: Int, query: String): WorkspacePage!
31083064
}
31093065

31103066
"""
@@ -4147,7 +4103,6 @@ type Workspace {
41474103
invitations(includeAccepted: Boolean, page: Int, perPage: Int): WorkspaceInvitationPage!
41484104
members(page: Int, perPage: Int): WorkspaceMembershipPage!
41494105
name: String!
4150-
organization: Organization
41514106
permissions: WorkspacePermissions!
41524107
slug: String!
41534108
updatedAt: DateTime

0 commit comments

Comments
 (0)