MERN - Stack application and book search engine. Allows users to search and browse books using Google Books API, as well as save and manage books on their individual profile.
Previously written with a RESTful API The application now runs using Apollo Server and Apollo Provider in order handle requests
- Fetch replaced by GraphQL queries.
- Put, Post and Delete replaced by GraphQL Mutations.
- User auth is attached as middleware, and accessible by each request through context.
Written w/ MERN, MongoDB, NoSQL, REST, GraphQl, Apollo Server, JWToken, React, Node, Express, Heroku, MongoDB Atlas, Apollo Provider
- Clone the repo to your machine. Navigate to the parent directory in your terminal and
npm i
all dependencies. - Launch both the backend & frontend servers concurrently simply by running
npm run develop
This repository can be used as reference on how to successfully refactor an existing application using from RESTful API to GraphQL API.
- In order to do so, I would recommend comparing both versions side-by-side. Specifically from the previous RESTful Architecture Commit
The bulk of the work for converting.
-
server.js
: Implement the Apollo Server and apply it to the Express server as middleware. -
auth.js
: Update the auth middleware function to work with the GraphQL API. -
Schemas
directory:-
resolvers.js
: Query and mutation functionality to work with the Mongoose models. -
typeDefs.js
:Query
andMutation
types* `me`: Returns a `User` type. * `login`: Accepts email and password; Returns an `Auth` type. * `addUser`: Accepts username, email, and password; Returns an `Auth` type. * `saveBook`: Accepts a book author's array, description, title, bookId, image, and link; Returns a `User` type. * `removeBook`: Accepts `bookId`; Returns a `User` type.
-
Auth
type:-
token
-
user
(References theUser
type.)
-
-
-
-
queries.js: GET_ME
, executes theme
query set up using Apollo Server. -
mutations.js
:-
LOGIN_USER
executesloginUser
mutation set up using Apollo Server. -
ADD_USER
executesaddUser
mutation. -
SAVE_BOOK
executessaveBook
mutation. -
REMOVE_BOOK
executesremoveBook
mutation.
-
-
App.js
: Apollo Provider setup to make every request work with the Apollo Server. -
SearchBooks.js
: ApollouseMutation()
Hook - ExecutesSAVE_BOOK
mutation in thehandleSaveBook()
function. -
SavedBooks.js: useQuery()
Hook: ExecutesGET_ME
query on load and saved touserData
.useMutation()
Hook: ExecutesREMOVE_BOOK
mutation in thehandleDeleteBook()
function.
-
SignupForm.js
:ADD_USER
mutation functionality. -
LoginForm.js
:LOGIN_USER
mutation functionality.- You can also use this repo as a solid starting point for MERN-stack applications using Google Books API.
Fork and critique as you see fit!
visit my github Reach out w/ Additional Questions. ianclark.fullstack@gmail.com
2021 - MIT MIT Info