Skip to content

Commit 9153394

Browse files
authored
feat: add get webapps by slug method
https://bluesquare.atlassian.net/browse/PATHWAYS-1048
2 parents 25ee040 + aa05822 commit 9153394

6 files changed

Lines changed: 146 additions & 1 deletion

File tree

openhexa/graphql/graphql_client/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@
226226
)
227227
from .get_file_by_path import GetFileByPath, GetFileByPathGetFileByPath
228228
from .get_users import GetUsers, GetUsersUsers, GetUsersUsersAvatar
229+
from .get_webapp_by_slug import (
230+
GetWebappBySlug,
231+
GetWebappBySlugWebapp,
232+
GetWebappBySlugWebappCreatedBy,
233+
GetWebappBySlugWebappPermissions,
234+
GetWebappBySlugWebappWorkspace,
235+
)
229236
from .input_types import (
230237
AddOrganizationMemberInput,
231238
AddPipelineOutputInput,
@@ -610,6 +617,11 @@
610617
"GetUsers",
611618
"GetUsersUsers",
612619
"GetUsersUsersAvatar",
620+
"GetWebappBySlug",
621+
"GetWebappBySlugWebapp",
622+
"GetWebappBySlugWebappCreatedBy",
623+
"GetWebappBySlugWebappPermissions",
624+
"GetWebappBySlugWebappWorkspace",
613625
"GraphQLClientError",
614626
"GraphQLClientGraphQLError",
615627
"GraphQLClientGraphQLMultiError",

openhexa/graphql/graphql_client/client.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from .get_connection import GetConnection, GetConnectionConnectionBySlug
4545
from .get_file_by_path import GetFileByPath, GetFileByPathGetFileByPath
4646
from .get_users import GetUsers, GetUsersUsers
47+
from .get_webapp_by_slug import GetWebappBySlug, GetWebappBySlugWebapp
4748
from .input_types import (
4849
AddToFavoritesInput,
4950
ArchiveWorkspaceInput,
@@ -1093,3 +1094,43 @@ def get_file_by_path(
10931094
)
10941095
data = self.get_data(response)
10951096
return GetFileByPath.model_validate(data).get_file_by_path
1097+
1098+
def get_webapp_by_slug(
1099+
self, workspace_slug: str, webapp_slug: str, **kwargs: Any
1100+
) -> Optional[GetWebappBySlugWebapp]:
1101+
query = gql(
1102+
"""
1103+
query getWebappBySlug($workspaceSlug: String!, $webappSlug: String!) {
1104+
webapp(workspaceSlug: $workspaceSlug, slug: $webappSlug) {
1105+
id
1106+
name
1107+
description
1108+
url
1109+
icon
1110+
isFavorite
1111+
createdBy {
1112+
id
1113+
displayName
1114+
email
1115+
}
1116+
workspace {
1117+
slug
1118+
name
1119+
}
1120+
permissions {
1121+
update
1122+
delete
1123+
}
1124+
}
1125+
}
1126+
"""
1127+
)
1128+
variables: Dict[str, object] = {
1129+
"workspaceSlug": workspace_slug,
1130+
"webappSlug": webapp_slug,
1131+
}
1132+
response = self.execute(
1133+
query=query, operation_name="getWebappBySlug", variables=variables, **kwargs
1134+
)
1135+
data = self.get_data(response)
1136+
return GetWebappBySlug.model_validate(data).webapp
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Generated by ariadne-codegen
2+
# Source: openhexa/graphql/queries.graphql
3+
4+
from typing import Any, Optional
5+
6+
from pydantic import Field
7+
8+
from .base_model import BaseModel
9+
10+
11+
class GetWebappBySlug(BaseModel):
12+
webapp: Optional["GetWebappBySlugWebapp"]
13+
14+
15+
class GetWebappBySlugWebapp(BaseModel):
16+
id: Any
17+
name: str
18+
description: Optional[str]
19+
url: str
20+
icon: Optional[str]
21+
is_favorite: bool = Field(alias="isFavorite")
22+
created_by: "GetWebappBySlugWebappCreatedBy" = Field(alias="createdBy")
23+
workspace: "GetWebappBySlugWebappWorkspace"
24+
permissions: "GetWebappBySlugWebappPermissions"
25+
26+
27+
class GetWebappBySlugWebappCreatedBy(BaseModel):
28+
id: Any
29+
display_name: str = Field(alias="displayName")
30+
email: str
31+
32+
33+
class GetWebappBySlugWebappWorkspace(BaseModel):
34+
slug: str
35+
name: str
36+
37+
38+
class GetWebappBySlugWebappPermissions(BaseModel):
39+
update: bool
40+
delete: bool
41+
42+
43+
GetWebappBySlug.model_rebuild()
44+
GetWebappBySlugWebapp.model_rebuild()

openhexa/graphql/queries.graphql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,3 +487,27 @@ query getFileByPath($path: String!, $workspaceSlug: String!) {
487487
type
488488
}
489489
}
490+
491+
query getWebappBySlug($workspaceSlug: String!, $webappSlug: String!) {
492+
webapp(workspaceSlug: $workspaceSlug, slug: $webappSlug) {
493+
id
494+
name
495+
description
496+
url
497+
icon
498+
isFavorite
499+
createdBy {
500+
id
501+
displayName
502+
email
503+
}
504+
workspace {
505+
slug
506+
name
507+
}
508+
permissions {
509+
update
510+
delete
511+
}
512+
}
513+
}

openhexa/graphql/schema.generated.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3381,7 +3381,7 @@ type Query {
33813381

33823382
"""Search users."""
33833383
users(organizationId: UUID, query: String!, workspaceSlug: String): [User!]!
3384-
webapp(id: UUID!): Webapp
3384+
webapp(workspaceSlug: String!, slug: String!): Webapp
33853385
webapps(favorite: Boolean, page: Int, perPage: Int, workspaceSlug: String): WebappsPage!
33863386
workspace(slug: String!): Workspace
33873387
workspaces(organizationId: UUID, page: Int, perPage: Int, query: String): WorkspacePage!

openhexa/sdk/workspaces/current_workspace.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,3 +661,27 @@ def get_file(self, path: str) -> File:
661661
size=result.size,
662662
type=result.type,
663663
)
664+
665+
def get_webapp(self, webapp_slug: str):
666+
"""Get a webapp by its slug.
667+
668+
Parameters
669+
----------
670+
webapp_slug : str
671+
The slug identifier of the webapp
672+
673+
Returns
674+
-------
675+
The webapp object with name, url, description and other properties
676+
677+
Raises
678+
------
679+
ValueError
680+
If the webapp does not exist
681+
"""
682+
webapp = OpenHexaClient().get_webapp_by_slug(workspace_slug=self.slug, webapp_slug=webapp_slug)
683+
684+
if not webapp:
685+
raise ValueError(f"Webapp {webapp_slug} does not exist in workspace {self.slug}.")
686+
687+
return webapp

0 commit comments

Comments
 (0)