Skip to content

Latest commit

 

History

History
109 lines (94 loc) · 2.62 KB

README.md

File metadata and controls

109 lines (94 loc) · 2.62 KB

GraphQL API

Implemented for needs of recruitment

Requirements

This task is for demonstrating understanding of HTTP, GraphQL, Node.js and general API practices.

  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:
{
  movies {
    title
    year
    rating
    actors {
      name
      birthday
      country
      directors {
        name
        birthday
        country
      }
    }
  }
}
  1. Add support for the following mutation:
mutation createUser($username: String!, $password: String!) {
  createUser(username: $username, password: $password) {
    token
    user {
      id
      name
    }
  }
}
  1. 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
    }
  }
}
  1. 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
      }
    }
  }
}
  1. /graphql must be accessible for external clients.

  2. End.

Instructions

Introduction

To implement task requirements I used:

I implemented unit tests and used TypeScript and TSLint.

Runing the API

  1. Install dependencies and build using npm install.
  2. Run API using npm start.
  3. GraphQL Playground will be available on http://localhost:4000. API will be available for external clients on http://localhost:4000/graphql.
  4. To build API use npm run build.

Unit test

  1. To run unit tests execute npm test

Notes:

  1. I added exclamation mark to types in mutations because username and password are required fields.
  2. GraphQL will be created when API will be started. In case of issues I copied it to "schema-backup" directory and added to repository.