This is a simple GraphQL server implementation using Apollo.
-
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
mongodinstancenpm run start:mongo
-
Populate mongodb with data from
src/mongo/testFixtures/*.jsonnpm run seed:mongo
-
Optionally, stop
mongodnpm run stop:mongo
npm startThis also starts mongod in the background. Once done you can stop it by running:
npm run stop:mongoOnce 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
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
}
}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.
This repository includes Jest for unit testing. Tests are written in TypeScript and can be conveniently placed alongside the files/functions they test.
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
Check out a sample test file for reference:
server/src/utils/calculate.test.ts
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.
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!
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 eslintto show linting errorsnpm run eslint-fixto auto-fix linting errors