I tried to reproduce the same in my environment.
Tried with the following query:
vmCore=tostring(properties.hardwareProfile.vmSizeProperties.NumberOfCores)
But not able to get number of cores .
As i do not have them enabled in my portal to display in Json of my Virtual machine template too.

As i also Tried with properties.hardwareProfile.vmSizeProperties
Graph query:
Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| project name, properties.vmId, properties.storageProfile.osDisk.osType,properties.hardwareProfile.vmSize,properties.hardwareProfile.vmSizeProperties
| order by ['name'] asc
Everything like hardware profile is resulting in output except vm size properties are empty which includes number of cores property for vmsize properties where it has to have number of cores.

Try Initially check the properties and then call the number of cores for each VM.
Below command gives VM size particularly.
Command:
$Myvm= Get-AzureRmVM -ResourceGroupName myrg -Name myacctvm

Command:
$MyVmZizeProperties = Get-AzureRmVMSize -ResourceGroupName myrg -VMName myacctVM

$NumberOfCores = $MyVmZizeProperties.NumberOfCores

$MyVmZizeProperties = Get-AzureRmVMSize -ResourceGroupName myrg -VMName myacctVM | Export-Csv -Path C:\vmproperties.csv -NoTypeInformation
Reference: https://learn.microsoft.com/en-us/azure/virtual-machines/resource-graph-samples?tabs=azure-cli