This example shows how to implement a GraphQL server with TypeScript with the following stack:
- Express GraphQL: Express middleware for GraphQL HTTP servers
- GraphQL Nexus: GraphQL schema definition and resolver implementation
- Prisma Client: Databases access (ORM)
- Prisma Migrate: Database migrations
- SQLite: Local, file-based SQL database
- Getting Started
- Using the GraphQL API
- Evolving the app
- Switch to another database (e.g. PostgreSQL, MySQL, SQL Server)
- Next steps
Download this example:
curl -LJO 'https://github.com/sinhaGuild/pg-nexus-ts-gql/archive/refs/heads/main.zip'
Install npm dependencies:
cd api
yarn install
yarn run dev
Alternative: Clone the entire repo
Clone this repository:
git clone git@github.com:sinhaGuild/pg-nexus-ts-gql.git --depth=1
Install npm dependencies:
cd api/
yarn install
Run the following command to create your SQLite database file. This also creates the User
and Post
tables that are defined in prisma/schema.prisma
:
npx prisma migrate dev --name init
When npx prisma migrate dev
is executed against a newly created database, seeding is also triggered. The seed file in prisma/seed.ts
will be executed and your database will be populated with the sample data.
Launch your GraphQL server with this command:
yarn run dev
Navigate to http://localhost:4000 in your browser to explore the API of your GraphQL server in a GraphQL Playground.