Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Google Cloud

Set Up Prisma Server for GraphQL on Ubuntu 18.04 – Google Cloud

by Cloudbooklet
5 years ago
in Google Cloud, Compute Engine
Set Up Prisma Server For Graphql On Ubuntu 18.04
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

Set Up Prisma Server for GraphQL on Ubuntu 18.04 - Google Cloud. Prisma is a replacement for traditional ORMs and used to build GraphQL servers, REST APIs, microservices and more.

ADVERTISEMENT

In this guide you are going to learn how to set up and install Prisma server on Ubuntu 18.04 using Docker and Docker Compose. We will also run a test GraphQL query in the GraphQL Playground which connects to external database Cloud SQL.

This tutorial is tested on Google Cloud Platform with Compute Engine VM Instance and Cloud SQL. It will work on all Ubuntu systems.

Table of Contents

  1. Prerequisites
  2. Install Prisma with Docker Compose
  3. Setup Firewall
  4. Install Prisma Local Environment
    1. Deploy to Prisma Server
    2. Run a GraphQL query

Prerequisites

  1. Your Compute Engine Instance running.
  2. For setting up Compute Engine, see the Setting up Compute Engine Instance.
  3. Ubuntu server setup on Google Cloud.
  4. Google Cloud SQL Setup, see Setup Cloud SQL and connect with Compute Engine.
  5. How to install Docker on Ubuntu 18.04 LTS.
  6. Install Docker Compose with Docker on Ubuntu 18.04.
  7. Node.js and NPM installed in your local computer.

Install Prisma with Docker Compose

Docker Compose allows you to manage and run multi-container applications. YOu can use it to set up the infrastructure required for Prisma service.

ADVERTISEMENT

SSH to your VM Instance and navigate to your project directory. In our case it will be my-project

You might also like

How To Install Git On Ubuntu 20.04

How to Install Git on Linux

3 months ago
Vector Image

DataStax Enhances Astra DB on Google Cloud with Vector Search Capability

3 months ago

Create a new docker-compose.yml file for Prisma server configuration. This will automatically spin up your Prisma and connect to Cloud SQL and configure it easily.

Make sure you replace the following contents in your docker-compose.yml file.

ADVERTISEMENT
  • managementApiSecret: YOUR_SECRET
  • host: CLOUD_SQL_IP_ADDRESS
  • user: USERNAME
  • password: PASSWORD

Execute the following command to create the docker-compose.yml file.

sudo nano docker-compose.yml

Paste the following contents and hit CTRL + X followed by Y and Enter to save and exit the file.

ADVERTISEMENT
version: "3"
services:
prisma:
image: prismagraphql/prisma:1.23.4
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
managementApiSecret: YOUR_SECRET
databases:
default:
connector: mysql
host: CLOUD_SQL_IP_ADDRESS
port: 3306
user: USERNAME
password: PASSWORD
migrations: true

This configuration pulls the latest version of Prisma and connect to port 4466. It also set the configurations to connect to Cloud SQL.

Now you can start the docker containers in detached mode.

ADVERTISEMENT
sudo docker-compose up -d

Once the containers are created you can view the running containers using the following command.

You will get an output similar to the one below.

ADVERTISEMENT
sudo docker ps
Output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
645865e010bc prismagraphql/prisma:1.23.4 "/bin/sh -c /app/sta…" 3 minutes ago Up 3 minutes 0.0.0.0:4466->4466/tcp my-project_prisma_1

Prisma server is setup and connected to Cloud SQL, you can now deploy your Prisma service from local system.

Setup Firewall

As Prisma server is listening on port 4466, you need to allow connections on this port.

So navigate to VPC Network >> Firewall rules and create a firewall rule.

Provide a name.

In Targets select All instances in the network

In Source IP ranges enter 0.0.0.0/0

In Protocols and ports check tcp and enter 4466

Click Create.

Install Prisma Local Environment

Create a new directory for your Prisma files and navigate into it.

npm install -g prisma

Create a new file structure for a new Prisma database API, which generates the files necessary to build your application.

prisma init hello-world

You will see an interactive prompt to select one of the servers. Choose Use other server and press ENTER

Output
Set up a new Prisma server or deploy to an existing server?

You can set up Prisma for local development (based on docker-compose)
Use existing database Connect to existing database
Create new database Set up a local database using Docker

Or deploy to an existing Prisma server:
Demo server Hosted demo environment incl. database (requires login)
❯ Use other server Manually provide endpoint of a running Prisma server

Then you need to provide the endpoint of your Prisma server. That will be your VM Instance External IP address with port 4466 (http://EXTERNAL_IP_ADDRESS:4466).

Output
Enter the endpoint of your Prisma server http://EXTERNAL_IP_ADDRESS:4466

Next you need to enter your management API secret.

Output
Enter the management API secret YOUR_SECRET

Next choose the default for service name and stage

Select the programming language as Prisma TypeScript Client for the Prisma Client.

Output
Select the programming language for the generated Prisma client (Use arrow keys)
❯ Prisma TypeScript Client
Prisma Flow Client
Prisma JavaScript Client
Prisma Go Client
Don't generate

Once this is completed 3 files has been created and your application is ready to deploy.

Output
Created 3 new files:
prisma.yml Prisma service definition
datamodel.prisma GraphQL SDL-based datamodel (foundation for database)
.env Env file including PRISMA_API_MANAGEMENT_SECRET

Next steps:
1. Open folder: cd hello-world
2. Deploy your Prisma service: prisma deploy
3. Read more about deploying services:
http://bit.ly/prisma-deploy-services

Generating schema… 27ms

Saving Prisma Client (TypeScript) at D:\prisma\hello-world\generated\prisma-client\

Deploy to Prisma Server

Move into directory.

cd hello-world

Deploy your Prisma service from local to the Prisma server.

prisma deploy

You will see an output similar to this.

Output
Creating stage dev for service hello-world √
Deploying service hello-world to stage dev to server default 2.0s

Changes:

User (Type)
+ Created type User
+ Created field id of type GraphQLID!
+ Created field name of type String!
+ Created field updatedAt of type DateTime!
+ Created field createdAt of type DateTime!

Applying changes 2.4s

Your Prisma GraphQL database endpoint is live:

HTTP: http://EXTERNAL_IP_ADDRESS:4466/hello-world/dev
WS: ws://EXTERNAL_IP_ADDRESS:4466/hello-world/dev

Now you can connect to two different endpoints.

  • The management Interface: http://EXTERNAL_IP_ADDRESS:4466/management, where you can manage and deploy Prisma services.
  • The GraphQL API: http://EXTERNAL_IP_ADDRESS:4466/hello-world/dev

Run a GraphQL query

Go to your web browser and visit http://EXTERNAL_IP_ADDRESS:4466/hello-world/dev . You can experiment with the GraphQL playground.

Graphql Payground

Here you can test by sending a mutation to create a user. Run the following mutation on the left side of the GraphQL Playground.

mutation {
createUser(data: { name: "Alice" }) {
id
name
}
}

Once you hit the play button, you will see the results on the right side.

Test Graphql

Now you have a Prisma server and service running on your server, and tested queries in GraphQL’s IDE.

Tags: Compute EngineGoogle Cloud PlatformGraphQLPrisma
ShareTweetSendShare
Cloudbooklet

Cloudbooklet

Comments 1

  1. Avatar Of John John says:
    4 years ago

    How do you select a database scheme

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

How To Setup Ssh Keys On Ubuntu

How to Setup SSH Keys on Ubuntu 20.04

4 months ago
Draggan Ai Editing Tool Install And Use Draggan Photo Editor

DragGAN AI Editing Tool Install and Use DragGAN Photo Editor

4 months ago
Set Up Deep Learning With Nvidia, Cuda, Cudnn On Ubuntu

How to Set Up Deep Learning with Nvidia, CUDA, cuDNN on Ubuntu 22.04

7 months ago
How To Install Or Upgrade Php 8.2 On Ubuntu 22.04

How to Install or Upgrade PHP 8.2 on Ubuntu 22.04

9 months ago

Follow Us

Trending Articles

Interactive Ai

Interactive AI – Next Phase of Artificial Intelligence

September 22, 2023

Google Bard Extensions: How to Link Your Gmail, Docs, Maps, and More to an AI Chatbot

5 Best TikTok Private Account Viewer in 2023

Why Did Meta Shut Down 3 VR Games?

Amazon Prime Big Deal Days 2023: Best Deals

WhatsApp Business Gets New Features to Help your Businesses Grow

Popular Articles

10 Best Email Tracking App For 2023: Which One Is Right For You?

10 Best Email Tracking App for 2023: Which One is Right for You?

September 1, 2023

Create High Quality AI Cover Song with Covers AI

9 Best AI YouTube Video Summarizers Online

10 Best Email Autoresponder Tool for Lead Generation

Charley AI: The Best AI Essay Writing Tool

4 Ways to Reset Snapchat Password

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.