Discontinuous functions with closed graphs

I tried looking up a question regarding graphs of continuous functions on this site, but all the ones I found consider functions from $\mathbb{R}$ into $\mathbb{R}$. I have been pondering the following question: given a general topological spaces $X, Y$, and a function $f: X\to Y$, when does $Graph(f)$ closed in $X\times Y$ imply that $f$ is continuous. By the closed graph theorem, this is true whenever $X$ and $Y$ are both Banach spaces.

Also, it is fairly easy to prove that whenever $Y$ is a Hausdorff space and $f$ is continuous, then $Graph(f)$ is closed, but I do not think that the converse is true, so I am trying to find an example where $X$ is some topological space, $Y$ a Hausdorff space, $f: X\to Y$ a function with a closed graph in $X\times Y$, but who fails to be continuous. As of yet I have not been able to find such a counterexample, partially because I have no clue where to look for such a counterexample. I would really appreciate getting some directions to go in.


$f\colon\mathbb{R}\to\mathbb{R}$ defined by $$ f(x)=\frac1x\quad\text{if}\quad x\ne0,\quad f(0)=0. $$


I'd like to answer the comment about why the graph is closed (particularly as it also took me a while to see it).

To see that the graph of $f\colon\mathbb{R}\to\mathbb{R}$ defined by $$ f(x)=\frac1x\quad\text{if}\quad x\ne0,\quad f(0)=0. $$ is closed consider the equivalent definition of a closed graph in a metric space. $G(f)$ is closed if whenever $(x_n) \to x$ and $(f(x_n)) \to y$ then $y = f(x)$. (This follows since in a metric space closure is equivalent to sequential closure and convergence in the product space is equivalent to convergence of the components)

Now for $(x_n) \to 0$ then $(f(x_n))$ is not convergent so $(x_n) \to x$ and $(f(x_n)) \to y$ is not satisfied, while for every other sequence $(x_n) \to x \ne 0$ then $(f(x_n)) \to f(x)$.

So it is true that whenever $(x_n) \to x$ and $(f(x_n)) \to y$ then $y = f(x)$ and therefore $G(f) $ is closed.