π An API to manage contacts using GraphQL and Typescript
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.
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/
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.
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
}
}
{
"data": {
"createContact": {
"id": "ab2d6337-afa6-414d-be2b-ccca51c08a43"
}
}
}
query {
contact(id: "ab2d6337-afa6-414d-be2b-ccca51c08a43") {
name
website
notes
}
}
{
"data": {
"contact": {
"name": "Luis Felipe Santos do Nascimento",
"website": "https://luisfelipesdn12.now.sh",
"notes": "It's me :)"
}
}
}
query {
contacts {
...contactFields
}
}
{
"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 :)"
}
]
}
}
mutation {
updateContact(
id: "ab2d6337-afa6-414d-be2b-ccca51c08a43"
data: {
website: "https://github.com/luisfelipesdn12/"
}
) {
...contactFields
}
}
{
"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 :)"
}
}
}