Structure of the JS Code Base
server.js that is located in the root code folder
src/ is the entry point into the application.
All other code components are placed into designated sub-folders, except for
schema.js, which is used by the GraphQL engine. You can also see
schema.graphql file in the
src/ folder. This is generated by manually executing
scripts/updateSchema.js. It is used to share the schema definition with GraphQL clients - we'll talk about this more in the "GraphQL Data API" chapter.
Demo Project JS Code Folders
src/config- initiates the runtime configuration with values coming from the OS Environment and
.envfile, or assigns hardcoded defaults. The folder also contains sample SSH key files to handle the JWT security - an optional feature commended out in the demo. JWT is explained in the "Running NodeJS" chapter
src/data-seed- code and sample source YAML files to pre-load the database with test data
src/db-models- the data layer, hardcoded for the use of MongoDB via the
mongoosepackage; reviewed in details in the "MongoDB Datastore" chapter. Isolating the data layer into a separate set of objects is a common design strategy - helps switching to a different database if needed, by replacing only the data layer components
middlewareis widely used in JS/web development and can be applied to any program layer that handles any kind of transformation flow or process (or anything at all).
http-middlewarecomponent runs the flow from the http request coming in to the point where the "controller"-like logic (business rules) takes over
src/paging-processor- this is the code that enables navigation through datasets via "paging" request, like "extract next n elements after element x" or "last n before x", etc. The code links together GraphQL and MongoDB processes to get the result (so, it is a "middleware")
src/relay...folders - facilitate data handling per GraphQL standards. Discussed in great details in the "GraphQL Data API" chapter
src/utils- miscellaneous code objects, including
A developer familiar with the MVC design would be wondering - where are the Models, Views and Controllers? They are kind of embedded in the GraphQL core. Will talk about it more in the "GraphQL Data API" chapter.
From the folder structure - next, to the Naming Convention