Skip to content

vit0rr/users-graphiql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to run the project

### 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:

# Will return informations about user with id "41"

{
  user(id: "41") {
    id
    firstName
    age
    company {
      name
    }
  }
}

The company fetch:

# 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:

mutation{
  addUser(firstName: "Elon" age: 32){
    firstName
    age
  }
}

Delete users:

mutation{
  deleteUser(id: "4pQ-ym-"){
    id
  }
}

Edit users:

mutation {
  editUser(id: "uX1tabO", firstName: "Markinhos", age: 100, companyId: "2") {
    id
    firstName
    age
    company{
      id
      name
      description
    }
  }
}


About

Crud with GraphQL + Express + Json Server

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published