https://github.com/jedrzejginter/mock-server
https://github.com/jedrzejginter/mock-server
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jedrzejginter/mock-server
- Owner: jedrzejginter
- Created: 2019-08-31T07:39:17.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-02T06:49:16.000Z (almost 6 years ago)
- Last Synced: 2025-01-21T07:44:15.180Z (5 months ago)
- Language: JavaScript
- Size: 125 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## API Documentation
```bash
yarn api:rest
# Start REST API server on port 4000.yarn api:graphql
# Start GraphQL API server on port 4000.yarn db:reset
# Reset the database.
# Requires restarting used API server.
```**Important note:** Don't run both servers in the same time, because it can cause problems with database syncing.
### REST API
We used Postman app to generate a documentation for REST API. You can see it here: .
---
### GraphQL API
Just run the GraphQL API server and open in your browser. You can find there a GraphQL playground with all available endpoints.
#### Custom error handling
Our GraphQL API has a custom error reporting mechanism (for mutations only) inspired by this talk: . That means that you can get a HTTP 200 code even when mutation failed because of some error, like invalid task id.\
This is how you should work with the mutation response:```graphql
{
mutation {
result: addTagForTask(taskId: 4, tagName: "Tag for task") {
__typename
... on Task {
id
title
tagsId
}
... on OperationError {
code
message
}
}
}
}
```##### Result with error
Example of failed mutation response:
```json
{
"data": {
"result": {
"__typename": "OperationError",
"code": "TOO_MANY_TAGS",
"message": "A single task cannot have more than 4 tags"
}
}
}
```##### Successful result
```json
{
"data": {
"result": {
"__typename": "Task",
"id": 4,
"title": "Write reusable base styles",
"tagsId": [3, 6]
}
}
}
```