Thanks for your quick response @alexmigf and a big thank you!
I tried a different approach I, registered a new type invoiceURL” at the order.
But my mistakes were, at first i did not added the orderKey for security and secondly i didn’t enable the “Guest Access”, but with your help it worked out.
add_action('graphql_register_types', function () {
register_graphql_field('Order', 'invoiceUrl', [
'type' => 'String',
'description' => __('Invoice URL', 'wp-graphql'),
'resolve' => function ($order) {
$newOrder = new WC_Order($order);
if (!(get_current_user_id() == $newOrder->user_id)) {
throw new UserError(sprintf(__('Access restricted! invoice URL '. get_current_user_id() .' 1' .$newOrder->user_id.' 1', 'your-plugin')));
}
$pdf_url = wp_nonce_url(admin_url('admin-ajax.php?action=generate_wpo_wcpdf&document_type=invoice&order_ids='.$order -> get_id().'&order_key='.$order->get_order_key()), 'generate_wpo_wcpdf');
$newURL = str_replace("amp;", "", $pdf_url);
return $newURL;
}
]);
});