Created with CodeSandbox, the article that properly explains this is here
This was created to demonstrate authentication in GraphQL.
- create a user
- authenticate the user
- generate and validate the token
Used
- apollo-server v2
- jsonwebtoken
- bcrypt
- pick(from lodash)
- mongoose
Althought this example uses mongoose and MongoDb, you can easily set up any other database.
Mutations
mutation {
register(email:"olivier@gmail.com", password:"compl8353pass"){
email
password
}
}
mutation {
login(email:"olivier@gmail.com", password:"compl8353pass")
}
Queries
{
users {
email
password
}
loggedInUser {
email
}
}
To-do
- Use a different database (relational)
- Migrate to typescript
- Add more examples to show how relationships work in GraphQL