You can keep the second query from firing using a property called enabled as:
const { data: resourceId } = useGetResourceId();
const { data, isLoading, error } = useGetResourceData(resourceId, {
enabled: !!resourceId // Query won't run until resourceId is truthy
});