Skip to content

Latest commit

 

History

History
134 lines (90 loc) · 3.32 KB

File metadata and controls

134 lines (90 loc) · 3.32 KB

Server

This is a simple GraphQL server implementation using Apollo.

Setup

  • Install npm dependencies

    npm install
  • Install MongoDB, using homebrew or download and install

    brew install mongodb-community
  • Make MongoDB data directory (in server)

    mkdir -p ./data/db
  • Start mongod instance

    npm run start:mongo
  • Populate mongodb with data from src/mongo/testFixtures/*.json

    npm run seed:mongo
  • Optionally, stop mongod

    npm run stop:mongo

Run the server

npm start

This also starts mongod in the background. Once done you can stop it by running:

npm run stop:mongo

API

GraphQL API

Once the server starts, the GraphQL API is available on http://localhost:4000/graphql

You can test your queries and mutations in GraphQL Playground by visiting the endpoint in your browser or you can use Apollo Sandbox

GraphQL queries

HelloWorld: a simple Hello, World! query. Just to make sure your server is up and running!

query HelloWorld {
    hello
}

PricingPlans: Fetches pricing plans for given countryCode

query PricingPlans($countryCode: String) {
    pricingPlans(countryCode: $countryCode) {
        _id
        billingFrequency
        trialPeriodDays
        isRecommended
        currency
        price
    }
}

REST or other APIs

In case you are not familiar with GraphQL or prefer using another API (e.g., REST), you are free to do so. Feel free to modify the server setup or implement an alternative API style that best suits your approach.

Testing

This repository includes Jest for unit testing. Tests are written in TypeScript and can be conveniently placed alongside the files/functions they test.

Running tests

Use the following commands to run tests:

  • Run all tests:
    npm test
  • Run tests in watch mode (auto-retest on file changes):
    npm run test:watch
  • Run tests with coverage report:
    npm run test:coverage

Example test file

Check out a sample test file for reference:
server/src/utils/calculate.test.ts

Your choice of testing tools

While Jest is pre-configured, you are free to setup and use any testing framework or tool you prefer. It would be great if it supports Typescript, but doesn't have to.

Testing is encouraged, but is not required

Writing tests is encouraged, but not mandatory. You are welcome to include tests where you feel they add value. If you prefer TDD or any other methodology, feel free to apply it!

Linting

This repo contains a basic linting setup using eslint and prettier. You can setup your editor to show linting errors (and/or auto-fix on save). E.g. using the VS Code ESLint extension.

You can also run:

  • npm run eslint to show linting errors
  • npm run eslint-fix to auto-fix linting errors