WD40 is good for a lot of things, but a true mechanical lubricant it is not. The petroleum component will work as a lubricant for a short time, but it should not be used as such in any service application, certainly not on a chain. However, it is arguably a great chain cleaner. The petroleum products in it break down grease and grime very well, but you should follow up by removing all residue and applying a high quality chain lube.
I know an aircraft mechanic that got in some serious trouble using DW40 to "lubricate" control serface pivots and cable bearings on small aircraft with WD40, instead of a mil spec lubricant, as specified. The FAA inspectors were not impressed.