Skip to content

Commit

Permalink
generate entites from json
Browse files Browse the repository at this point in the history
  • Loading branch information
msaipraneeth committed Oct 2, 2024
1 parent 83d13ed commit 336cec8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cmem_plugin_graphql/workflow/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
MultilineStringParameterType,
)
from cmem_plugin_base.dataintegration.plugins import WorkflowPlugin
from cmem_plugin_base.dataintegration.ports import (
UnknownSchemaPort,
)
from cmem_plugin_base.dataintegration.utils import write_to_dataset
from cmem_plugin_base.dataintegration.utils.entity_builder import build_entities_from_data
from gql import Client, gql
from gql.transport.aiohttp import AIOHTTPTransport
from graphql import GraphQLError, GraphQLSyntaxError

from cmem_plugin_graphql.workflow.utils import (
get_dict,
get_entities_from_list,
is_jinja_template,
)

Expand Down Expand Up @@ -128,6 +131,8 @@ def __init__( # nosec
if oauth_access_token:
self.headers["Authorization"] = f"Bearer {oauth_access_token}"

self._set_ports()

def set_graphql_variable_values(self, variable_values: str) -> None:
"""Validate and set graphql_variable_values"""
try:
Expand Down Expand Up @@ -213,7 +218,7 @@ def execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> Enti
context=context.user,
)

return get_entities_from_list(payload)
return build_entities_from_data(payload)

def process_entities(self, entities: Entities) -> Iterator[dict[str, Any] | None]:
"""Process entities"""
Expand Down Expand Up @@ -242,3 +247,10 @@ def process_entities(self, entities: Entities) -> Iterator[dict[str, Any] | None
self.log.error(f"Failed entity: {type(ex)}") # noqa: TRY400

yield result

def _set_ports(self) -> None:
"""Define input/output ports based on the configuration"""
if self.graphql_dataset:
self.output_port = None
else:
self.output_port = UnknownSchemaPort()

0 comments on commit 336cec8

Please sign in to comment.