yarn start
which is a commonly used convention..babelrc
file containing Babel configuration. Add "start"
script to the package.json
file:package.json
file, but it shouldn't be a problem.yarn start
and navigate to http://localhost:8080/
in the browser's window, you must be able to see the following:express-graphql
middleware.arch
, platform
, and uptime
values grouped under the top-level environment
field.Environment
), and one top-level query field environment
. But since, we're planning to add more types and query fields later on, it would be a good idea to group them under src/types
and src/queires
folders. Plus, you would add src/schema.js
file exporting the "schema" GraphQL object type.ProductType
and ProductCategoryType
declarations can be exported from the **src/types/product.js
**file.Environment
GraphQL type is going to list arch
, platform
, and uptime
fields, alongside their types and resolve()
methods:resolve()
function that would return the actual value for that field. Note that these resolve methods can be async (returning a Promise
).environment
field in our example, we're going to introduce yet another convention — placing them in multiple files under the src/queries
folder. In many cases, those top-level fields would contain large resolve()
functions and most likely you won't like having all of them within the same file. So, the environment
field is going to be exported from src/queires/environment.js
:{}
. If it would resolve to null
or undefined
the query traversal would stop right there, and the GraphQL query (from the example above) would resolve to:src/queries/index.js
and src/types/index.js
re-exporting everything from the sibling files:environment
field declaration we just created is going to be used in the root GraphQL object type:express-graphql
middleware inside src/index.js
:express-graphql
middleware provides out of the box:resolve()
methods we would often need access to the (request) context data such the currently logged-in user, data loaders (more on that later), etc.Context
class and pass it to the express-graphql
middleware alongside the schema:resolve()
method:--insepect
argument to nodemon
.start
script inside of package.json
file as follows:.vscode/launch.json
file instructing VS Code how it should launch the debugger: