This task is for demonstrating understanding of HTTP, GraphQL, Node.js and general API practices.
- Implement a Node.js-based server with raw
http
, Koa or Express. - Add a
/graphql
endpoint serving the apollo-server or any other GraphQL implementation. - Schema must be able to return proper response for the following public query:
{
movies {
title
year
rating
actors {
name
birthday
country
directors {
name
birthday
country
}
}
}
}
- Add support for the following mutation:
mutation createUser($username: String!, $password: String!) {
createUser(username: $username, password: $password) {
token
user {
id
name
}
}
}
- To expand on the number four, add a mutation-based authentication that accepts:
mutation login($username: String!, $password: String!) {
login(username: $username, password: $password) {
token
user {
id
name
}
}
}
- Authenticated users may request additional fields for the query used earlier. New
secret_rating
field must return the a random string between 5.0-9.0:
{
movies {
secret_rating
title
year
rating
actors {
name
birthday
country
directors {
name
birthday
country
}
}
}
}
-
/graphql
must be accessible for external clients. -
End.
To implement task requirements I used:
I implemented unit tests and used TypeScript and TSLint.
- Install dependencies and build using
npm install
. - Run API using
npm start
. - GraphQL Playground will be available on http://localhost:4000. API will be available for external clients on http://localhost:4000/graphql.
- To build API use
npm run build
.
- To run unit tests execute
npm test
- I added exclamation mark to types in mutations because username and password are required fields.
- GraphQL will be created when API will be started. In case of issues I copied it to "schema-backup" directory and added to repository.