/GraphQl-booksearch

Book search engine using the MERN stack

Primary LanguageJavaScriptMIT LicenseMIT

MERN - Book Search Engine (RESTful API to GraphQL API Conversion)


License: MIT

Table of Contents


Description


MongoDB Express.js React NodeJS TypeScript GraphQL Apollo-GraphQL JWT Heroku Webpack

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.
image

image

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

Installation


  • 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

Usage


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.

Back-end

  • 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 and Mutation 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 the User type.)

Front-End

  • queries.js: GET_ME, executes the me query set up using Apollo Server.

  • mutations.js:

    • LOGIN_USER executes loginUser mutation set up using Apollo Server.

    • ADD_USER executes addUser mutation.

    • SAVE_BOOK executes saveBook mutation.

    • REMOVE_BOOK executes removeBook mutation.

  • App.js: Apollo Provider setup to make every request work with the Apollo Server.

  • SearchBooks.js: Apollo useMutation() Hook - Executes SAVE_BOOK mutation in the handleSaveBook() function.

  • SavedBooks.js: useQuery() Hook: Executes GET_ME query on load and saved to userData.

    • useMutation() Hook: Executes REMOVE_BOOK mutation in the handleDeleteBook() 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.

    Contributing


    Fork and critique as you see fit!

    Questions


    visit my github Reach out w/ Additional Questions. ianclark.fullstack@gmail.com

    License

    2021 - MIT MIT Info