A GraphQL wrapper of the Chuck Norris Quote API. This is just a demo to show how REST API can be wrapped with GraphQL. It also demonstrates how authentication with JWT can be implemented on top of the REST API.
Install all the dependencies with:
npm installIn order to run the server you have to start the GraphQL server as well as the mock database by running the following.
npm run serverThis will run nodemon on the server
To start the mock database run the following in a separate terminal:
json-server --watch db.jsonAll routes of the Chuck Norris API can be queried through the GraphQL interface. Only the random jokes route is currently checking for an Authorization header (JWT token). All other routes can be protected by the simply wrapping the resolver in a checkAuthAndResolve function and passing the controller as an argument as well as the context of the request:
categories: (_, args, context) => {
return checkAuthAndResolve(context, getCategories)
},