This traces an example in the code of how different parts are linked together.
The example comes from the 'first' step, which is consuming an invite code, to login.
-
Loaded from
src/server/index.js(app.use(appRenderer)) =>src/server/middleware/app-renderer.jsx(const routes = makeRoutes(authCheck)) =>src/routes.jsxyou will see<Route path='invite/:inviteId' component={CreateOrganization} ... -
This loads
src/containers/CreateOrganization.jsx -
which while loading calls
inviteDataanduserDatawhich will callgetInviteandgetCurrentUserthrough graphql api -
The client then makes an xmlhttprequest to
/graphqlwith the following payload:
{"debugName":"___composed","query":"query ___composed($___getInvite___requestIndex_0___inviteId: String!) {\n ___getInvite___requestIndex_0___fieldIndex_0: invite(id: $___getInvite___requestIndex_0___inviteId) {\n id\n isValid\n }\n ___getCurrentUser___requestIndex_1___fieldIndex_0: currentUser {\n id\n }\n}\n","variables":{"___getInvite___requestIndex_0___inviteId":"abc-123"}}
-
GraphQL 'schema' is defined in
src/server/api/schema.jswhere you will seecurrentUserandinvitedefined there. Those definitions magically (viatype RootQueryin that file) makegetCurrentUserandgetInviteexist. SeerootResolvers =... in the file for the code that will run on e.g.getInviteunder theinvite:key. -
After authenticating the user with authRequired(user), it "loads" the invite. The first argument of
load(id)is presumed to map to the id field, because TKTK??? probably it's defined throughsrc/server/api/invite.js -
Assuming that an invite is found with id=abc-123 and the user is authenticated, the graphql returns this info to the client.
-
Back in
CreateOrganization.jsx, with the data now loaded, React renders the container, which runsrenderForm()and displays the form to create an organization to the user. -
When the user fills out the organization name field and clicks submit, it then runs
onSubmitfor the GSForm and callsmutations.createOrganizationwith the form values as arguments, again through GraphQL. -
We circle back (through another XHR request go /graphql) into
src/server/api/schema.jsand callcreateOrganizationwith the same arguments listed in the jsx file. -
In schema.js
rootMutationshas acreateOrganizationmethod which is called and it runs (after revalidating the invite id and user)Organization.save(...)-- Organization, in this case is a model (see the import at the top) and is defined insrc/server/models/organization.js.