We can define the derivative of a function whose domain is a subset of rational numbers?
There's no reason that a derivative couldn't be defined on such a set like $\mathbb Q$. As you note, the limit $$\lim_{h\rightarrow 0}\frac{f(a+h)-f(h)}{h}$$ may still be calculated even if $a+h$ is restricted to only rational values.
I think it's worth noting that the fact that $\mathbb Q$ is totally disconnected might give the wrong impression. The above definition only fails when fed isolated points - that is points with no other points in the domain in an open neighborhood. In the language of topology, we could say points such that $\{x\}$ is open in the domain of the function. Whether or not the domain is connected it somewhat irrelevant. So, you can't use this definition of for a function defined only on $\mathbb Z$ where every point is isolated. But it works fine on any dense subset of $\mathbb R$, like $\mathbb Q$. Another similar thing to think about is that not all function $f:\mathbb Q\rightarrow\mathbb R$ are continuous, despite $\mathbb Q$ being totally disconnected.
We might avoid using such a derivative as one might notice that a lot of theorems (e.g. the fundamental theorem of calculus) really do need conditions like "$f:\mathbb R\rightarrow\mathbb R$ is everywhere differentiable" which can't be replaced by $f:A\rightarrow\mathbb R$ being differentiable everywhere in its domain.