Skip to content

Latest commit

 

History

History
90 lines (58 loc) · 2.98 KB

README.md

File metadata and controls

90 lines (58 loc) · 2.98 KB

MY API

This example shows how to implement a GraphQL server with TypeScript with the following stack:

Contents

Getting started

1. Download example and install dependencies

Download this example:

curl https://codeload.github.com/prisma/prisma-examples/tar.gz/latest | tar -xz --strip=2 prisma-examples-latest/typescript/graphql

Install npm dependencies:

cd graphql
npm install
Alternative: Clone the entire repo

Clone this repository:

git clone git@github.com:prisma/prisma-examples.git --depth=1

Install npm dependencies:

cd prisma-examples/typescript/graphql
npm install

2. Create and seed the database

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

Now, seed the database with the sample data in prisma/seed.ts by running the following command:

npx prisma db seed --preview-feature

3. Start the GraphQL server

Launch your GraphQL server with this command:

npm run dev

Navigate to http://localhost:4000 in your browser to explore the API of your GraphQL server in a GraphQL Playground.

Using the GraphQL API

The schema that specifies the API operations of your GraphQL server is defined in ./schema.graphql. Below are a number of operations that you can send to the API using the GraphQL Playground.

Feel free to adjust any operation by adding or removing fields. The GraphQL Playground helps you with its auto-completion and query validation features.

Next steps