This documentation guides you through setting up and running a GraphQL API using Fastify as the framework, Prisma as the ORM, and PostgreSQL as the database. The provided repository already contains the necessary codebase.
-
Fastify is a fast and low overhead web framework for Node.js
-
PostgreSQL is a powerful, open source object-relational database system
Before you start, ensure you have the following installed:
- Node.js and npm
- Yarn
- PostgreSQL
-
Clone the Repository:
git clone [email protected]:Mubeyd/graphQl-Api-Postgres.git cd graphQl-Api-Postgres
-
Install Dependencies:
yarn install
-
Configure the Database:
- Create a PostgreSQL database.
- Rename the
.env.example
file to.env
and fill in your database connection details.
-
Migrate Database:
Run Prisma migrations to create the database tables:
npx prisma migrate dev
-
Start the Server:
yarn dev
-
Access GraphQL Playground:
Open your browser and navigate to
http://localhost:4000/graphql
.
-
GraphQL Playground:
In the GraphQL Playground, you can write and test your queries and mutations against the defined schema.
Example Query:
query Users { users { id username email } }
Example Mutation:
mutation CreateTag($input: TagCreateInput!) { createTag(input: $input) { id isActive imagePath nameTxJson { en ar tr } descriptionTxJson { en ar tr } } }
-
Explore API:
Explore the available queries, mutations, and their documentation in the right sidebar of the GraphQL Playground.
The GraphQL API is exposed through Caddy, acting as a reverse proxy. No additional setup is required for Caddy, as it's already configured in the Docker Compose
file, and the necessary configuration files are already provided in the Caddyfile
directory.
You've successfully set up and run a GraphQL API using Fastify, Prisma, and PostgreSQL. The provided repository contains a functional codebase that you can extend and customize to build more complex GraphQL APIs according to your project requirements. Happy coding! 🚀