Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": ["airbnb-base", "prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error"
},
"env": {
"es6": true,
"node": true
},
"parser": "babel-eslint"
}
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 120,
"tabWidth": 4,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
}
62 changes: 16 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,28 @@
# MadeByCodera GraphQL Test
# GraphQL Test Task

## Description
### App configuration

You are tasked with writing the GraphQL api for a new Todo List mobile app.
- add `.env` file with environment variables (see `example.env`);

### Todo GraphQL Type
The structure of the Todo GraphQL Type according to the frontend developer should look like the following:
### DB configuration

Field | Data Type | Description
------------ | ------------- | -------------
id | UUID | Unique identifier for the todo.
description | String | Describes what the todo is.
createdAt | Date | Tells us when the todo was created. Defaults to current datetime.
completed | Boolean | Indicates if the todo is complete. Defaults to false.
priority | Int | 1 is the highest priority. Defaults to 1.
PostgreSQL v11.4 is used as data source

### Todo GraphQL Query and Mutations
And the frontend developer is counting on you to implement the following 5 methods under the GraphQL api endpoint:
1. **List Todos** - Query - Retrieved todos can be sorted by the `priority`, `createdAt`, or `description` fields in ascending or descending order. By default the todos are unsorted. In addition, the todos can be filtered by the `completed` field.
2. **Create todo** - Mutation - `description` is required. `priority` is optional and if not provided should default to 1. The rest of the fields: `id`, `createdAt`, and `completed` should have defaults supplied for them as noted in the Todo GraphQL Type mentioned above.
3. **Update todo** - Mutation - Should update a todo based on the `id` provided in the request. `description` and/or `priority` fields can be updated. `priority` must be 1 or greater if sent in request.
4. **Mark todo complete** - Mutation - Should update a todo's `complete` field to `true` based on the `id` provided in the request.
4. **Delete todo** - Mutation - Should delete a todo based on the `id` provided in the request.
- create database with a name that you set in `.env`
- run `npm run db:migrate` to make all required migrations
- run `npm run db:seed` to insert mock data in the DB (optional)

### Documentation
**Note:** Sql dump is located under `./graphql-test-task.dump.sql`.

The front end developer would also like a little bit of documentation to help him use the api. The easiest way to provide documentation is to add comments to each query, mutation, and type that is defined in the GraphQL schema. The following multi-line comments example highlights how you should be declaring comments in the query, mutation, or type definitions:
### Start app

```
"""
<my comments go here>
"""
```
To start app just run `npm start`.

This will make it very easy for the frontend developer to see them when inspecting the running GraphQL server using [GraphQL Playground](https://www.apollographql.com/docs/apollo-server/features/graphql-playground/)
P.S Do not forget to install npm modules (`npm i`).

As demonstrated in the following screenshot
**Note:** GraphQL Playground can be found on the following address `<host>/graphql`

[![graphql-playground-example.png](https://i.postimg.cc/rw6HMzmt/graphql-playground-example.png)](https://postimg.cc/VdRgFfXY)
### Test app

### Testing

The front end developer would also like to see examples of using this GraphQL api to help him make his own requests, as well as show to him that the api will work as he expects. You may do this however you see fit. The simplest way possible would be to write variations of query and mutation requests in GraphQL Playground and then click `COPY CURL`, pasting the curl command into a shell script that you could provide at the root of the repo called `test.sh`.

[![graphql-test-copy-curl-example.png](https://i.postimg.cc/8c0vxzyb/graphql-test-copy-curl-example.png)](https://postimg.cc/BP2tK4f8)

## Instructions
1. Fork this repository. Do all of your work on your personal fork. Then create a new pull request on your personal fork
2. You must implement this graphql backend using [Apollo Server](https://www.apollographql.com/docs/apollo-server/)
3. You can use whatever data structure you are most comfortable with for storing the data such as in-memory, MySQL, Postgres, SQLite, MongoDB, etc... . Using Postgres is preferred and considered a plus, since that is what we use currently.
4. This repo should be an npm project such that we can install the dependencies that you define for the server in order to run it using Node.

Here is an example of creating a pull request from a fork of a repository:
[![pull-request-example.png](https://i.postimg.cc/QCgrr53S/pull-request-example.png)](https://postimg.cc/RJ0Y7Wqn)

## NOTE
If you are not storing the data in-memory, please commit a sql dump file of the database schema to the repo. Please add a note of where this file is located in this `README.md` if the sql dump is not located at the root of the repo. Your submission will be **DISCARDED** if you **DO NOT** commit a sql dump file for your implementation, if it uses a database.
- start the app by running `npm start`
- run `sh test.sh` to test query and mutations
6 changes: 6 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DB_USERNAME=
DB_PASSWORD=
DB_NAME=
DB_HOST=
DB_PORT=
APP_PORT=
230 changes: 230 additions & 0 deletions graphql-test-task.dump.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
--
-- PostgreSQL database dump
--

-- Dumped from database version 11.4
-- Dumped by pg_dump version 11.4

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: knex_migrations; Type: TABLE; Schema: public; Owner: andrew
--

CREATE TABLE public.knex_migrations (
id integer NOT NULL,
name character varying(255),
batch integer,
migration_time timestamp with time zone
);


ALTER TABLE public.knex_migrations OWNER TO andrew;

--
-- Name: knex_migrations_id_seq; Type: SEQUENCE; Schema: public; Owner: andrew
--

CREATE SEQUENCE public.knex_migrations_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


ALTER TABLE public.knex_migrations_id_seq OWNER TO andrew;

--
-- Name: knex_migrations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: andrew
--

ALTER SEQUENCE public.knex_migrations_id_seq OWNED BY public.knex_migrations.id;


--
-- Name: knex_migrations_lock; Type: TABLE; Schema: public; Owner: andrew
--

CREATE TABLE public.knex_migrations_lock (
index integer NOT NULL,
is_locked integer
);


ALTER TABLE public.knex_migrations_lock OWNER TO andrew;

--
-- Name: knex_migrations_lock_index_seq; Type: SEQUENCE; Schema: public; Owner: andrew
--

CREATE SEQUENCE public.knex_migrations_lock_index_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


ALTER TABLE public.knex_migrations_lock_index_seq OWNER TO andrew;

--
-- Name: knex_migrations_lock_index_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: andrew
--

ALTER SEQUENCE public.knex_migrations_lock_index_seq OWNED BY public.knex_migrations_lock.index;


--
-- Name: todo_list; Type: TABLE; Schema: public; Owner: andrew
--

CREATE TABLE public.todo_list (
id integer NOT NULL,
description character varying(255) NOT NULL,
"createdAt" timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
completed boolean DEFAULT false,
priority integer DEFAULT 1
);


ALTER TABLE public.todo_list OWNER TO andrew;

--
-- Name: todo_list_id_seq; Type: SEQUENCE; Schema: public; Owner: andrew
--

CREATE SEQUENCE public.todo_list_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


ALTER TABLE public.todo_list_id_seq OWNER TO andrew;

--
-- Name: todo_list_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: andrew
--

ALTER SEQUENCE public.todo_list_id_seq OWNED BY public.todo_list.id;


--
-- Name: knex_migrations id; Type: DEFAULT; Schema: public; Owner: andrew
--

ALTER TABLE ONLY public.knex_migrations ALTER COLUMN id SET DEFAULT nextval('public.knex_migrations_id_seq'::regclass);


--
-- Name: knex_migrations_lock index; Type: DEFAULT; Schema: public; Owner: andrew
--

ALTER TABLE ONLY public.knex_migrations_lock ALTER COLUMN index SET DEFAULT nextval('public.knex_migrations_lock_index_seq'::regclass);


--
-- Name: todo_list id; Type: DEFAULT; Schema: public; Owner: andrew
--

ALTER TABLE ONLY public.todo_list ALTER COLUMN id SET DEFAULT nextval('public.todo_list_id_seq'::regclass);


--
-- Data for Name: knex_migrations; Type: TABLE DATA; Schema: public; Owner: andrew
--

COPY public.knex_migrations (id, name, batch, migration_time) FROM stdin;
1 20190711191934_todo_list.js 1 2019-07-12 14:21:54.354+03
\.


--
-- Data for Name: knex_migrations_lock; Type: TABLE DATA; Schema: public; Owner: andrew
--

COPY public.knex_migrations_lock (index, is_locked) FROM stdin;
1 0
\.


--
-- Data for Name: todo_list; Type: TABLE DATA; Schema: public; Owner: andrew
--

COPY public.todo_list (id, description, "createdAt", completed, priority) FROM stdin;
1 Complete task 2019-07-12 14:22:00.234+03 f 1
2 Do homework 2019-07-12 14:22:00.234+03 t 2
3 Do shopping 2019-07-12 14:22:00.234+03 f 3
4 Read the book 2019-07-12 14:22:00.234+03 f 4
5 Take a rest 2019-07-12 14:22:00.234+03 t 5
\.


--
-- Name: knex_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: andrew
--

SELECT pg_catalog.setval('public.knex_migrations_id_seq', 1, true);


--
-- Name: knex_migrations_lock_index_seq; Type: SEQUENCE SET; Schema: public; Owner: andrew
--

SELECT pg_catalog.setval('public.knex_migrations_lock_index_seq', 1, true);


--
-- Name: todo_list_id_seq; Type: SEQUENCE SET; Schema: public; Owner: andrew
--

SELECT pg_catalog.setval('public.todo_list_id_seq', 5, true);


--
-- Name: knex_migrations_lock knex_migrations_lock_pkey; Type: CONSTRAINT; Schema: public; Owner: andrew
--

ALTER TABLE ONLY public.knex_migrations_lock
ADD CONSTRAINT knex_migrations_lock_pkey PRIMARY KEY (index);


--
-- Name: knex_migrations knex_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: andrew
--

ALTER TABLE ONLY public.knex_migrations
ADD CONSTRAINT knex_migrations_pkey PRIMARY KEY (id);


--
-- Name: todo_list todo_list_pkey; Type: CONSTRAINT; Schema: public; Owner: andrew
--

ALTER TABLE ONLY public.todo_list
ADD CONSTRAINT todo_list_pkey PRIMARY KEY (id);


--
-- PostgreSQL database dump complete
--

4 changes: 4 additions & 0 deletions knexfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('dotenv').config();
const config = require('./src/config');

module.exports = config.db;
Loading