Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GQL Add dynamic partition mutation (#12562)
In Dagit, we want to be able to add a new partition to a dynamic partitions definition through the UI. This PR adds a mutation that allows for adding this new partition.
- Loading branch information
1 parent
c78992f
commit 216c9fc
Showing
11 changed files
with
295 additions
and
2 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
js_modules/dagit/packages/core/src/graphql/possibleTypes.generated.json
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
...on_modules/dagster-graphql/dagster_graphql/implementation/execution/dynamic_partitions.py
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,80 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
from dagster._core.definitions.selector import ( | ||
RepositorySelector, | ||
) | ||
from dagster._core.workspace.permissions import Permissions | ||
|
||
from dagster_graphql.schema.errors import GrapheneDuplicateDynamicPartitionError | ||
|
||
from ..utils import UserFacingGraphQLError, assert_permission_for_location, capture_error | ||
|
||
if TYPE_CHECKING: | ||
from ...schema.inputs import GrapheneRepositorySelector | ||
from ...schema.partition_sets import GrapheneAddDynamicPartitionSuccess | ||
|
||
|
||
def _repository_contains_dynamic_partitions_def( | ||
graphene_info, repository_selector: RepositorySelector, partitions_def_name: str | ||
) -> bool: | ||
from dagster._core.host_representation.external_data import ( | ||
ExternalDynamicPartitionsDefinitionData, | ||
) | ||
|
||
if graphene_info.context.has_repository_location(repository_selector.location_name): | ||
repo_loc = graphene_info.context.get_repository_location(repository_selector.location_name) | ||
if repo_loc.has_repository(repository_selector.repository_name): | ||
repository = repo_loc.get_repository(repository_selector.repository_name) | ||
matching_dynamic_partitions_defs = [ | ||
asset_node.partitions_def_data | ||
for asset_node in repository.external_repository_data.external_asset_graph_data | ||
if asset_node.partitions_def_data | ||
and isinstance( | ||
asset_node.partitions_def_data, ExternalDynamicPartitionsDefinitionData | ||
) | ||
and asset_node.partitions_def_data.name == partitions_def_name | ||
] | ||
return len(matching_dynamic_partitions_defs) > 0 | ||
return False | ||
|
||
|
||
@capture_error | ||
def add_dynamic_partition( | ||
graphene_info, | ||
repository_selector: "GrapheneRepositorySelector", | ||
partitions_def_name: str, | ||
partition_key: str, | ||
) -> "GrapheneAddDynamicPartitionSuccess": | ||
from dagster_graphql.schema.errors import GrapheneUnauthorizedError | ||
|
||
from ...schema.partition_sets import GrapheneAddDynamicPartitionSuccess | ||
|
||
unpacked_repository_selector = RepositorySelector.from_graphql_input(repository_selector) | ||
|
||
assert_permission_for_location( | ||
graphene_info, | ||
Permissions.EDIT_DYNAMIC_PARTITIONS, | ||
unpacked_repository_selector.location_name, | ||
) | ||
|
||
if not _repository_contains_dynamic_partitions_def( | ||
graphene_info, unpacked_repository_selector, partitions_def_name | ||
): | ||
raise UserFacingGraphQLError( | ||
GrapheneUnauthorizedError( | ||
message=( | ||
"The repository does not contain a dynamic partitions definition with the given" | ||
" name." | ||
) | ||
) | ||
) | ||
|
||
if graphene_info.context.instance.has_dynamic_partition(partitions_def_name, partition_key): | ||
raise UserFacingGraphQLError( | ||
GrapheneDuplicateDynamicPartitionError(partitions_def_name, partition_key) | ||
) | ||
|
||
graphene_info.context.instance.add_dynamic_partitions(partitions_def_name, [partition_key]) | ||
return GrapheneAddDynamicPartitionSuccess( | ||
partitionsDefName=partitions_def_name, partitionKey=partition_key | ||
) |
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
Oops, something went wrong.