def send_graph(graph: Graph, ckcore_base_uri: str, ckcore_graph: str, dump_json: bool=False):
    merge_uri = f'{ckcore_base_uri}/graph/{ckcore_graph}/merge'
    log.debug(f'Sending graph via {merge_uri}')
    graph_outfile = None
    if dump_json:
        graph_outfile = open('graph.dump.json', 'w')
    try:
        graph_export_iterator = GraphExportIterator(graph, graph_outfile)
        headers = {'Content-Type': 'application/x-ndjson', 'Cloudkeeper-Ckworker-Nodes': str(graph.number_of_nodes()), 'Cloudkeeper-Ckworker-Edges': str(graph.number_of_edges())}
        if getattr(ArgumentParser.args, 'psk', None):
            encode_jwt_to_headers(headers, {}, ArgumentParser.args.psk)
        r = requests.post(merge_uri, data=graph_export_iterator, headers=headers)
        if (r.status_code != 200):
            log.error(r.content)
            raise RuntimeError(f'Failed to send graph: {r.content}')
        log.debug(f'ckcore reply: {r.content.decode()}')
        log.debug(f'Sent {graph_export_iterator.nodes_sent} nodes and {graph_export_iterator.edges_sent} edges to ckcore')
    finally:
        if (graph_outfile is not None):
            graph_outfile.close()
def send_graph(graph: Graph, ckcore_base_uri: str, ckcore_graph: str, dump_json: bool=False):
    merge_uri = f'{ckcore_base_uri}/graph/{ckcore_graph}/merge'
    log.debug(f'Sending graph via {merge_uri}')
    graph_outfile = None
    if dump_json:
        graph_outfile = open('graph.dump.json', 'w')
    try:
        graph_export_iterator = GraphExportIterator(graph, graph_outfile)
        headers = {'Content-Type': 'application/x-ndjson', 'Cloudkeeper-Ckworker-Nodes': str(graph.number_of_nodes()), 'Cloudkeeper-Ckworker-Edges': str(graph.number_of_edges())}
        if getattr(ArgumentParser.args, 'psk', None):
            encode_jwt_to_headers(headers, {}, ArgumentParser.args.psk)
        r = requests.post(merge_uri, data=graph_export_iterator, headers=headers)
        if (r.status_code != 200):
            log.error(r.content)
            raise RuntimeError(f'Failed to send graph: {r.content}')
        log.debug(f'ckcore reply: {r.content.decode()}')
        log.debug(f'Sent {graph_export_iterator.nodes_sent} nodes and {graph_export_iterator.edges_sent} edges to ckcore')
    finally:
        if (graph_outfile is not None):
            graph_outfile.close()