Skip to content

luisfelipesdn12/contacts-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

contacts-graphql

πŸ“• An API to manage contacts using GraphQL and Typescript

πŸ“– About

That's my very first project with both TypeScript and GraphQL. It's a simple API where is possible to manage contacts by reading, adding, modifying and deleting them, with GraphQL operations.

πŸš€ Running

You can see the working of this project with a deployed version here. But to run it locally, follow the steps:

# Clone this repository and go to the project root
git clone https://github.com/luisfelipesdn12/contacts-graphql.git
cd contacts-graphql

# Install the dependences
npm install
# or: yarn

# Build and start the project
npm run build
# or: yarn build
npm run start
# or: yarn start

It should result in a log in the terminal saying which port you should access. For default, it may be http://localhost:6060/

πŸ’» Technologies

Used TypeScript & NodeJS with the following dependencies:

  • apollo-server - To handle the GraphQL requests.
  • lowdb - Small local JSON database to store the contacts.
  • type-graphql - Used to generate GraphQL schema and resolvers.
  • uuid - Generates IDs for contacts.

πŸ‘€ Example

Creating a contact (createContact)

mutation {
  createContact(
    data: {
      name: "Luis Felipe Santos do Nascimento"
      phone: "+55 11 90000-0000"
      email: "luisfelipesdn12@gmail.com"
      website: "https://luisfelipesdn12.now.sh"
      notes: "It's me :)"
    }
  ) {
    id
  }
}

Return

{
  "data": {
    "createContact": {
      "id": "ab2d6337-afa6-414d-be2b-ccca51c08a43"
    }
  }
}

Getting a contact (contact)

query {
	contact(id: "ab2d6337-afa6-414d-be2b-ccca51c08a43") {
    name
    website
    notes
  }
}

Return

{
  "data": {
    "contact": {
      "name": "Luis Felipe Santos do Nascimento",
      "website": "https://luisfelipesdn12.now.sh",
      "notes": "It's me :)"
    }
  }
}

Getting all contacts (contacts)

query {
  contacts {
    ...contactFields
  }
}

Return

{
  "data": {
    "contacts": [
      {
        "id": "ab2d6337-afa6-414d-be2b-ccca51c08a43",
        "name": "Luis Felipe Santos do Nascimento",
        "phone": "+55 11 90000-0000",
        "email": "luisfelipesdn12@gmail.com",
        "website": "https://luisfelipesdn12.now.sh",
        "notes": "It's me :)"
      }
    ]
  }
}

Updating a contact (updateContact)

mutation {
  updateContact(
    id: "ab2d6337-afa6-414d-be2b-ccca51c08a43"
    data: {
      website: "https://github.com/luisfelipesdn12/"
    }
  ) {
    ...contactFields
  }
}

Return

{
  "data": {
    "updateContact": {
      "id": "ab2d6337-afa6-414d-be2b-ccca51c08a43",
      "name": "Luis Felipe Santos do Nascimento",
      "phone": "+55 11 90000-0000",
      "email": "luisfelipesdn12@gmail.com",
      "website": "https://github.com/luisfelipesdn12/",
      "notes": "It's me :)"
    }
  }
}

Deleting a contact (deleteContact)

mutation {
  deleteContact(id: "ab2d6337-afa6-414d-be2b-ccca51c08a43")
}

Return

{
  "data": {
    "deleteContact": true
  }
}