I am doing a problem in Measure, Integration & Real Analysis by Sheldon Axler on page 105.
Suppose $(X, \mathcal{S})$ is a measurable space and $f: X \to \mathbb{R}$ is a function. Let $\operatorname{graph}(f) \subset X \times \mathbb{R}$ denote the graph of $f$:
$$\text{graph}(f) = \{(x, f(x)) : x \in X\}$$
Let $\mathcal{B}$ denote the $\sigma$-algebra of Borel subsets of $\mathbb{R}$. Prove that $\operatorname{graph}(f) \in \mathcal{S} \otimes \mathcal{B}$ if and only if $f$ is an $\mathcal{S}$-measurable function.
I've already solved the if statement. But I can't find a way to solve the only if statement. I saw other similar posts, but I didn't find the only if statement.
For the if one, consider $$ E_k = \bigcup_{j=1}^{2^k k - 1} f^{-1}\left(\left[\frac{j}{2^k}, \frac{j+1}{2^k}\right]\right) \times \left[\frac{j}{2^k}, \frac{j+1}{2^k}\right], \quad F_k = f^{-1}\left([2^k k, \infty]\right) \times [k 2^k, \infty), \quad G_k = E_k \cup F_k. $$ and we take the limit of $G_k$.
Now how about the only if statement? The difficult part is so show that $f^{-1}(B)\in \mathcal{S}$ for any Borel set. I'm struggling with this.
Update: My attempt: using $\text{graph}(f)\in \mathcal{S}\otimes\mathcal{B}$, construct an $\mathcal{S}\otimes\mathcal{B}$-measurable function. Then take its section, for example $g_y$, that could possibly be $f$, and we now that the this section is $\mathcal{S}$-measurable.