Airbnb Clone - GraphQL Server Example with Prisma
prismais listed as a development dependency and script in this project's
package.json. This means you can invoke the Prisma CLI without having it globally installed on your machine (by prefixing it with
yarn prisma deployor
yarn prisma playground. If you have the Prisma CLI installed globally (which you can do with
npm install -g prisma), you can omit the
1. Download the example & install dependencies
Clone the repository with the following command:
git clone firstname.lastname@example.org:graphcool/graphql-server-example.git
Next, navigate into the downloaded folder and install the NPM dependencies:
cd graphql-server-example yarn install
2. Deploy the Prisma database service
cd prisma docker-compose up -d cd .. yarn prisma deploy
I don't have Docker installed on my machine
To deploy your service to a public cluster (rather than locally with Docker), you need to perform the following steps:
- Remove the
yarn prisma deploy.
- When prompted by the CLI, select a public cluster (e.g.
- Replace the
index.tswith the HTTP endpoint that was printed after the previous command.
Notice that when deploying the Prisma service for the very first time, the CLI will execute the mutations from
database/seed.graphqlto seed some initial data in the database. The CLI is aware of this file because it's listed in
3. Start the GraphQL server
The Prisma database service that's backing your GraphQL server is now available. This means you can now start the server:
dev script starts the server (on
http://localhost:4000) and opens a GraphQL Playground where you get acces to the API of your GraphQL server (defined in the application schema) as well as the underlying Prisma API (defined in the auto-generated Prisma database schema) directly.
Inside the Playground, you can start exploring the available operations by browsing the built-in documentation.
Testing the API
queries/queries.graphql to see several example operations you can send to the API. To get an understanding of the booking flows, check the mutations in
now --dotenv .env.prod
Notice that you need to create the
.env.prod file yourself before invoking the command. It should list the same environment variables as
.env but with different values. In particular, you need to make sure that your Prisma service is deployed to a cluster that accessible over the web.
Here is an example for what
.env.prod might look like:
PRISMA_STAGE="prod" PRISMA_CLUSTER="public-tundrapiper-423/prisma-us1" PRISMA_ENDPOINT="http://us1.prisma.sh/public-tundrapiper-423/prisma-airbnb-example/dev" PRISMA_SECRET="mysecret123" APP_SECRET="appsecret321"
To learn more about deploying GraphQL servers with Zeit Now, check out this tutorial.
I'm getting the error message
[Network error]: FetchError: request to http://localhost:4466/auth-example/dev failed, reason: connect ECONNREFUSED when trying to send a query or mutation
This is because the endpoint for the Prisma service is hardcoded in
index.js. The service is assumed to be running on the default port for a local cluster:
http://localhost:4466. Apparently, your local cluster is using a different port.
You now have two options:
- Figure out the port of your local cluster and adjust it in
index.js. You can look it up in
- Deploy the service to a public cluster. Expand the
I don't have Docker installed on my machine-section in step 2 for instructions.
Either way, you need to adjust the
endpoint that's passed to the
Prisma constructor in
index.js so it reflects the actual cluster domain and service endpoint.