$\require{AMScd}$ Let $(X,\mathcal O_X)$ be a scheme and $\mathcal A$ a quasi-coherent $\mathcal O_X$-algebra, i.e. a sheaf of ring $\mathcal A$ together with a morphism $\mathcal O_X \to \mathcal A$ making it a quasi-coherent $\mathcal O_X$-module.
Let consider the induced scheme $Spec(\mathcal A)$ the relative spectrum defined locally via $$\Gamma(U, \mathcal O_{Spec(\mathcal A)}):= \mathcal A(U)$$
gluing provides indeed a scheme.
Now let consider a morphism $g: Y \to X$ of schemes. My question is why the construction above respects pullbacks; therefore why
$$Spec(g^*\mathcal A) \cong Spec(\mathcal A) \times_X Y$$
My ideas: I heard that $Spec(\mathcal A)$ represents the functor
$$\begin{eqnarray} \label{constructions-equation-spec} F : \mathit{Sch}^{opp} & \longrightarrow & \textit{Sets} \\ T & \longmapsto & F(T) = \{ \text{pairs }(f, \varphi ) \text{ with } f:T \to X, \varphi: f^*\mathcal{A} \to \mathcal{O}_ T \text{ surjective }\} \nonumber \end{eqnarray}$$
so using Yoneda lemma it suffice to show it on level of pairs as above. But how?
By the way: can it also be shown directly on the level of stalks using the definition of pullback functor of sheaves via $$f^{*}{\mathcal {G}}:=f^{-1}{\mathcal {G}}\otimes _{f^{-1}{\mathcal {O}}_{Y}}{\mathcal {O}}_{X}$$?
Is the induced map $Spec(\mathcal A) \to X$ set theoretically surjective?