-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workspace field to GraphQL Dataset (#4318)
* add minimal gql workspace definitions * graphql workspace test * lint imports * lint import
- Loading branch information
1 parent
f073ba4
commit bdfc97f
Showing
9 changed files
with
388 additions
and
202 deletions.
There are no files selected for viewing
398 changes: 215 additions & 183 deletions
398
app/packages/relay/src/queries/__generated__/datasetQuery.graphql.ts
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
FiftyOne Server workspace. | ||
| Copyright 2017-2024, Voxel51, Inc. | ||
| `voxel51.com <https://voxel51.com/>`_ | ||
| | ||
""" | ||
|
||
from datetime import datetime | ||
import typing as t | ||
|
||
import strawberry as gql | ||
|
||
from fiftyone.server.scalars import BSON | ||
|
||
|
||
@gql.type | ||
class Workspace: | ||
id: gql.ID | ||
|
||
color: t.Optional[str] | ||
child: BSON | ||
dataset_id: gql.ID | ||
created_at: t.Optional[datetime] | ||
description: t.Optional[str] | ||
name: t.Optional[str] | ||
last_modified_at: t.Optional[datetime] | ||
last_loaded_at: t.Optional[datetime] | ||
slug: t.Optional[str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
""" | ||
FiftyOne Server workspace tests. | ||
| Copyright 2017-2024, Voxel51, Inc. | ||
| `voxel51.com <https://voxel51.com/>`_ | ||
| | ||
""" | ||
|
||
import unittest | ||
|
||
import strawberry as gql | ||
from strawberry.schema.config import StrawberryConfig | ||
|
||
import fiftyone as fo | ||
|
||
from fiftyone.server.constants import SCALAR_OVERRIDES | ||
from fiftyone.server.query import Dataset | ||
|
||
from decorators import drop_async_dataset | ||
from utils.graphql import execute | ||
|
||
|
||
@gql.type | ||
class DatasetQuery(Dataset): | ||
dataset: Dataset = gql.field(resolver=Dataset.resolver) | ||
|
||
|
||
schema = gql.Schema( | ||
query=DatasetQuery, | ||
scalar_overrides=SCALAR_OVERRIDES, | ||
config=StrawberryConfig(auto_camel_case=False), | ||
) | ||
|
||
|
||
class TestGroupModeSidebarCounts(unittest.IsolatedAsyncioTestCase): | ||
@drop_async_dataset | ||
async def test_workspace_field(self, dataset: fo.Dataset): | ||
histograms_panel = fo.Panel(type="Histograms") | ||
name = "histograms" | ||
workspace = fo.Space(children=[histograms_panel]) | ||
dataset.save_workspace(name, workspace) | ||
|
||
query = """ | ||
query Query($name: String!, $slug: String!) { | ||
dataset(name: $name) { | ||
workspace(slug: $slug) { | ||
child | ||
name | ||
slug | ||
} | ||
} | ||
} | ||
""" | ||
|
||
result = await execute( | ||
schema, | ||
query, | ||
{"name": dataset.name, "slug": name}, | ||
) | ||
|
||
self.assertEqual( | ||
result.data, | ||
{ | ||
"dataset": { | ||
"workspace": { | ||
"child": workspace.to_dict(), | ||
"name": "histograms", | ||
"slug": name, | ||
} | ||
} | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import typing as t | ||
|
||
import strawberry as gql | ||
|
||
from fiftyone.server.context import get_context | ||
|
||
|
||
async def execute(schema: gql.Schema, query: str, variables: t.Dict): | ||
"""Execute a test GraphQL query. | ||
Args: | ||
schema: a :class:`strawberry.Schema` | ||
query: a GraphQL query string | ||
variables: a variables dictionary | ||
Returns: | ||
an :class:`strawberry.types.execution.ExecutionResult` | ||
""" | ||
return await schema.execute( | ||
query, | ||
variable_values=variables, | ||
context_value=get_context(use_global_db_client=False), | ||
) |