-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5874 from opsmill/pog-external-graphql-context-IF…
…C-1303 Provide option to set GraphQL context information as input to mutations
- Loading branch information
Showing
12 changed files
with
215 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from infrahub.core.constants import InfrahubKind | ||
from infrahub.core.manager import NodeManager | ||
from infrahub.exceptions import NodeNotFoundError, ValidationError | ||
|
||
if TYPE_CHECKING: | ||
from .initialization import GraphqlContext | ||
from .types.context import ContextInput | ||
|
||
|
||
async def apply_external_context(graphql_context: GraphqlContext, context_input: ContextInput | None) -> None: | ||
"""Applies context provided by an external mutation to the GraphQL context""" | ||
if not context_input or not context_input.account: | ||
return | ||
|
||
try: | ||
account = await NodeManager.get_one_by_id_or_default_filter( | ||
db=graphql_context.db, id=str(context_input.account.id), kind=InfrahubKind.GENERICACCOUNT | ||
) | ||
except NodeNotFoundError as exc: | ||
raise ValidationError(input_value="Unable to set context for account that doesn't exist") from exc | ||
|
||
graphql_context.active_account_session.account_id = account.id |
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
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.