Is it okay to publish an article before applying for a patent?

You can't. You have to apply for a patent first and publish an article first, and the pass rate will be reduced.

An invention-creation applying for a patent shall not lose its novelty in any of the following circumstances within six months before the date of filing:

(1) It was exhibited for the first time at an international exhibition sponsored or recognized by the China Municipal Government;

(2) It was first published at a specific academic conference or technical conference;

(3) Others disclose the contents of the application without the consent of the applicant.

Note: International exhibitions recognized by the China Municipal Government refer to international exhibitions registered or recognized by the Bureau of International Exhibitions as stipulated in the Convention on International Exhibitions.

An academic conference or technical conference refers to an academic conference or technical conference organized by the relevant competent department of the State Council or a national academic organization.

The patent administration department of the State Council may, when it deems it necessary, require the applicant to submit supporting documents within a specified time limit.

If the above conditions are met, otherwise, the novelty of the technical scheme will be affected and the patent right will be difficult to pass.