TITLE: A continuous function and a closed graph
QUESTION [8 upvotes]: Suppose I would like to show that for 2 metric spaces $A,B$, a function $f:A\to B$ and the graph of $f$, $G=\{(a,f(a))\in A\times B|a\in A\}$ that 
$f$ is continuous IFF $G$ is closed (with an additional condition for the $(\Leftarrow)$ direction -- $B$ is compact)
My thoughts are
$(\Rightarrow) a_k\to a \implies f(a_k)\to f(a)$, therefore $(a_k,f(a_k))\to (a,b)\implies (a,b)\in A\times B$.
My doubts are that do I need to say something about the product metric? As far as I know there isn't a unique definition for it. Also this "proof" seems to be too simple -- I think it might be lacking in something.
$(\Leftarrow) $ Suppose $a_k\to a$,  Then since $G$ is compact, given a sequence $(a_k, f(a_k))$, we can find a subsequence $(a_{k_n}, f(a_{k_n}))$ that converges (I am not sure what this law is, I hope I haven't confused the context and that it is really applicable here.) Since the limit is in $G$, therefore $f(a_{k_n})\to f(a)$ for $a_{k_n}\to a$. Therefore $f$ is continuous.
Again, I think there might be holes in my argument, or perhaps even wrong assumptions. 
Please teach me to fix it. Thanks!

REPLY [5 votes]: I remember doing a similar problem where working by contradiction was easier.
Suppose $a_i$ converges to $a$ but $f(a_i)$ does not converge to $f(a)$. Then there exists an $\epsilon>0$ such that for all $N\in \mathbb{N}$, there exists an $i_N>N$ such that $f(a_{i_N})\notin B(f(a),\epsilon)$.
If $B$ is compact, then there is a subsequence $b_i$ of the $a_{i_N}$ such that $f(b_i)$ converges. Then the sequence $(b_i,f(b_i))$ must converge (since each of its coordinates converge) and since the graph is closed it converges to a point $(b,f(b))$. But then it follows that $b=a$, and so $f(b_i)$ converges to $f(b)=f(a)$, however this is an absurdity because every element of any subsequence of $f(a_{i_N})$ is more than $\epsilon$ from $f(a)$. 
Hence, $f$ preserves convergent sequences, and is continuous.