def post(self): """ Execute GraphQL queries and mutations Use this endpoint to send http request to the GraphQL API. """ payload = request.json # Execute request on GraphQL API status, data = utils.execute_graphql_request(payload['query']) # Execute batch of indicators if status == 200 and 'executeBatch' in payload['query']: if 'id' in data['data']['executeBatch']['batch']: batch_id = str(data['data']['executeBatch']['batch']['id']) batch = Batch() batch.execute(batch_id) else: message = "Batch Id attribute is mandatory in the payload to be able to trigger the batch execution. Example: {'query': 'mutation{executeBatch(input:{indicatorGroupId:1}){batch{id}}}'" abort(400, message) # Test connectivity to a data source if status == 200 and 'testDataSource' in payload['query']: if 'id' in data['data']['testDataSource']['dataSource']: data_source_id = str( data['data']['testDataSource']['dataSource']['id']) data_source = DataSource() data = data_source.test(data_source_id) else: message = "Data Source Id attribute is mandatory in the payload to be able to test the connectivity. Example: {'query': 'mutation{testDataSource(input:{dataSourceId:1}){dataSource{id}}}'" abort(400, message) if status == 200: return jsonify(data) else: abort(500, data)
# filename='data_quality.log', stream=sys.stdout, level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') if __name__ == '__main__': parser = argparse.ArgumentParser( description='Entry point to execute data quality scripts.') parser.add_argument('method', type=str, help='Method to be executed.') parser.add_argument( 'id', type=int, help='Id of the object on which to execute the method.') arguments = parser.parse_args() method = arguments.method if method == 'execute_batch': batch_id = arguments.id batch = Batch() batch.execute(batch_id) elif method == 'test_data_source': data_source_id = arguments.id data_source = DataSource() data_source.test(data_source_id) else: error_message = 'Invalid method {method}'.format(method=method) log.error(error_message) raise Exception(error_message)
parser.add_argument('id', type=int, help='Id of the object on which to execute the method.') arguments = parser.parse_args() authorization = arguments.authorization method = arguments.method if method == 'execute_batch': batch_id = arguments.id # Customize logger to send logs to GraphQL API when executing a batch root_log = logging.getLogger() root_log.addHandler(CustomLogHandler(authorization, batch_id=batch_id)) batch = Batch() batch.execute(authorization, batch_id) elif method == 'test_data_source': data_source_id = arguments.id # Customize logger to send logs to GraphQL API when testing a data source root_log = logging.getLogger() root_log.addHandler(CustomLogHandler(authorization, data_source_id=data_source_id)) data_source = DataSource() data_source.test(authorization, data_source_id) else: error_message = f'Invalid method {method}' log.error(error_message) raise Exception(error_message)