This is a sample NodeJS API project built using NestJS, Prisma and GraphQL.
Follow the steps outlined below to get this API up and running on your local machine.
- clone the repo and
cd
into the project directory - run
yarn install
to install the dependencies
- rename the file
example.env
to.env
and fill in the user, password, and database_name fields (removing the square brackets) - in a separate terminal window, run
docker-compose up
which will create the image if you don't have it locally already, and will start the postgres database container. This will show the logs from the database because it's currently attached. If you want to run it in detached mode instead, rundocker-compose up -d
- in a separate terminal window, run
docker ps
to ensure that your database container is running
- rename the file
example.data.js
todata.js
- navigate to this url, and copy all the objects into the array in the
data.js
file - run
npx prisma db push
which will create the table(s) in the database based on the models in theprisma/schema.prisma
file - run
npx prisma db seed
which will take the data fromdata.js
and insert them into your postgres database
- run
yarn start
to startup the API server - in a browser window, go to
localhost:3000/graphql/
to make queries
Fetch all pokemon:
{
pokemons {
id
name {
english
}
image
}
}
Fetch specific pokemon:
{
pokemon(id: 30) {
id
type
name {
english
}
}
}
Fetch all teams:
{
teams {
id
name
pokemonIds
}
}
Fetch specific team:
{
team(id: 4) {
id
name
pokemonIds
}
}
Create team:
mutation createTeam {
createTeam(
input: { name: "Best team!", pokemonIds: ["21", "255", "800", "44", "39"] }
) {
id
name
pokemonIds
createdAt
}
}
Update team:
mutation updateTeam {
updateTeam(input: { id: "1", name: "Updated team name" }) {
id
name
pokemonIds
createdAt
}
}
Delete team:
mutation deleteTeam {
deleteTeam(id: "3") {
id
name
}
}