Skip to content

Innovic-io/apollo-graphql-pintrest-clone

Repository files navigation

Pintrest API clone on Apollo GraphQL with MongoDB

Built with:

  • TypeScript
  • MongoDB
  • Docker
  • GraphQL

Libraries:

  • Apollo server ( on express )
  • GraphQL ( with tools )
  • JsonWebToken
  • Inversify
  • SonarTS

Principles:

  • Feature based code organization
  • e2e testing
  • unit testing
  • Custom JWT authentication with hashed passwords stored in DB.
  • Based on dependency injection principles.

Development

We used Insomnia tool for testing GraphQL API responses: https://insomnia.rest/

# install local dependencies
npm install


# create docker containers for development
docker-compose -f docker-compose.yml -f docker-compose.local.yml up -d

Run e2e tests and unit tests

# end to end tests
npm run e2e

# unit tests
npm run test

GraphQL example calls

Mutations:

# Create user in DB

mutation {
    createUser(username: "unique", password: "pass123", 
        first_name: "Marc", last_name: "Marcovski")
    
  # Authentication
    loginUser(username: "unique",
      password: "pass123")
} # copy token which you get in Bearer authorization

# create user for later follow 
mutation {
    createUser(username: "unique 1", password: "pass123", 
               first_name: "Boris", last_name: "Yurinov")
}
# Create Board

mutation { 
    createBoard(
    name: "Unique Name", 
    description: "Board description") {
        _id name created_at creator { username first_name }
    }
} # copy _id which you get

# Create Pin

mutation {
    createPin(board: "boardID",
    name: "Unique name",
    note: "Note for this pin") {
        name created_at  board {  created_at description name}
        creator { username first_name }
    }
}

# get all users 
{
	getAllUsers { _id first_name last_name }
} # copy some _id

# Follow user and Board

mutation {
	followBoard(_id: "boardID") {
		_id name followers { first_name last_name }
	}

	followUser(_id: "userID") {
		first_name last_name following { first_name last_name }
	}
} 

Queries:

# Get 

fragment userResult on User { username first_name last_name }

fragment boardResult on Board { 
  name 
  creator { ...userResult } 
  followers {...userResult} }

fragment pinResult on Pin {
	name created_at note
	board { ...boardResult }
	creator { ...userResult }
}

{
	getPin(_id: "pinID") { ...pinResult }
	getBoard(_id: "boardID") { ...boardResult }
	getUser { ...userResult }
	getUserBoards { ...boardResult }
	getUserPins { ...pinResult }
	getPinsFromBoard(boardID: "boardID" ) { ...pinResult }
	getUserFollowings { ...userResult	}
}

Subscription

To reflect subscription:

  1. Send one of requests
	getAllPins {
		name
	}

	getAllUsers {
		username
	}
  1. Go to localhost

Production

docker-compose up -d

Change schema on fly

Constants GRAPHQL_MIDDLEWARE method .replace(middleware) change middleware which will be executed. Async function changeSchema() from helper.functions is beta version of ExpressGraphQL middleware

GRAPHQL_MIDDLEWARE.haldler() will add middleware on desired endpoint.

Commercial break

  • INNOVIC doo
  • Software consulting company for building full stack solutions.
  • Proficient in: NodeJS, TypeScript, Angular, MongoDB...
  • You have project for us? hello@innovic.io

About

🌺🌻🌷🌹 Pintrest API clone on Apollo GraphQL with MongoDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published