If $f:X\to Y$ is a function, $X, Y$ metric spaces, we define the graph of $f$ as the set $$G(f) = \{(x,f(x)), x\in X)\}$$ If $X$ is compact, then show that $f$ is continuous if, and only if, $G(f)$ is closed in $X\times Y$.
I'm struggling with the reverse. I tried to suppose that $f$ is not continuous on some point $x$, so we have a sequence $(x_n)$ such that $(x_n)\to x$ but $f(x_n)$ does not converge to $f(x)$, but I don't know how it can lead to the fact that $G(f)$ is not closed.