Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vit0rr/users-graphiql
Crud with GraphQL + Express + Json Server
https://github.com/vit0rr/users-graphiql
express graphql json-server nodejs
Last synced: 25 days ago
JSON representation
Crud with GraphQL + Express + Json Server
- Host: GitHub
- URL: https://github.com/vit0rr/users-graphiql
- Owner: vit0rr
- License: mit
- Created: 2022-05-20T17:48:31.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-06-08T16:45:36.000Z (over 2 years ago)
- Last Synced: 2024-10-03T08:47:45.909Z (about 1 month ago)
- Topics: express, graphql, json-server, nodejs
- Language: JavaScript
- Homepage:
- Size: 229 KB
- Stars: 9
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# How to run the project
```bash
### Install dependecies
$ yarn install### Run GraphQL server
$ yarn dev### Run Json Server
$ yarn run json:server### The server will start at port http://localhost:4000/graphql
### The Json Server will start at port http://localhost:3000/users/
```# How the project work?
In my `server.js` I have my express code that can start my server and listen on localhost:4000/graphql a GraphQL server that listen my schema and a rule that set my property graphiql to `true`.
`schema.js` has the GraphQL schema, with my types, Queryes and mutations.
# How to run the CRUD?
With the both server started, I made two principles fetches: `user` and `company`.
The user fetch:
```GraphQL# Will return informations about user with id "41"
{
user(id: "41") {
id
firstName
age
company {
name
}
}
}
```The company fetch:
```GraphQL
# Will return informations about the company by id and who users work in this company{
company(id: "2"){
id
name
description
users{
firstName
}
}
}```
Add users:
```GraphQLmutation{
addUser(firstName: "Elon" age: 32){
firstName
age
}
}```
Delete users:
```GraphQLmutation{
deleteUser(id: "4pQ-ym-"){
id
}
}```
Edit users:
```GraphQL
mutation {
editUser(id: "uX1tabO", firstName: "Markinhos", age: 100, companyId: "2") {
id
firstName
age
company{
id
name
description
}
}
}```