Giter Site home page Giter Site logo

bogvsdev / gpg Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mklfarha/gpg

0.0 0.0 0.0 1.3 MB

GPG is a tool to generate a GraphQL API, Auth Server (JWT) and Web Management Tool (React) based on a configuration file that defines entities with their corresponding fields and relationships.

Go 100.00%

gpg's Introduction

GPG

Go Project Generator

GPG is a tool to generate a GraphQL API, Auth Server (JWT) and Web Management Tool (React) based on a configuration file that defines entities with their corresponding fields and relationships written in Go.

This code is experimental and is not meant for production usage, use it at your own risk

What you get from the generator

GPG What you get

You are generating a layered monolith, it includes an auth server, a GraphQL API (playground included), and a web CMS to manage your data.

The generator will take care of creating the code and the tables in MySQL and it will make the corresponding changes as your design evolves by leveraging Skeema and GO templates.

This generator is great for small projects, prototyping, and capturing structured data, you can have the project up and running in a few minutes.

Checkout the CA Parks demo project to see the generated code.

Getting Started

Step 1 - Model your project

GPG takes in a JSON file that holds the configuration of the project, a list of the entities, with the corresponding fields and relationships.

You can generate this config file using the GPG Web Editor.

GPG Web Editor

  • Make sure to include a user entity in your design this is needed for authentication and to access the web app.
    • The email and password fields are required
  • Follow the naming conventions to avoid unusual errors.

Step 2 - Setup your database

GPG currently only supports MySQL, make sure you have MySQL running locally or in the cloud and update the configuration in the project settings.

Step 3 - Generate the code

Make sure you have Go installed (last tested in 1.18)

Clone this repo:

git clone [email protected]:mklfarha/gpg.git

Build the code:

go build .

Run the generator with your config file and target (where you want the code to be generated):

go run . genall ./gpg_project_ca_parks_1682056073188.json ~/Desktop/caparks

Step 4 - Validate the generation

The code will log every step of the generation, this can be the first step to ensure everything was generated correctly.

Check MySQL and make sure your tables have been generated, there should be a table for each of your entities:

SHOW TABLES

Try building and running the generated code:

cd {generate target path}/{project identifer}/api

go build .

go run .

This should run your API locally, you should see something like this

API Run

Step 5 - Create a user

You can use the CLI tool in the generated code to create the first user, afterwards you can use the CMS

To use the CLI, follow these steps:

cd {generate target path}/{project identifer}/cli

go build .

go run . create-user

Follow the interactive steps to create the user.

Step 6 - Run the CMS

The CMS web tool uses React, make sure you have node installed

Follow these steps to run it:

cd {generate target path}/{project identifer}/web

npm install

npm start

The web app should start on port 3000

GPG CRM

[Bonus] Generate an token and use the GraphQL Playground

To generate token, you need to create a user first

You can use the CLI tool in the generated code to create a user token,

To use the CLI, follow these steps:

cd {generate target path}/{project identifer}/cli

go build .

go run . create-token

Follow the interactive steps to create the token.

Once you have the token, open the plaground

http://localhost:8080/gplay 

Enter the username and password added in the project settings:

GPG Auth

(if prompted again, cancel, at this point you should see the playground)

Add the token just generate in the headers and reload

{
  "authorization":"bearer {your token here}"
}

GPG Auth

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.