https://github.com/mabc224/node-apollo-graphql-jwt-api
Node Express based Apollo GraphQL api with custom directive, authentication and authorization with jwt
https://github.com/mabc224/node-apollo-graphql-jwt-api
apollo apollo-server-express directives expressjs graphql jwt jwt-authentication nodejs
Last synced: 2 months ago
JSON representation
Node Express based Apollo GraphQL api with custom directive, authentication and authorization with jwt
- Host: GitHub
- URL: https://github.com/mabc224/node-apollo-graphql-jwt-api
- Owner: mabc224
- Created: 2019-08-24T15:23:51.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-07-18T04:06:34.000Z (almost 6 years ago)
- Last Synced: 2025-12-31T19:29:02.629Z (5 months ago)
- Topics: apollo, apollo-server-express, directives, expressjs, graphql, jwt, jwt-authentication, nodejs
- Language: JavaScript
- Homepage: https://tt0fh.sse.codesandbox.io/graphql
- Size: 12.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## APP: [https://tt0fh.sse.codesandbox.io/graphql](https://tt0fh.sse.codesandbox.io/graphql)
### CodeSandbox: [https://codesandbox.io/s/node-express-apollo-graphql-jwt-api-tt0fh](https://codesandbox.io/s/node-express-apollo-graphql-jwt-api-tt0fh)
Setup:
```$xslt
npm install
npm start
http://localhost:8000/graphql
Running in dev mode
npm run dev
```
This code base is for understanding of HTTP, GraphQL, Node.js and general API practices.
Instructions:
1. Implement a Node.js-based server with raw `http`, Koa or Express.
2. Add a `/graphql` endpoint serving the apollo-server or any other GraphQL implementation.
3. Schema must be able to return proper response for the following public query:
```graphql
{
movies {
title
year
rating
actors {
name
birthday
country
directors {
name
birthday
country
}
}
}
}
```
4. Add support for the following mutation:
```graphql
mutation createUser($username: String, $password: String) {
createUser(username: $username, password: $password) {
token
user {
id
name
}
}
}
Input Fields
{
"username": "",
"password": ""
}
```
5. To expand on the number four, add a mutation-based authentication that accepts:
```graphql
mutation login($username: String, $password: String) {
login(username: $username, password: $password) {
token
user {
id
name
}
}
}
Input Fields
{
"username": "",
"password": ""
}
HTTP Headers
{
"Authorization": "Bearer ...Token..."
}
```
6. Authenticated users may request additional fields for the query used earlier. New `scoutbase_rating` field must return the a random string between 5.0-9.0:
```graphql
{
movies {
scoutbase_rating
title
year
rating
actors {
name
birthday
country
directors {
name
birthday
country
}
}
}
}
HTTP Headers
{
"Authorization": "Bearer ...Token..."
}
```
7. `/graphql` must be accessible for external clients.
8. End.