Skip to content
Santekno.com | Tech Tutorials and Trends
EN
📖 0%
21 Aug 2025 · 5 min read ·Article 52 / 125
Go

52 Deploying graphql-go to Render/Vercel/Heroku

IH
Ihsan Arif
Writer at Santekno · Backend Engineer

52 Deploying graphql-go to Render/Vercel/Heroku

Danger
Note: “52” is the sequence number in my tutorial series. If you’d like to learn more about various Go projects, feel free to browse my archive on Medium!

As a backend engineer, I often get asked: “If you’re using Go and the graphql-go framework, is it actually easy to deploy to cloud providers like Render, Vercel, or Heroku?” The short answer is: It’s easy, as long as you understand how it works! In this article, I’ll walk you through deploying a Go-based GraphQL service (graphql-go) to three popular platforms: Render, Vercel, and Heroku. I’ll share code examples, scenario simulations, and even deployment flow diagrams.


Setting Up a GraphQL Service with graphql-go

Before we get into deployment, we need to have a simple GraphQL service in place first. Let’s start with the most fundamental piece.

Project Structure

text
1graphql-demo/
2├── main.go
3├── go.mod
4├── schema.graphql

The schema.graphql File

graphql
1type Query {
2    hello: String!
3}

The main.go File

go
 1package main
 2
 3import (
 4    "context"
 5    "log"
 6    "net/http"
 7    "github.com/graphql-go/graphql"
 8    "github.com/graphql-go/handler"
 9)
10
11func main() {
12    fields := graphql.Fields{
13        "hello": &graphql.Field{
14            Type: graphql.String,
15            Resolve: func(p graphql.ResolveParams) (interface{}, error) {
16                return "Hello world!", nil
17            },
18        },
19    }
20    rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields}
21    schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)}
22    schema, err := graphql.NewSchema(schemaConfig)
23    if err != nil {
24        log.Fatalf("failed to create schema, error: %v", err)
25    }
26
27    h := handler.New(&handler.Config{
28        Schema:     &schema,
29        Pretty:     true,
30        GraphiQL:   true,
31    })
32
33    port := getPort()
34    http.Handle("/graphql", h)
35    log.Printf("Server is running on port %s...", port)
36    log.Fatal(http.ListenAndServe(":"+port, nil))
37}
38
39// Get the port from the environment variable, defaulting to 8080.
40func getPort() string {
41    port := os.Getenv("PORT")
42    if port == "" {
43        port = "8080"
44    }
45    return port
46}
Danger
Note: Make sure you’ve already run go mod init graphql-demo and installed the two main packages:
go get github.com/graphql-go/graphql
go get github.com/graphql-go/handler

1. Deploying to Render

Render is a fairly “developer friendly” cloud platform that’s very popular in the Go community. Render automatically builds from the source code in your repository (GitHub/GitLab) and runs your commands.

How Deploying to Render Works

MERMAID
flowchart TD
    A[Push ke repo Github] --> B[Connect repo ke Render Web Service]
    B --> C[Render build Go]
    C --> D[Service jalan di subdomain Render]

Deployment Walkthrough

  1. Push your code to a GitHub repo.
  2. Sign up/log in to Render .
  3. Select New Web Service → connect to your repo.
  4. Fill in the form:
    • Environment: Go
    • Build Command: leave it empty (Render automatically runs go build)
    • Start Command: ./graphql-demo (this name matches the binary produced by the build)
  5. Render’s default port: the PORT variable (which we’ve already handled in main.go).
  6. Click deploy.

Deployment Configuration Table

FieldValue
RuntimeGo
Build Command(leave empty)
Start Command./graphql-demo
Port envPORT (default:8080)
Service typeWeb Service

Testing:
Visit the URL https://your-service-name.onrender.com/graphql, open GraphiQL, and try the query:

graphql
1query {
2  hello
3}

2. Deploying to Heroku

Heroku is still a favorite too, especially for prototyping. This time, we need to create a Procfile in the project root:

The Procfile

text
1web: ./graphql-demo

Heroku Deployment Steps

  1. Install the Heroku CLI (if you don’t have it yet).
  2. heroku create graphql-go-demo
  3. Set GOFLAGS so the build is static:
    text
    1heroku config:set GOFLAGS="-tags heroku"
  4. The Procfile instructs Heroku to run the binary produced by the build.
  5. Run:
    text
    1git push heroku main
  6. Wait for the build to finish – Heroku will automatically build and run the app.

Make sure the port uses the PORT env variable!
Query the endpoint at:
https://graphql-go-demo.herokuapp.com/graphql

Troubleshooting

Sometimes Heroku refuses to run a Go binary if it isn’t static. If you hit an error, use a custom build command in a Makefile:

makefile
1build:
2    CGO_ENABLED=0 GOOS=linux go build -o graphql-demo main.go

Update the Procfile if necessary.


3. Deploying to Vercel

Vercel was originally known for frontend work (Next.js), but it can now run serverless Go too!

Creating an API Function on Vercel

The folder structure must follow Vercel’s convention:

text
1/api/graphql/main.go

Fill in api/graphql/main.go using an HTTP handler, but make use of the vercel/go-api runtime :

go
 1package main
 2
 3import (
 4    "context"
 5    "github.com/awslabs/aws-lambda-go-api-proxy/httpadapter"
 6    "github.com/graphql-go/graphql"
 7    "github.com/graphql-go/handler"
 8    "github.com/vercel-community/go-api/api"
 9)
10
11func main() {
12    fields := graphql.Fields{
13        "hello": &graphql.Field{
14            Type: graphql.String,
15            Resolve: func(p graphql.ResolveParams) (interface{}, error) {
16                return "Hello from Vercel!", nil
17            },
18        },
19    }
20    rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields}
21    schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)}
22    schema, _ := graphql.NewSchema(schemaConfig)
23
24    h := handler.New(&handler.Config{
25        Schema:     &schema,
26        Pretty:     true,
27        GraphiQL:   true,
28    })
29
30    httpHandler := httpadapter.NewV2(h)
31    api.HandleFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
32        httpHandler.ServeHTTP(w, r)
33    })
34}

The vercel.json File

json
1{
2  "version": 2,
3  "builds": [
4    { "src": "api/graphql/main.go", "use": "@vercel/go" }
5  ]
6}

How to Deploy

  1. npm i -g vercel (install the CLI).
  2. vercel login
  3. vercel (follow the wizard).

The API endpoint will be available at:
https://your-project-name.vercel.app/api/graphql


Platform Comparison

FeatureRenderHerokuVercel (Serverless)
Free tierYesYes*Yes
Build processAutomaticAutomaticAutomatic
Port configurationEasyEasyAutomatic
PersistentYesYesStateless, cold start
ScalabilityEasyEasyAutomated
GraphiQL supportYesYesYes
Danger
*Heroku has had a limited free tier since late 2022.

When Should You Pick Which?

  • Render: Production-ready Go projects where you want full control and easy deployment.
  • Heroku: Quick prototyping with easy database integration.
  • Vercel: Serverless needs—stateless API functions.

Conclusion

Deploying graphql-go to a cloud platform turns out to be very straightforward, as long as we understand the build and execution patterns of each provider. The key is to: handle the PORT environment variable, provide a startup file (Procfile/vercel.json), and take advantage of continuous deploy features.

Go ahead and experiment, then adapt the workflow to your needs—hopefully you won’t hesitate to deploy a Go backend to a modern cloud anymore!


Main References:


See you in the next article in this series, number 53!

Related Articles

💬 Comments