go-mcu-graphql_api

—|Welcome to my Go MCU api Project 👋|—

This year I started learning GO and GraphQL, and wanted to give a try how they can work together, and this little project came out of it.

You can register a user in a db using GraphQL, query, mutate the db with jwt authentication.

It uses PostgreSQL db in a docker.

This was created purely just for fun, and experimenting with the tech stacks.

Hope you like it and helps you in some way.

Version

PROJECT PHILOSOPHYTECH STACKSCREENSHOTSCONTRIBUTINGABOUT ME

Project-philosophy

Experiment with GO, learn some new things, with docker / GO / GraphQL.

Demo

TODO

Screenshots

Features

Tech Stack

  • GO
  • Gorm
  • gqlgen
  • Postgres
  • graphql
  • docker

API-s used for MCU data

Packages used

  • github.com/99designs/gqlgen for GraphQl generator
  • jwt-go
  • Go chi
  • gqlparser
  • gorm

Prerequisites

  • Install go
  • Install docker / docker-compose
  • Set up .env file

Installation

Install go(lang)

with homebrew:

sudo brew install go

with apt-get):

sudo apt-get install golang

install Golang manually or compile it yourself

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

PORT= -> your localhost port for the qraphql playground defaults to 8080

DB_HOST= -> localhost
DB_PORT= -> 5432
DB_USER= -> anything
DB_PASSWORD= -> anything
DB_NAME=-> anything

Run Locally

Clone the project

  git clone https://github.com/NorbertRuff/go-mcu-graphql_api

Go to the project directory

  cd go-mcu-graphql_api

Install dependencies

go get
go mod tidy

First start Postgres server with docker compose:

 docker-compose up -d

Finally run the server:

go run server.go

Now navigate to https://localhost:8080 you can see graphiql playground and query the graphql server.

Commands

For example:

You can create a user, this command gives back a JWT Token

mutation createuser {
  createUser(
    variables: {
      username: "bob"
      password: "bob"
      email: "bob"
      firstname: "bob"
      lastName: "bob"
    }
  )
}

Login an existing user, this command gives back a JWT Token

mutation {
    login(variables: { username: "bob", password: "bob" })
}

Query all the movies requires: JWT token

query {
    movies
    {
        imdb_id
        movie_id
        title
        overview
        duration
        user {
            user_id
            username
        }
    }

}

You can generate resolvers and types from gql schema configured in gqlgen.yml

go run github.com/99designs/gqlgen generate 

or

go generate 

Compile

One great aspect of Golang is, that you can start go applications via go run server.go, but also compile it to an executable with go build server.go. After that you can start the compiled version which starts much faster.

Build your app and synthesize your stacks.

Generates a .build/ directory with the compiled files.

Lessons Learned

  • Basic clean code
  • Go project structure
  • Go graphgl
  • Go pointers
  • Go structs, types
  • Graphql schema
  • Docker compose
  • Sql
  • Postgres
  • Gorm
  • Docker Compose

Give a ⭐️ if this project helped you!

🚀About-Me

Hi 👋, I’m Norbert

A passionate developer from Hungary

  • 🔭 I’m currently working on Frontend skills 🚀
  • 🎓 I recently completed Codecool Hungary Full-Stack developer bootcamp.
  • 👯 I’m looking to collaborate with other Developers 😉
  • 🥅 2022 Goals: Learn scss, less css, typescript, front-end frameworks.
  • 💬 Ask me about anything, I am happy to help 😉
  • 🧗 I try to go beyond and push the bounds.
  • ⚡ Fun fact: I love old technology 🙌

LinkedIn Gmail Badge Discord Badge

My Github Stats

My Skill Set 👩‍💻

💻


🌐



🎨


prathmesh

Roadmap

TODO

Feedback

If you have any feedback, please visit the issues page

Acknowledgements

TODO

Contributing

Contributions are always welcome!

See contributing.md for ways to get started.

Please adhere to this project’s code of conduct.

Visit original content creator repository https://github.com/NorbertRuff/go-mcu-graphql_api

Comments

Leave a Reply

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