"""Get product data from the message and hydrate it with graphql.""" from content_utils.connectors.graphql import LambdaGraphQLConnector from src import config def extract_product_message_body(product_id, correlation_id): """Return the product object from the debezium message.""" product_data = {'release_id': product_id} product_response = get_product_metadata( product_data.get('release_id'), correlation_id ) product_data.update(product_response) return product_data def get_product_metadata(product_id, correlation_id): """Get the vendor id for the product.""" gql_conn = LambdaGraphQLConnector( config.GRAPHQL_GATEWAY_URL, config.APPLICATION_NAME, config.app_logger, correlation_id=correlation_id, raise_on_error=True ) response = gql_conn.get_base_product({'product_id': product_id}) return { 'label_id': int(response['label_id']), 'label_owner': response.get('label_owner'), 'company_brand': response['company_brand'] or {}, 'distribution_format_id': response['distribution_format_id'], 'assigned_to': response['assigned_to_id'], 'assigned_reviewer': response['assigned_reviewer_id'] }