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.jsx
you will see<Route path='invite/:inviteId' component={CreateOrganization} ...
-
This loads
src/containers/CreateOrganization.jsx
-
which while loading calls
inviteData
anduserData
which will callgetInvite
andgetCurrentUser
through graphql api -
The client then makes an xmlhttprequest to
/graphql
with 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.js
where you will seecurrentUser
andinvite
defined there. Those definitions magically (viatype RootQuery
in that file) makegetCurrentUser
andgetInvite
exist. SeerootResolvers =
... in the file for the code that will run on e.g.getInvite
under 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
onSubmit
for the GSForm and callsmutations.createOrganization
with the form values as arguments, again through GraphQL. -
We circle back (through another XHR request go /graphql) into
src/server/api/schema.js
and callcreateOrganization
with the same arguments listed in the jsx file. -
In schema.js
rootMutations
has acreateOrganization
method 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
.