graphql-go-server

Implement a TODO-app as a CLI tool using:

Getting Started

We will setup and deploy the following:

  • GraphQL Server
  • GraphQL Playground
  • MySQL (free remote database on AWS provided by Prisma)

1. Download example & install dependencies

Clone the repository in your go env folder (example: go/src/github.com/ YOUR SETUP MAY BE DIFFERENT):

git clone https://github.com/flavioespinoza/graphql-go-server.git

Ensure dependencies are available and up-to-date:

cd graphql-go-server/cli-app
dep ensure -update

2. Install the Prisma CLI

To run the example, you need the Prisma CLI

npm install -g prisma
brew install prisma
brew tap

3. Set up database & deploy Prisma datamodel

For this example, you'll use a free demo database (AWS Aurora) hosted in Prisma Cloud. To set up your database, run:

prisma deploy

Then, follow these steps in the interactive CLI wizard:

  1. Select Demo server
  2. Authenticate with Prisma Cloud in your browser (if necessary)
  3. Back in your terminal, confirm all suggested values

3.1 Docker Alternative

Run Prisma locally with docker-compose
  1. Ensure you have Docker installed on your machine. If not, you can get it from here:

    docker --version
  2. CD into the cli-app/ directory and create docker-compose.yml file:

    touch docker-compose.yml
  3. Copy the content below add it to the new docker-compose.yml file:

    version: '3'
    services:
      prisma:
        image: prismagraphql/prisma:1.34
        restart: always
        ports:
        - "4466:4466"
        environment:
          PRISMA_CONFIG: |
            port: 4466
            databases:
              default:
                connector: mysql
                host: mysql
                port: 3306
                user: root
                password: prisma
                migrations: true
      mysql:
        image: mysql:5.7
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: prisma
        volumes:
          - mysql:/var/lib/mysql
    volumes:
      mysql:
  4. Run with docker-compose

    docker-compose up -
  5. Open the prisma.yml located in the graphql-go-server/cli-app/prisma/ directory and set endpoint to http://localhost:4466:

    # Specifies the HTTP endpoint of your Prisma API.
    endpoint: http://localhost:4466 
    ...
  6. Deploy with prisma:

    prisma deploy

4. Use the CLI app

go run main.go

create <item: string>

Add Todo item

go run main.go create 'Lissy Salsa Dancing, Thursday'

list

List all Todo items

go run main.go list

delete <item: string>

Remove a Todo item

go run main.go delete 'Groceries'

6. GraphQL Playground

Navigate to: http://localhost:4466/

GraphQL Playground

Next steps