Mongo + Apollo server + Docker + Express graphql server boilerplate.
- MongoDB - if not using docker
- docker & docker-compose - if using docker
npm i
- create your .env file. Example is in .env.example.
docker-compose up --build
- To use the docker image
or
npm start
- running with locally installed mongodb and autoreload with nodemon.
- don't forget to change DB_HOST=localhost inside .env file when using local mongoDb installation.
npm start
- starts server for local development. Only used if not using docker.
To create a new user use the mutation:
register(name: "Thanos", email: "thanos@universe.com", password: "infinityStars")
To login use the mutation:
login(email: "thanos@universe.com", password: "infinityStars")
To create a post use the mutation:
addPost(text: "New post")
Used for returning cursor based pagginated posts.
Used for returning cursor based pagginated users.
Used to get the current logged in user
query { me { id email firstName lastName } }
Used to get a single post with a postId
query { post(id:"postId") { id text } }
Used to get all posts
query { posts { edges { post { id text createdAt updatedAt } cursor } pageInfo { startCursor endCursor hasNextPage hasPreviousPage } } }
Used to get all users
query { users { edges { user { id email firstName lastName createdAt updatedAt } cursor } pageInfo { startCursor endCursor hasNextPage hasPreviousPage } } }
login( email: String! password: String! ): User
register( name: String! email: String! password: String! ): User
updateProfile( firstName: String lastName: String email: String ): User
changePassword( oldPassword: String! newPassword: String! ): User
addPost( text: String ): Post
These are mutations only available for an admin user ( a user with a role set to "admin")
deletePost( postIds: [ID!]! ): [Post]!
changeUserRole( userId: ID! role: String! ): User
-
don't forget to add any new env variables to the .env file
-
- don't forget to change DB_HOST=localhost inside .env file when using local mongoDb installation.
-
If you've installed new npm plugins, do:
docker-compose stop node
docker-compose build node
docker-compose up -d --no-recreate node
or
You could just
npm install
any new packages inside the node container itself.docker-compose exec node bash
npm intall <packageName>
inside bash.