Skip to content

Fake and reliable API data provider implemented in NodeJS, GraphQL, Prisma, MongoDB and Typescript

Notifications You must be signed in to change notification settings

ahmedalatawi/nodejs-graphql-fake-api

Repository files navigation

NodeJS GraphQL Fake API Data Provider

This is a free online GraphQL API for providing fake and reliable data for testing and prototyping. It's built with NodeJS, GraphQL, TypeScript, MongoDB and Prisma (see demo documentation here).

The API currently returns the top 45 most popular and none-editable actores and actresses. See demo below:

Feel free to add, edit, or delete your own celebrities as you wish.

Run app locally

1. Clone this repo & set up MongoDB

You'll need to set up a MongoDB that supports replica set operations. For example, you can use MongoDB Atlas, see more details here.

Create a .env file in the project's root directory, and add the database URL as described in .env.example file.

2. Install dependencies & run app

Run yarn to install Node dependencies, and yarn prisma generate to generate Prisma Client, then:

yarn dev

Open http://localhost:4000/graphql to view it in the browser.

The is the GraphQL playground page used for testing locally, where you can also find info about the Schema, Mutations, Queries, etc.

Retrieve all celebrities

query {
  celebrities {
    id
    name
    bio
    dateOfBirth
    birthPlace
    photoUrl
    editable
  }
}
See more API operations

Retrieve a single celebrity by ID

You can retrieve a single celebrity by passing the id:

query {
  celebrity(id: "__CELEBRITY_ID__") {
    id
    ...
  }
}

Create a new celebrity

This mutation creates a new celebrity by passing the celebrity object:

mutation {
  createCelebrity(celebrity: {name: "__NAME__", bio: "__BIO__", dateOfBirth: "__DATE_OF_BIRTH__", birthPlace: "__BIRTH_PLACE__", photoUrl: "__PHOTO_URL__", editable: "__EDITABLE__"}) {
    id
    ...
  }
}

Update an existing celebrity

This mutation updates an existing celebrity by passing the id along with the properties to update:

mutation {
  updateCelebrity(celebrity: {id: "__ID__", name: "__NAME__", bio: "__BIO__", dateOfBirth: "__DATE_OF_BIRTH__", birthPlace: "__BIRTH_PLACE__", photoUrl: "__PHOTO_URL__"}) {
    id
    ...
  }
}

Delete an existing celebrity

This mutation deletes an existing celebrity by passing the id:

mutation {
  deleteCelebrity(id: "__ID__") {
    id
    ...
  }
}

Delete all existing celebrities

This mutation deletes all existing celebrities:

mutation {
  deleteAllCelebrities {
    count
  }
}

Run tests locally

yarn test

This runs all unit tests locally.

Author 📚

Ahmed Alatawi

About

Fake and reliable API data provider implemented in NodeJS, GraphQL, Prisma, MongoDB and Typescript

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published