Right. So in reality, you would want to calculate both gradients before updating parameters. It is kinda tricky but you can do, in pseudo code:
fake = G(z)
fake_d = fake.detach()
fake_d.requires_grad = True

pred_fake = D(fake_d)
pred_fake_d = pred_fake.detach()
pred_fake_d.requires_grad = True

loss_G = log(1-pred_fake_d)
grad_pred_fake = autograd.grad(loss_G, pred_fake_d)
grad_fake = autograd.grad(pred_fake, fake_d, grad_pred_fake, retain_graph=True)
fake.backward(grad_fake)

loss_D = log(pred_fake) + D(real)
loss_D.backward()